Ablage je Einheit, Stufe 2: Verwaltung und Organisationsseite (#684)
- OrgAdministration: eine neue Einheit bekommt ihren Bereich (Mitglieder: die Einheit samt Untereinheiten, schreiben); reservierte Namen und belegte Bereichs-Ids werden als Einheiten-Id abgelehnt. Uebergreifende Bereiche anlegen (mit Eigentuemer), Name/Zweck/geschuetzte Ordner aendern, Mitgliederliste ersetzen, nur leere Bereiche loeschen, nie den eigenen einer Einheit. Eine geloeschte Einheit verlaesst alle Mitgliederlisten; ihr Bereich geht nur, wenn er leer ist, sonst bleibt er ohne Eigentuemer. Nachruesten des eigenen Bereichs fuer Einheiten von vor #684. Alles im AuditLog. - API unter /api/organisation/workspaces; die Uebersicht liefert je Bereich Mitglieder, Dateizahl und - von der Instanz berechnet - wer hineinkommt. - Organisationsseite: Bereiche unter der Struktur, Bearbeitung mit Mitglieder-Editor, "Wer hineinkommt", Bereichskarte an der Einheit, Bereiche am Agenten. Sprachschluessel en/de. - Die Nachschau nach einem Absturz bekommt die Organisation mit, sonst fände sie einen Aufruf in einem benannten Bereich nicht. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ff20ce2563
commit
609298dd7a
@@ -690,7 +690,11 @@ public sealed class AppHost : IAsyncDisposable
|
||||
loggerFactory.CreateLogger($"ClawdDotNet.Tools.{toolName}.Probe"),
|
||||
CancellationToken.None,
|
||||
agent.WorkspacePath,
|
||||
agent.SharedWorkspacePath);
|
||||
agent.SharedWorkspacePath)
|
||||
{
|
||||
// #684: a call in a named workspace is only found with the organisation.
|
||||
Organisation = Core.Organisation.OrgChart.From(instance)
|
||||
};
|
||||
}
|
||||
|
||||
var recovery = new CrashRecovery(audit, tools, loggerFactory, KontextFuer);
|
||||
|
||||
@@ -34,6 +34,9 @@ public sealed record UnitSettingChange(
|
||||
bool Outlier,
|
||||
bool SelectedByDefault);
|
||||
|
||||
/// <summary>#684: One entry of a workspace's member list, as the administration takes it.</summary>
|
||||
public sealed record WorkspaceMemberInput(string? UnitId, string? AgentId, WorkspaceAccess Access, bool IncludeSubUnits = true);
|
||||
|
||||
/// <summary>What a move or a lowered ceiling would do before it is done.</summary>
|
||||
public sealed record StructurePreview(
|
||||
IReadOnlyList<string> AffectedAgents,
|
||||
@@ -86,6 +89,10 @@ public sealed class OrgAdministration(AppHost host, ILogger logger)
|
||||
return AdminResult.Failure("A unit needs a name.");
|
||||
if (Chart.Unit(id) is not null)
|
||||
return AdminResult.Failure($"There is already a unit '{id}'.");
|
||||
if (!WorkspaceLayout.IsValidId(id))
|
||||
return AdminResult.Failure($"'{id}' is reserved — a unit's workspace carries its id, and '{id}' already means something in FileRW.");
|
||||
if (Chart.Workspace(id) is not null)
|
||||
return AdminResult.Failure($"There is already a workspace '{id}'. A unit's own workspace carries the unit's id — choose another id.");
|
||||
if (!string.IsNullOrWhiteSpace(parentId) && Chart.Unit(parentId) is null)
|
||||
return AdminResult.Failure($"There is no unit '{parentId}' to put it under.");
|
||||
|
||||
@@ -97,8 +104,11 @@ public sealed class OrgAdministration(AppHost host, ILogger logger)
|
||||
Goal = goal?.Trim() ?? ""
|
||||
});
|
||||
|
||||
// #684: every unit gets its own workspace — the normal case, it costs no decision.
|
||||
host.Instance.Workspaces.Add(OwnWorkspace(id, name.Trim()));
|
||||
|
||||
Save(null, "unit_create", new { id, name, parentId, goal }, reason);
|
||||
return AdminResult.Success($"Unit '{name.Trim()}' created.");
|
||||
return AdminResult.Success($"Unit '{name.Trim()}' created, with its workspace '{id}'.");
|
||||
}
|
||||
|
||||
public AdminResult UpdateUnit(string unitId, string? name, string? goal, string reason = "")
|
||||
@@ -129,8 +139,28 @@ public sealed class OrgAdministration(AppHost host, ILogger logger)
|
||||
return AdminResult.Failure($"Unit '{unit.Name}' still has members or sub-units. Move them first.");
|
||||
|
||||
host.Instance.Units.Remove(unit);
|
||||
Save(null, "unit_delete", new { unitId }, reason);
|
||||
return AdminResult.Success($"Unit '{unit.Name}' deleted.");
|
||||
|
||||
// #684: what was filed belongs to the unit, and the unit is gone — so nothing is
|
||||
// deleted here. Its entries leave the member lists; its own workspace goes only if
|
||||
// it is empty, otherwise it stays without owner for a human to decide.
|
||||
var kept = new List<string>();
|
||||
foreach (var workspace in host.Instance.Workspaces.ToList())
|
||||
{
|
||||
workspace.Members.RemoveAll(m => Same(m.UnitId, unit.Id));
|
||||
if (!Same(workspace.OwnerUnitId, unit.Id))
|
||||
continue;
|
||||
|
||||
workspace.OwnerUnitId = null;
|
||||
if (Same(workspace.Id, unit.Id) && !HasFiles(workspace.Id))
|
||||
host.Instance.Workspaces.Remove(workspace);
|
||||
else
|
||||
kept.Add(workspace.Id);
|
||||
}
|
||||
|
||||
Save(null, "unit_delete", new { unitId, workspacesKept = kept }, reason);
|
||||
return AdminResult.Success(kept.Count == 0
|
||||
? $"Unit '{unit.Name}' deleted."
|
||||
: $"Unit '{unit.Name}' deleted. Its workspace(s) {string.Join(", ", kept.Select(k => $"'{k}'"))} still hold files and remain, without owner.");
|
||||
}
|
||||
|
||||
/// <summary>The lead must be a member of the unit. <c>null</c> leaves it without a lead.</summary>
|
||||
@@ -549,6 +579,177 @@ public sealed class OrgAdministration(AppHost host, ILogger logger)
|
||||
}
|
||||
}
|
||||
|
||||
// ─── workspaces (#684) ───
|
||||
|
||||
/// <summary>
|
||||
/// A workspace shared across units on purpose — the article master that purchasing owns
|
||||
/// and marketing reads. It needs a named owner or none (then it belongs to the human),
|
||||
/// and its id must not be a unit's: those are kept for the units' own workspaces.
|
||||
/// </summary>
|
||||
public AdminResult CreateWorkspace(
|
||||
string id, string name, string? purpose, string? ownerUnitId,
|
||||
IReadOnlyList<WorkspaceMemberInput> members, string reason = "")
|
||||
{
|
||||
id = (id ?? "").Trim();
|
||||
if (!WorkspaceLayout.IsValidId(id))
|
||||
return AdminResult.Failure($"A workspace id consists of letters, digits, '-' and '_', and is none of {string.Join(", ", WorkspaceLayout.Reserved)}.");
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return AdminResult.Failure("A workspace needs a name.");
|
||||
if (Chart.Workspace(id) is not null)
|
||||
return AdminResult.Failure($"There is already a workspace '{id}'.");
|
||||
if (Chart.Unit(id) is not null)
|
||||
return AdminResult.Failure($"'{id}' is the id of a unit — its own workspace carries it. Choose another id.");
|
||||
if (!string.IsNullOrWhiteSpace(ownerUnitId) && FindUnit(ownerUnitId) is null)
|
||||
return AdminResult.Failure($"There is no unit '{ownerUnitId}' to own it.");
|
||||
if (CheckMembers(members) is { } problem)
|
||||
return AdminResult.Failure(problem);
|
||||
|
||||
host.Instance.Workspaces.Add(new WorkspaceConfig
|
||||
{
|
||||
Id = id,
|
||||
Name = name.Trim(),
|
||||
Purpose = purpose?.Trim() ?? "",
|
||||
OwnerUnitId = string.IsNullOrWhiteSpace(ownerUnitId) ? null : FindUnit(ownerUnitId)!.Id,
|
||||
Members = members.Select(ToMember).ToList()
|
||||
});
|
||||
|
||||
Save(null, "workspace_create", new { id, name, ownerUnitId, members }, reason);
|
||||
return AdminResult.Success($"Workspace '{name.Trim()}' created.");
|
||||
}
|
||||
|
||||
/// <summary>Name, purpose and protected folders. <c>null</c> leaves a value as it is.</summary>
|
||||
public AdminResult UpdateWorkspace(
|
||||
string workspaceId, string? name, string? purpose, IReadOnlyList<string>? protectedPaths, string reason = "")
|
||||
{
|
||||
if (FindWorkspace(workspaceId) is not { } workspace)
|
||||
return AdminResult.Failure($"There is no workspace '{workspaceId}'.");
|
||||
if (name is not null && string.IsNullOrWhiteSpace(name))
|
||||
return AdminResult.Failure("A workspace needs a name.");
|
||||
|
||||
var paths = protectedPaths?
|
||||
.Select(p => p.Replace('\\', '/').Trim().Trim('/'))
|
||||
.Where(p => p.Length > 0)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
if (paths?.FirstOrDefault(p => p.Split('/').Any(part => part is "." or "..")) is { } bad)
|
||||
return AdminResult.Failure($"'{bad}' is not a folder inside the workspace.");
|
||||
|
||||
if (name is not null) workspace.Name = name.Trim();
|
||||
if (purpose is not null) workspace.Purpose = purpose.Trim();
|
||||
if (paths is not null) workspace.ProtectedPaths = paths;
|
||||
|
||||
Save(null, "workspace_update", new { workspaceId, name, purpose, protectedPaths = paths }, reason);
|
||||
return AdminResult.Success($"Workspace '{workspace.Name}' saved.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the member list. The right stands here, at the workspace — whoever is not on
|
||||
/// the list does not see it. Works for a unit's own workspace too: widening it to a
|
||||
/// reading neighbour is exactly the kind of decision that belongs to a human.
|
||||
/// </summary>
|
||||
public AdminResult SetWorkspaceMembers(string workspaceId, IReadOnlyList<WorkspaceMemberInput> members, string reason = "")
|
||||
{
|
||||
if (FindWorkspace(workspaceId) is not { } workspace)
|
||||
return AdminResult.Failure($"There is no workspace '{workspaceId}'.");
|
||||
if (CheckMembers(members) is { } problem)
|
||||
return AdminResult.Failure(problem);
|
||||
|
||||
var before = workspace.Members.Select(m => new { m.UnitId, m.AgentId, m.Access, m.IncludeSubUnits }).ToList();
|
||||
workspace.Members = members.Select(ToMember).ToList();
|
||||
|
||||
Save(null, "workspace_members", new { workspaceId, before, after = members }, reason);
|
||||
return AdminResult.Success($"Members of '{workspace.Name}' saved.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only an empty workspace can be deleted: nothing filed is ever thrown away from here.
|
||||
/// A unit's own workspace goes with its unit, not on its own.
|
||||
/// </summary>
|
||||
public AdminResult DeleteWorkspace(string workspaceId, string reason = "")
|
||||
{
|
||||
if (FindWorkspace(workspaceId) is not { } workspace)
|
||||
return AdminResult.Failure($"There is no workspace '{workspaceId}'.");
|
||||
if (Chart.UnitWorkspace(workspace.OwnerUnitId) == workspace)
|
||||
return AdminResult.Failure($"'{workspace.Id}' is the own workspace of unit '{workspace.OwnerUnitId}' — it goes when the unit is deleted.");
|
||||
if (HasFiles(workspace.Id))
|
||||
return AdminResult.Failure($"Workspace '{workspace.Name}' still holds files. Nothing filed is deleted from here — move or remove them first.");
|
||||
|
||||
host.Instance.Workspaces.Remove(workspace);
|
||||
Save(null, "workspace_delete", new { workspaceId }, reason);
|
||||
return AdminResult.Success($"Workspace '{workspace.Name}' deleted.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives a unit its own workspace if it has none — for units that existed before
|
||||
/// workspaces did. Does nothing for a unit that has one.
|
||||
/// </summary>
|
||||
public AdminResult CreateUnitWorkspace(string unitId, string reason = "")
|
||||
{
|
||||
if (FindUnit(unitId) is not { } unit)
|
||||
return AdminResult.Failure($"There is no unit '{unitId}'.");
|
||||
if (Chart.UnitWorkspace(unit.Id) is not null)
|
||||
return AdminResult.Success($"'{unit.Name}' already has its workspace.");
|
||||
if (Chart.Workspace(unit.Id) is not null)
|
||||
return AdminResult.Failure($"There is a workspace '{unit.Id}' that does not belong to the unit. Rename or delete it first.");
|
||||
if (!WorkspaceLayout.IsValidId(unit.Id))
|
||||
return AdminResult.Failure($"The unit id '{unit.Id}' cannot be a workspace id.");
|
||||
|
||||
host.Instance.Workspaces.Add(OwnWorkspace(unit.Id, unit.Name));
|
||||
Save(null, "workspace_create", new { id = unit.Id, ownerUnitId = unit.Id }, reason);
|
||||
return AdminResult.Success($"'{unit.Name}' has its workspace now.");
|
||||
}
|
||||
|
||||
/// <summary>The folder of a workspace; <c>null</c> when the instance has no shared folder.</summary>
|
||||
public string? WorkspaceFolder(string workspaceId)
|
||||
=> WorkspaceLayout.PathOf(
|
||||
host.Instance.Agents.Select(a => a.SharedWorkspacePath).FirstOrDefault(p => !string.IsNullOrWhiteSpace(p)),
|
||||
workspaceId);
|
||||
|
||||
/// <summary>How many files a workspace holds, in all its folders.</summary>
|
||||
public int FileCount(string workspaceId)
|
||||
=> WorkspaceFolder(workspaceId) is { } folder && Directory.Exists(folder)
|
||||
? Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Count()
|
||||
: 0;
|
||||
|
||||
private bool HasFiles(string workspaceId) => FileCount(workspaceId) > 0;
|
||||
|
||||
private static WorkspaceConfig OwnWorkspace(string unitId, string unitName) => new()
|
||||
{
|
||||
Id = unitId,
|
||||
Name = unitName,
|
||||
OwnerUnitId = unitId,
|
||||
Members = [new WorkspaceMember { UnitId = unitId, Access = WorkspaceAccess.Write, IncludeSubUnits = true }]
|
||||
};
|
||||
|
||||
private string? CheckMembers(IReadOnlyList<WorkspaceMemberInput> members)
|
||||
{
|
||||
foreach (var member in members)
|
||||
{
|
||||
var byUnit = !string.IsNullOrWhiteSpace(member.UnitId);
|
||||
var byAgent = !string.IsNullOrWhiteSpace(member.AgentId);
|
||||
if (byUnit == byAgent)
|
||||
return "Each member is either a unit or an agent.";
|
||||
if (byUnit && FindUnit(member.UnitId) is null)
|
||||
return $"There is no unit '{member.UnitId}'.";
|
||||
if (byAgent && host.AgentAdmin.Find(member.AgentId!) is null)
|
||||
return $"There is no agent '{member.AgentId}'.";
|
||||
if (member.Access == WorkspaceAccess.None)
|
||||
return "A member needs at least read access — leave it off the list instead.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private WorkspaceMember ToMember(WorkspaceMemberInput input) => new()
|
||||
{
|
||||
UnitId = string.IsNullOrWhiteSpace(input.UnitId) ? null : FindUnit(input.UnitId)!.Id,
|
||||
AgentId = string.IsNullOrWhiteSpace(input.AgentId) ? null : host.AgentAdmin.Find(input.AgentId!)!.AgentId,
|
||||
Access = input.Access,
|
||||
IncludeSubUnits = input.IncludeSubUnits
|
||||
};
|
||||
|
||||
private WorkspaceConfig? FindWorkspace(string? workspaceId)
|
||||
=> workspaceId is null ? null : host.Instance.Workspaces.FirstOrDefault(w => Same(w.Id, workspaceId));
|
||||
|
||||
private UnitConfig? FindUnit(string? unitId)
|
||||
=> unitId is null ? null : host.Instance.Units.FirstOrDefault(u => Same(u.Id, unitId));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user