swarm-ui: edit an agent's permissions on its detail panel
The detail panel had editors for inference, instructions, resource caps and
accounts, but nothing for the permissions the swarm grants, which could only
be set at create time or with swarmctl. A permissions row shows the grant
(the default set, none, or the list) and an edit dialog ticks the catalogue
from GET /api/permissions and saves with PUT /api/agents/{agent}/permissions.
Ticking exactly the default set sends the DELETE, as the create form sends no
list for it.
This commit is contained in:
parent
eaf26aaadd
commit
78c48272ee
1 changed files with 339 additions and 3 deletions
23
frontend/packages/swarm-ui/src/agent/detail/permissions.ts
Normal file
23
frontend/packages/swarm-ui/src/agent/detail/permissions.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// The detail panel's permissions editor: what it starts on and how a granted
|
||||
// set reads. Kept out of the component so `npm test` can run it.
|
||||
|
||||
/**
|
||||
* The editor's starting selection: the swarm's stored list when it sets one,
|
||||
* else the default set. Names the catalogue (`all`) does not list are dropped,
|
||||
* since the route refuses an unknown one, and the operator would be unable to
|
||||
* clear a box they cannot see.
|
||||
*/
|
||||
export function editorSelection(
|
||||
stored: string[] | undefined,
|
||||
all: string[],
|
||||
defaults: string[],
|
||||
): string[] {
|
||||
return (stored ?? defaults).filter((p) => all.includes(p));
|
||||
}
|
||||
|
||||
/** What the panel says about a stored `permissions` field. */
|
||||
export function grantSummary(stored: string[] | undefined): string {
|
||||
if (stored === undefined) return "the default set";
|
||||
if (stored.length === 0) return "none";
|
||||
return `${stored.length} granted`;
|
||||
}
|
||||
Loading…
Reference in a new issue