mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
fix: name a non-authoring role's access build and run, with a restricted badge
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
72db21f599
commit
3ebe4b1b5f
@@ -2,7 +2,9 @@
|
||||
import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte'
|
||||
import type { McpWorkspaceAccess } from '$lib/gen'
|
||||
import type { McpAccess } from './McpAccessPicker.svelte'
|
||||
import { accessLabel, connectsSeparately, workspaceMcpUrl } from './workspaceAccess'
|
||||
import Popover from '$lib/components/Popover.svelte'
|
||||
import { Badge } from '$lib/components/common'
|
||||
import { accessLabel, connectsSeparately, restriction, workspaceMcpUrl } from './workspaceAccess'
|
||||
|
||||
interface Props {
|
||||
workspaces: McpWorkspaceAccess[]
|
||||
@@ -23,11 +25,20 @@
|
||||
<ul class="flex flex-col divide-y rounded-md border max-h-60 overflow-y-auto">
|
||||
{#each listed as workspace (workspace.id)}
|
||||
{@const separate = connectsSeparately(workspace, all, covered, access)}
|
||||
{@const restricted = restriction(workspace, access)}
|
||||
<li class="flex flex-col gap-1 px-2 py-1.5">
|
||||
<div class="flex items-baseline justify-between gap-2">
|
||||
<span class="text-xs text-emphasis truncate">{workspace.name}</span>
|
||||
<span class="text-xs text-secondary text-right">
|
||||
{accessLabel(workspace, access)}{separate ? ', connect separately' : ''}
|
||||
{#if restricted}
|
||||
<Popover notClickable>
|
||||
{#snippet text()}
|
||||
<div class="text-xs max-w-xs">{restricted}</div>
|
||||
{/snippet}
|
||||
<Badge color="gray" small>Restricted</Badge>
|
||||
</Popover>
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
{#if separate}
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
accessLabel,
|
||||
connectsSeparately,
|
||||
defaultConnection,
|
||||
editsHint,
|
||||
restriction,
|
||||
servedOn,
|
||||
toolsetLevel
|
||||
} from './workspaceAccess'
|
||||
@@ -38,10 +38,11 @@ it('names the lower of the picked access and the workspace one', () => {
|
||||
'12 scripts and flows as tools'
|
||||
)
|
||||
const edits = { ...ws('a', 'run_and_edit'), edits: ['variables', 'schedules', 'triggers'] }
|
||||
expect(accessLabel(edits, 'full')).toBe('Read, run and edit')
|
||||
expect(editsHint(edits)).toBe(
|
||||
'Explore, run deployed scripts, flows and agents, and edit variables, schedules and triggers.'
|
||||
expect(accessLabel(edits, 'full')).toBe('Build and run')
|
||||
expect(restriction(edits, 'full')).toBe(
|
||||
'Your role writes no scripts, flows or apps. The client runs them and edits variables, schedules and triggers.'
|
||||
)
|
||||
expect(restriction(edits, 'read_run')).toBeUndefined()
|
||||
expect(accessLabel(ws('a', 'run_and_edit'), 'read_run')).toBe('Read and run')
|
||||
expect(accessLabel(ws('a', 'read_only'), 'read_run')).toBe('Read only')
|
||||
expect(accessLabel(ws('a', 'read_only'), 'selected')).toBe('Not available')
|
||||
|
||||
@@ -7,7 +7,7 @@ export type WorkspaceAccess = McpWorkspaceAccess['access']
|
||||
|
||||
const LABELS: Record<WorkspaceAccess, string> = {
|
||||
build_and_run: 'Build and run',
|
||||
run_and_edit: 'Read, run and edit',
|
||||
run_and_edit: 'Build and run',
|
||||
read_and_run: 'Read and run',
|
||||
read_only: 'Read only',
|
||||
runnables: 'Scripts and flows as tools',
|
||||
@@ -43,13 +43,14 @@ export function accessLabel(workspace: McpWorkspaceAccess, picked: McpAccess): s
|
||||
return LABELS[access]
|
||||
}
|
||||
|
||||
/** What a role that edits only some kinds lets the client do; the label stays short. */
|
||||
export function editsHint(workspace: McpWorkspaceAccess): string | undefined {
|
||||
/** How a role that writes no scripts, flows or apps holds back build and run, which keeps the
|
||||
* label of the level picked. */
|
||||
export function restriction(workspace: McpWorkspaceAccess, picked: McpAccess): string | undefined {
|
||||
if (workspace.access !== 'run_and_edit' || picked !== 'full') return undefined
|
||||
const edits = workspace.edits ?? []
|
||||
if (workspace.access !== 'run_and_edit' || edits.length === 0) return undefined
|
||||
const last = edits.at(-1)
|
||||
const listed = edits.length > 1 ? `${edits.slice(0, -1).join(', ')} and ${last}` : last
|
||||
return `Explore, run deployed scripts, flows and agents, and edit ${listed}.`
|
||||
return `Your role writes no scripts, flows or apps. The client runs them${listed ? ` and edits ${listed}` : ''}.`
|
||||
}
|
||||
|
||||
/** The covered workspaces a connection serves. One set to scripts and flows as tools is served
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import Tooltip from '$lib/components/Tooltip.svelte'
|
||||
import Popover from '$lib/components/Popover.svelte'
|
||||
import McpAccessPicker, {
|
||||
ACCESS_HINTS,
|
||||
ACCESS_SCOPES,
|
||||
@@ -24,8 +25,8 @@
|
||||
import {
|
||||
accessLabel,
|
||||
defaultConnection,
|
||||
editsHint,
|
||||
givesAnything,
|
||||
restriction,
|
||||
servedOn,
|
||||
toolsetLevel,
|
||||
workspaceMcpUrl
|
||||
@@ -189,21 +190,24 @@
|
||||
const groups = $derived.by(() => {
|
||||
const byLabel = new Map<string, McpWorkspaceAccess[]>()
|
||||
for (const w of served) {
|
||||
const label = accessLabel(w, access)
|
||||
byLabel.set(label, [...(byLabel.get(label) ?? []), w])
|
||||
const key = `${accessLabel(w, access)}\n${restriction(w, access) ?? ''}`
|
||||
byLabel.set(key, [...(byLabel.get(key) ?? []), w])
|
||||
}
|
||||
return [...byLabel].map(([label, ws]) => {
|
||||
return [...byLabel].map(([key, ws]) => {
|
||||
const label = accessLabel(ws[0], access)
|
||||
const level = toolsetLevel(ws[0], access)
|
||||
const hint =
|
||||
!givesAnything(ws[0], access)
|
||||
? 'Nothing the client can use there with this access.'
|
||||
: isTools(ws[0])
|
||||
? 'The scripts and flows your role offers, each as its own tool, and nothing else.'
|
||||
: ((level === 'full' && editsHint(ws[0])) || ACCESS_HINTS[level ?? access])
|
||||
: ACCESS_HINTS[level ?? access]
|
||||
return {
|
||||
key,
|
||||
label,
|
||||
ws,
|
||||
level,
|
||||
restricted: restriction(ws[0], access),
|
||||
hint: ws.every((w) => w.limited) ? `${hint} Set by your role.` : hint
|
||||
}
|
||||
})
|
||||
@@ -599,7 +603,7 @@
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet accessRow(group: (typeof groups)[number], named: boolean)}
|
||||
{@const open = shownTools.includes(group.label)}
|
||||
{@const open = shownTools.includes(group.key)}
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex flex-wrap items-center gap-x-1.5">
|
||||
<span class="text-xs text-primary">
|
||||
@@ -610,6 +614,14 @@
|
||||
{group.label}
|
||||
{/if}
|
||||
</span>
|
||||
{#if group.restricted}
|
||||
<Popover notClickable>
|
||||
{#snippet text()}
|
||||
<div class="text-xs max-w-xs">{group.restricted}</div>
|
||||
{/snippet}
|
||||
<Badge color="gray" small>Restricted</Badge>
|
||||
</Popover>
|
||||
{/if}
|
||||
<Tooltip small>{group.hint}</Tooltip>
|
||||
{#if !named}{@render pen()}{/if}
|
||||
{#if group.level}
|
||||
@@ -621,8 +633,8 @@
|
||||
aria-expanded={open}
|
||||
onClick={() =>
|
||||
(shownTools = open
|
||||
? shownTools.filter((l) => l !== group.label)
|
||||
: [...shownTools, group.label])}
|
||||
? shownTools.filter((l) => l !== group.key)
|
||||
: [...shownTools, group.key])}
|
||||
>
|
||||
{open ? 'Hide tools' : 'Show tools'}
|
||||
</Button>
|
||||
@@ -644,7 +656,7 @@
|
||||
{@render accessRow(groups[0], false)}
|
||||
{:else if groups.length > 1}
|
||||
<div class="flex flex-col divide-y rounded-md border">
|
||||
{#each groups as group (group.label)}
|
||||
{#each groups as group (group.key)}
|
||||
<div class="px-2 py-1.5">{@render accessRow(group, true)}</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user