diff --git a/frontend/src/lib/components/InstanceSetting.svelte b/frontend/src/lib/components/InstanceSetting.svelte index 48323cab2a..ac6518998e 100644 --- a/frontend/src/lib/components/InstanceSetting.svelte +++ b/frontend/src/lib/components/InstanceSetting.svelte @@ -24,6 +24,7 @@ import AgentWorkloadIdentityIssuers from './instanceSettings/AgentWorkloadIdentityIssuers.svelte' import McpExternalIdp from './instanceSettings/McpExternalIdp.svelte' import OtelAuditLogsSettings from './instanceSettings/OtelAuditLogsSettings.svelte' + import HubAccessSetting from './instanceSettings/HubAccessSetting.svelte' import WorkspaceRolesSetting from './instanceSettings/WorkspaceRolesSetting.svelte' import SmtpSettings from './instanceSettings/SmtpSettings.svelte' import SecretBackendConfig from './instanceSettings/SecretBackendConfig.svelte' @@ -52,6 +53,8 @@ oauths?: Record warning?: string markSettingSaved?: (key: string) => void + /** The settings as saved, without the page's edits. */ + initialValues?: Record } let { @@ -62,7 +65,8 @@ openSmtpSettings, oauths, warning, - markSettingSaved + markSettingSaved, + initialValues }: Props = $props() const dispatch = createEventDispatcher() @@ -356,6 +360,14 @@ {:else if setting.fieldType == 'workspace_roles'} + {:else if setting.fieldType == 'hub_access'} + {:else} = { storage: 'setting', ee_only: 'Custom workspace roles are only available in the EE version', validate: workspaceRolesErrors + }, + { + label: 'Hub scripts', + key: 'hub_access', + fieldType: 'hub_access', + storage: 'setting' } ], 'Managed Postgres': [ diff --git a/frontend/src/lib/components/instanceSettings/HubAccessSetting.svelte b/frontend/src/lib/components/instanceSettings/HubAccessSetting.svelte new file mode 100644 index 0000000000..69a8dd3bda --- /dev/null +++ b/frontend/src/lib/components/instanceSettings/HubAccessSetting.svelte @@ -0,0 +1,83 @@ + + + +
+ {#if unlicensed} + + {#if ceBuild} + This Community Edition server does not apply the list below. A workspace admin can still + set one in that workspace's settings. + {:else} + The list below keeps applying as it is. A workspace admin can still replace it in that + workspace's settings. + {/if} + {#if Object.keys(list).length > 0} +
+ +
+ {/if} +
+ {/if} + +
+
diff --git a/frontend/src/lib/components/instanceSettings/WorkspaceRolesSetting.svelte b/frontend/src/lib/components/instanceSettings/WorkspaceRolesSetting.svelte index 0bdc23e175..ff881c1e79 100644 --- a/frontend/src/lib/components/instanceSettings/WorkspaceRolesSetting.svelte +++ b/frontend/src/lib/components/instanceSettings/WorkspaceRolesSetting.svelte @@ -4,6 +4,7 @@ import { Alert, Badge, Button } from '../common' import TextInput from '../text_input/TextInput.svelte' import RoleCapabilitiesEditor from '../settings/RoleCapabilitiesEditor.svelte' + import SettingCard from './SettingCard.svelte' import type { RoleCapabilities, RoleCapabilitiesPatch, RoleDefinition } from '$lib/gen' import { resolveCapabilities, @@ -107,148 +108,150 @@ } -
- {#if unlicensed} - +
+ {#if unlicensed} + + The roles below keep applying as they are. A workspace admin can still override what they + allow in that workspace's settings. + {#if serialize(rows) !== undefined} +
+ +
+ {/if} +
+ {/if} + + Roles members can hold in every workspace, in order: when several instance groups map a member + to different roles, the role listed first wins. A capability left unset uses the default: + everything for a role named developer, the operator rights for any other name. + Workspace admins can override a role in their workspace. A role still held by a member, + invite, auto-invite or instance group mapping cannot be removed. + + +
(rows = e.detail.items)} + onfinalize={(e) => (rows = e.detail.items)} > - The roles below keep applying as they are. A workspace admin can still override what they - allow in that workspace's settings. - {#if serialize(rows) !== undefined} -
- -
- {/if} - - {/if} - - Roles members can hold in every workspace, in order: when several instance groups map a member - to different roles, the role listed first wins. A capability left unset uses the default: - everything for a role named developer, the operator rights for any other name. - Workspace admins can override a role in their workspace. A role still held by a member, invite, - auto-invite or instance group mapping cannot be removed. - - -
(rows = e.detail.items)} - onfinalize={(e) => (rows = e.detail.items)} - > - {#each rows as row, i (row.id)} - {@const base = baseCapabilitiesFor(row.name)} - {@const caps = resolveCapabilities(base, row.capabilities, false)} -
-
-
- -
-
- -
- - {#if row.label.trim()} - {row.label.trim()} · - {/if} - {summary(caps)} - - {#if i === 0} - Highest - {/if} - -
- {#if errors[`${i}.name`]} - - {errors[`${i}.name`]} - - {/if} - {#if row.open} -
-
- Label -
- -
+ {#each rows as row, i (row.id)} + {@const base = baseCapabilitiesFor(row.name)} + {@const caps = resolveCapabilities(base, row.capabilities, false)} +
+
+
+
- (row.capabilities = p)} +
+ +
+ + {#if row.label.trim()} + {row.label.trim()} · + {/if} + {summary(caps)} + + {#if i === 0} + Highest + {/if} + +
- {:else if errors[`${i}.capabilities`]} - - {errors[`${i}.capabilities`]} - - {/if} -
- {/each} -
+ {#if errors[`${i}.name`]} + + {errors[`${i}.name`]} + + {/if} + {#if row.open} +
+
+ Label +
+ +
+
+ (row.capabilities = p)} + /> +
+ {:else if errors[`${i}.capabilities`]} + + {errors[`${i}.capabilities`]} + + {/if} +
+ {/each} + - {#if !disabled} -
- -
- {/if} -
+ {#if !disabled} +
+ +
+ {/if} + +
diff --git a/frontend/src/lib/components/settings/HubAccessEditor.svelte b/frontend/src/lib/components/settings/HubAccessEditor.svelte new file mode 100644 index 0000000000..724b94f94c --- /dev/null +++ b/frontend/src/lib/components/settings/HubAccessEditor.svelte @@ -0,0 +1,437 @@ + + +{#snippet icon(name: string)} + +
+ +
+{/snippet} + +
+
+ + {#if !readOnly} + ({ + displayName: v.label, + selected: v.id === view.id, + action: () => (viewId = v.id) + }))} + > + {#snippet buttonReplacement()} + + {/snippet} + + {/if} +
+ + +
{ + if (e.key === 'Escape' && selection.length > 0) { + e.preventDefault() + selected = [] + } + }} + > +
+ +
0 ? 'pb-14' : '')} + tabindex={readOnly ? undefined : 0} + aria-label="Integrations" + onkeydown={(e) => { + if (!readOnly && (e.ctrlKey || e.metaKey) && e.key === 'a') { + e.preventDefault() + selected = shown.map((i) => i.name) + } + }} + > + {#if hubUnavailable && !readOnly} +
+ + Only the integrations already allowed are shown. + +
+ {/if} + {#if loading && !readOnly} +
+ {:else} +
+ {#each shown as { name, label } (name)} + {@const page = hubNames[name] && `${$hubBaseUrlStore}/integrations/${name}`} + {@const count = countsLabel(name)} +
+ +
+
0 + ? 'invisible' + : 'group-hover/row:invisible' + )} + > + {@render icon(name)} +
+ {#if !readOnly} + 0 ? '' : 'invisible group-hover/row:visible' + )} + checked={selection.includes(name)} + title={selection.includes(name) + ? 'Deselect' + : 'Select (shift-click to select a range)'} + onClick={(e) => (shiftHeld = e.shiftKey)} + onChange={() => toggleSelected(name)} + /> + {/if} +
+
+ {#if page} + + {:else} + {label} + {/if} + {#if count} + {count} + {/if} +
+ {#if level(name) !== savedLevel(name)} + + {LEVEL_LABELS[savedLevel(name)]} → + + {/if} +
+ + level(name), (v) => v !== level(name) && apply([name], v as Level) + } + > + {#snippet children({ item })} + + + + {/snippet} + +
+
+ {:else} +

+ {query !== '' ? `No integration matches "${search.trim()}".` : view.empty} +

+ {/each} +
+ {/if} +
+ + {#if selection.length > 0} +
+
+ + {selection.length < shown.length + ? `${selection.length} selected` + : `All ${shown.length} selected`} + +
+ Set to + {#key bulkControlKey} + + + {#snippet children({ item })} + {#each ['none', 'read', 'write'] as const as to (to)} + setMany(selection, to)} + /> + {/each} + {/snippet} + + {/key} +
+ {#if selection.length < shown.length} + + {/if} +
+
+ {/if} +
+
+ + + {summary}{#if changes !== ''}. {changes}{#if everyAllowed}. New Hub integrations start at None{/if}{/if} + +
+ + diff --git a/frontend/src/lib/components/settings/WorkspaceHubAccess.svelte b/frontend/src/lib/components/settings/WorkspaceHubAccess.svelte new file mode 100644 index 0000000000..17c741ea8c --- /dev/null +++ b/frontend/src/lib/components/settings/WorkspaceHubAccess.svelte @@ -0,0 +1,81 @@ + + +
+ {#snippet action()} + (draft = data?.hub_access ?? null)} + saveLabel="Save Hub scripts" + /> + {/snippet} + + {#if !data} + Loading Hub scripts... + {:else} +
+ (draft = e.detail ? null : { ...(data?.instance_hub_access ?? {}) })} + /> + + {#key draft === null} + (draft = v)} + /> + {/key} +
+ {/if} +
diff --git a/frontend/src/lib/components/settings/WorkspaceRoleOverrides.svelte b/frontend/src/lib/components/settings/WorkspaceRoleOverrides.svelte index 3ef7be4018..e9803280b2 100644 --- a/frontend/src/lib/components/settings/WorkspaceRoleOverrides.svelte +++ b/frontend/src/lib/components/settings/WorkspaceRoleOverrides.svelte @@ -23,6 +23,7 @@ VISIBILITY_KEYS } from '$lib/workspaceRoles' import { ChevronDown, ChevronRight, Plus, RotateCcw, SaveIcon, Trash2 } from 'lucide-svelte' + import { untrack } from 'svelte' import { SvelteMap } from 'svelte/reactivity' interface Props { @@ -36,22 +37,11 @@ // Maps, not objects: a role name is any slug, `constructor` and `__proto__` included. const draft = new SvelteMap() - let loadedFrom: WorkspaceRoles | undefined = undefined const open = new SvelteMap() let newRoleName = $state('') let confirmSeatOpen = $state(false) let saving = $state(false) - $effect(() => { - if (data && data !== loadedFrom) { - loadedFrom = data - draft.clear() - for (const [name, o] of Object.entries(data.overrides ?? {})) { - draft.set(name, structuredClone($state.snapshot(o))) - } - } - }) - const instanceRoles = $derived((data?.roles ?? []).filter((r) => r.source === 'instance')) const workspaceOnlyNames = $derived( [...draft.keys()].filter((n) => !instanceRoles.some((r) => r.name === n)).sort() @@ -116,7 +106,10 @@ ].join(' · ') } - /** The overrides to store: instance roles left as the instance has them are dropped. */ + /** + * The overrides to store: instance roles left as the instance has them are dropped. Sorted, as + * `dirty` compares them as text and the server lists them in any order. + */ function cleaned(entries: Iterable<[string, RoleOverride]>): RoleOverrides { const out: [string, RoleOverride][] = [] for (const [name, v] of entries) { @@ -131,15 +124,24 @@ } ]) } - return Object.fromEntries(out) + return Object.fromEntries(out.sort(([a], [b]) => (a < b ? -1 : 1))) } const cleanedDraft = $derived(cleaned(draft)) - const dirty = $derived( - data != undefined && - JSON.stringify(cleanedDraft) !== JSON.stringify(cleaned(Object.entries(data.overrides))) - ) + const stored = $derived(data && JSON.stringify(cleaned(Object.entries(data.overrides)))) + const dirty = $derived(stored !== undefined && JSON.stringify(cleanedDraft) !== stored) + + $effect(() => { + // Only when the overrides changed: saving the Hub scripts reloads `data` too. + if (stored === undefined) return + untrack(() => { + draft.clear() + for (const [name, o] of Object.entries(data?.overrides ?? {})) { + draft.set(name, structuredClone($state.snapshot(o))) + } + }) + }) const errors = $derived.by(() => { const e: Record = Object.create(null) diff --git a/frontend/src/lib/components/settings/WorkspaceUserSettings.svelte b/frontend/src/lib/components/settings/WorkspaceUserSettings.svelte index 328224128c..9cc7bb8391 100644 --- a/frontend/src/lib/components/settings/WorkspaceUserSettings.svelte +++ b/frontend/src/lib/components/settings/WorkspaceUserSettings.svelte @@ -5,6 +5,7 @@ import ToggleButton from '$lib/components/common/toggleButton-v2/ToggleButton.svelte' import ToggleButtonGroup from '$lib/components/common/toggleButton-v2/ToggleButtonGroup.svelte' import WorkspaceRoleOverrides from '$lib/components/settings/WorkspaceRoleOverrides.svelte' + import WorkspaceHubAccess from '$lib/components/settings/WorkspaceHubAccess.svelte' import RolePicker from '$lib/components/settings/RolePicker.svelte' import { defaultRoleName, @@ -1072,7 +1073,14 @@
{#if $workspaceStore} - + + {#key $workspaceStore} + + +
+ + + {/key} {/if}
diff --git a/frontend/src/lib/workspaceRoles.ts b/frontend/src/lib/workspaceRoles.ts index 12b2e5a113..f3dfcde69f 100644 --- a/frontend/src/lib/workspaceRoles.ts +++ b/frontend/src/lib/workspaceRoles.ts @@ -41,6 +41,9 @@ const ALL_VISIBLE: RoleVisibility = { workers: true } +export const HUB_ACCESS_DESCRIPTION = + 'Members whose role cannot write code may use the approved Hub scripts of these integrations. Read allows only the scripts the Hub marks read-only.' + // Mirror `RoleCapabilities::FULL` and `RoleCapabilities::OPERATOR` in `windmill_common::roles`. export const FULL_CAPABILITIES: RoleCapabilities = { code: true,