mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-30 00:07:30 +00:00
feat: edit the Hub scripts list in instance and workspace settings
This commit is contained in:
@@ -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<string, any>
|
||||
warning?: string
|
||||
markSettingSaved?: (key: string) => void
|
||||
/** The settings as saved, without the page's edits. */
|
||||
initialValues?: Record<string, any>
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -62,7 +65,8 @@
|
||||
openSmtpSettings,
|
||||
oauths,
|
||||
warning,
|
||||
markSettingSaved
|
||||
markSettingSaved,
|
||||
initialValues
|
||||
}: Props = $props()
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
@@ -356,6 +360,14 @@
|
||||
<RetentionPeriodOverrides {values} disabled={!$enterpriseLicense || loading} />
|
||||
{:else if setting.fieldType == 'workspace_roles'}
|
||||
<WorkspaceRolesSetting {values} {loading} unlicensed={!$enterpriseLicense} />
|
||||
{:else if setting.fieldType == 'hub_access'}
|
||||
<HubAccessSetting
|
||||
{values}
|
||||
{initialValues}
|
||||
{loading}
|
||||
unlicensed={!$enterpriseLicense}
|
||||
ceBuild={version.includes('CE')}
|
||||
/>
|
||||
{:else}
|
||||
<SettingCard
|
||||
label={setting.key === 'disable_stats'
|
||||
|
||||
@@ -1209,6 +1209,7 @@
|
||||
{loading}
|
||||
{setting}
|
||||
{values}
|
||||
{initialValues}
|
||||
{markSettingSaved}
|
||||
{version}
|
||||
{oauths}
|
||||
|
||||
@@ -85,6 +85,7 @@ export interface Setting {
|
||||
| 'agent_workload_identity_issuers'
|
||||
| 'mcp_external_idp'
|
||||
| 'workspace_roles'
|
||||
| 'hub_access'
|
||||
storage: SettingStorage
|
||||
advancedToggle?: {
|
||||
label: string
|
||||
@@ -693,6 +694,12 @@ export const settings: Record<string, Setting[]> = {
|
||||
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': [
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from 'svelte/store'
|
||||
import { Alert, Button } from '../common'
|
||||
import SettingCard from './SettingCard.svelte'
|
||||
import HubAccessEditor from '../settings/HubAccessEditor.svelte'
|
||||
import { HUB_ACCESS_DESCRIPTION } from '$lib/workspaceRoles'
|
||||
import type { HubAccess, HubAccessList } from '$lib/gen'
|
||||
import { RotateCcw } from 'lucide-svelte'
|
||||
|
||||
interface Props {
|
||||
values: Writable<Record<string, any>>
|
||||
/** The settings as saved, without the page's edits. */
|
||||
initialValues?: Record<string, any>
|
||||
loading?: boolean
|
||||
/** Without a valid license the stored list keeps applying but can only be cleared. */
|
||||
unlicensed?: boolean
|
||||
/** A Community Edition server never applies the instance's list. */
|
||||
ceBuild?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
values,
|
||||
initialValues,
|
||||
loading = false,
|
||||
unlicensed = false,
|
||||
ceBuild = false
|
||||
}: Props = $props()
|
||||
|
||||
const KEY = 'hub_access'
|
||||
|
||||
// A list written through the API or YAML is stored as spelled.
|
||||
const normalize = (stored: Record<string, HubAccess> | undefined | null): HubAccessList =>
|
||||
Object.fromEntries(Object.entries(stored ?? {}).map(([k, v]) => [k.toLowerCase(), v]))
|
||||
const list = $derived(normalize($values[KEY]))
|
||||
|
||||
// Unset rather than `{}`, so that removing the last integration is a reset of the setting.
|
||||
function set(value: HubAccessList) {
|
||||
$values[KEY] = Object.keys(value).length > 0 ? value : undefined
|
||||
}
|
||||
</script>
|
||||
|
||||
<SettingCard
|
||||
label="Hub scripts"
|
||||
description="{HUB_ACCESS_DESCRIPTION} Applies to every workspace that does not replace this list with its own."
|
||||
settingKey={KEY}
|
||||
>
|
||||
<div class="flex flex-col gap-3 pt-2">
|
||||
{#if unlicensed}
|
||||
<Alert
|
||||
type="info"
|
||||
size="xs"
|
||||
title="Changing the instance's Hub scripts requires a valid Windmill Enterprise Edition license"
|
||||
>
|
||||
{#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}
|
||||
<div class="mt-2">
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: RotateCcw }}
|
||||
disabled={loading}
|
||||
onclick={() => set({})}
|
||||
>
|
||||
Clear the list
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</Alert>
|
||||
{/if}
|
||||
<HubAccessEditor
|
||||
value={list}
|
||||
saved={initialValues ? normalize(initialValues[KEY]) : list}
|
||||
readOnly={unlicensed || loading}
|
||||
onchange={set}
|
||||
/>
|
||||
</div>
|
||||
</SettingCard>
|
||||
@@ -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 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
{#if unlicensed}
|
||||
<Alert
|
||||
type="info"
|
||||
size="xs"
|
||||
title="Changing workspace roles requires a valid Windmill Enterprise Edition license"
|
||||
<SettingCard label="Roles" settingKey={KEY}>
|
||||
<div class="flex flex-col gap-3 pt-2">
|
||||
{#if unlicensed}
|
||||
<Alert
|
||||
type="info"
|
||||
size="xs"
|
||||
title="Changing workspace roles requires a valid Windmill Enterprise Edition license"
|
||||
>
|
||||
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}
|
||||
<div class="mt-2">
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: RotateCcw }}
|
||||
disabled={loading}
|
||||
onclick={() => ($values[KEY] = undefined)}
|
||||
>
|
||||
Reset to the default roles
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</Alert>
|
||||
{/if}
|
||||
<span class="text-xs text-secondary">
|
||||
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 <code>developer</code>, 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.
|
||||
</span>
|
||||
|
||||
<section
|
||||
class="flex flex-col gap-3"
|
||||
use:dragHandleZone={{
|
||||
items: rows,
|
||||
flipDurationMs,
|
||||
dragDisabled: disabled,
|
||||
// The handle zone is drag-disabled between drags, which would otherwise mark every
|
||||
// input in it aria-disabled.
|
||||
autoAriaDisabled: true,
|
||||
dropTargetStyle: {}
|
||||
}}
|
||||
onconsider={(e) => (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}
|
||||
<div class="mt-2">
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: RotateCcw }}
|
||||
disabled={loading}
|
||||
onclick={() => ($values[KEY] = undefined)}
|
||||
>
|
||||
Reset to the default roles
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</Alert>
|
||||
{/if}
|
||||
<span class="text-xs text-secondary">
|
||||
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 <code>developer</code>, 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.
|
||||
</span>
|
||||
|
||||
<section
|
||||
class="flex flex-col gap-3"
|
||||
use:dragHandleZone={{
|
||||
items: rows,
|
||||
flipDurationMs,
|
||||
dragDisabled: disabled,
|
||||
// The handle zone is drag-disabled between drags, which would otherwise mark every
|
||||
// input in it aria-disabled.
|
||||
autoAriaDisabled: true,
|
||||
dropTargetStyle: {}
|
||||
}}
|
||||
onconsider={(e) => (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)}
|
||||
<div class="flex flex-col rounded-md border bg-surface-tertiary">
|
||||
<div class="flex items-center gap-2 p-2">
|
||||
<div
|
||||
class="shrink-0 flex items-center {disabled
|
||||
? 'text-disabled cursor-not-allowed'
|
||||
: 'text-secondary cursor-move'}"
|
||||
use:dragHandle
|
||||
aria-label="Reorder role {row.name || i + 1}"
|
||||
>
|
||||
<GripVertical size={16} />
|
||||
</div>
|
||||
<div class="flex flex-col gap-0.5 w-40 shrink-0">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={row.name}
|
||||
error={errors[`${i}.name`]}
|
||||
inputProps={{ placeholder: 'name', disabled, 'aria-label': 'Role name' }}
|
||||
/>
|
||||
</div>
|
||||
<span class="text-2xs text-secondary truncate grow">
|
||||
{#if row.label.trim()}
|
||||
<span class="text-primary">{row.label.trim()}</span> ·
|
||||
{/if}
|
||||
{summary(caps)}
|
||||
</span>
|
||||
{#if i === 0}
|
||||
<Badge color="gray" verySmall>Highest</Badge>
|
||||
{/if}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: row.open ? ChevronDown : ChevronRight }}
|
||||
onclick={() => (row.open = !row.open)}
|
||||
>
|
||||
Capabilities
|
||||
</Button>
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
destructive
|
||||
iconOnly
|
||||
startIcon={{ icon: Trash2 }}
|
||||
aria-label="Remove role"
|
||||
title={rows.length === 1 ? 'Keep at least one role' : 'Remove role'}
|
||||
disabled={disabled || rows.length === 1}
|
||||
onclick={() => (rows = rows.filter((r) => r.id !== row.id))}
|
||||
/>
|
||||
</div>
|
||||
{#if errors[`${i}.name`]}
|
||||
<span class="text-2xs text-red-600 dark:text-red-400 px-2 pb-2 -mt-1">
|
||||
{errors[`${i}.name`]}
|
||||
</span>
|
||||
{/if}
|
||||
{#if row.open}
|
||||
<div class="border-t p-3 flex flex-col gap-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs font-semibold text-emphasis w-24">Label</span>
|
||||
<div class="w-60">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={row.label}
|
||||
inputProps={{
|
||||
placeholder: row.name || 'label',
|
||||
disabled,
|
||||
'aria-label': 'Role label'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{#each rows as row, i (row.id)}
|
||||
{@const base = baseCapabilitiesFor(row.name)}
|
||||
{@const caps = resolveCapabilities(base, row.capabilities, false)}
|
||||
<div class="flex flex-col rounded-md border bg-surface-tertiary">
|
||||
<div class="flex items-center gap-2 p-2">
|
||||
<div
|
||||
class="shrink-0 flex items-center {disabled
|
||||
? 'text-disabled cursor-not-allowed'
|
||||
: 'text-secondary cursor-move'}"
|
||||
use:dragHandle
|
||||
aria-label="Reorder role {row.name || i + 1}"
|
||||
>
|
||||
<GripVertical size={16} />
|
||||
</div>
|
||||
<RoleCapabilitiesEditor
|
||||
{base}
|
||||
patch={row.capabilities}
|
||||
baseName={row.name === DEVELOPER_ROLE ? 'developer default' : 'operator default'}
|
||||
setText="Set"
|
||||
inheritedText="Default"
|
||||
{disabled}
|
||||
onchange={(p) => (row.capabilities = p)}
|
||||
<div class="flex flex-col gap-0.5 w-40 shrink-0">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={row.name}
|
||||
error={errors[`${i}.name`]}
|
||||
inputProps={{ placeholder: 'name', disabled, 'aria-label': 'Role name' }}
|
||||
/>
|
||||
</div>
|
||||
<span class="text-2xs text-secondary truncate grow">
|
||||
{#if row.label.trim()}
|
||||
<span class="text-primary">{row.label.trim()}</span> ·
|
||||
{/if}
|
||||
{summary(caps)}
|
||||
</span>
|
||||
{#if i === 0}
|
||||
<Badge color="gray" verySmall>Highest</Badge>
|
||||
{/if}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: row.open ? ChevronDown : ChevronRight }}
|
||||
onclick={() => (row.open = !row.open)}
|
||||
>
|
||||
Capabilities
|
||||
</Button>
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
destructive
|
||||
iconOnly
|
||||
startIcon={{ icon: Trash2 }}
|
||||
aria-label="Remove role"
|
||||
title={rows.length === 1 ? 'Keep at least one role' : 'Remove role'}
|
||||
disabled={disabled || rows.length === 1}
|
||||
onclick={() => (rows = rows.filter((r) => r.id !== row.id))}
|
||||
/>
|
||||
</div>
|
||||
{:else if errors[`${i}.capabilities`]}
|
||||
<span class="text-2xs text-red-600 dark:text-red-400 px-2 pb-2">
|
||||
{errors[`${i}.capabilities`]}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</section>
|
||||
{#if errors[`${i}.name`]}
|
||||
<span class="text-2xs text-red-600 dark:text-red-400 px-2 pb-2 -mt-1">
|
||||
{errors[`${i}.name`]}
|
||||
</span>
|
||||
{/if}
|
||||
{#if row.open}
|
||||
<div class="border-t p-3 flex flex-col gap-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs font-semibold text-emphasis w-24">Label</span>
|
||||
<div class="w-60">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={row.label}
|
||||
inputProps={{
|
||||
placeholder: row.name || 'label',
|
||||
disabled,
|
||||
'aria-label': 'Role label'
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<RoleCapabilitiesEditor
|
||||
{base}
|
||||
patch={row.capabilities}
|
||||
baseName={row.name === DEVELOPER_ROLE ? 'developer default' : 'operator default'}
|
||||
setText="Set"
|
||||
inheritedText="Default"
|
||||
{disabled}
|
||||
onchange={(p) => (row.capabilities = p)}
|
||||
/>
|
||||
</div>
|
||||
{:else if errors[`${i}.capabilities`]}
|
||||
<span class="text-2xs text-red-600 dark:text-red-400 px-2 pb-2">
|
||||
{errors[`${i}.capabilities`]}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</section>
|
||||
|
||||
{#if !disabled}
|
||||
<div>
|
||||
<Button variant="default" unifiedSize="sm" startIcon={{ icon: Plus }} onclick={addRole}>
|
||||
Add role
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if !disabled}
|
||||
<div>
|
||||
<Button variant="default" unifiedSize="sm" startIcon={{ icon: Plus }} onclick={addRole}>
|
||||
Add role
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</SettingCard>
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
<script lang="ts">
|
||||
import { Alert, Button, Skeleton } from '$lib/components/common'
|
||||
import Checkbox from '$lib/components/common/checkbox/Checkbox.svelte'
|
||||
import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte'
|
||||
import { createAsyncConfirmationModal } from '$lib/components/common/confirmationModal/asyncConfirmationModal.svelte'
|
||||
import ToggleButton from '$lib/components/common/toggleButton-v2/ToggleButton.svelte'
|
||||
import ToggleButtonGroup from '$lib/components/common/toggleButton-v2/ToggleButtonGroup.svelte'
|
||||
import DropdownV2 from '$lib/components/DropdownV2.svelte'
|
||||
import TextInput from '$lib/components/text_input/TextInput.svelte'
|
||||
import IconedResourceType from '$lib/components/IconedResourceType.svelte'
|
||||
import { listHubIntegrationsShared } from '$lib/components/displayNameLoaders'
|
||||
import { integrationDisplayName } from '$lib/components/resourceTypeDisplay'
|
||||
import { disableHubStore, hubBaseUrlStore } from '$lib/stores'
|
||||
import type { HubAccess, HubAccessList, ListHubIntegrationsResponse } from '$lib/gen'
|
||||
import { ChevronDown, ExternalLink, SquareCheckBig, X } from 'lucide-svelte'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
type Level = HubAccess | 'none'
|
||||
|
||||
interface Props {
|
||||
value: HubAccessList
|
||||
/** The list as saved, which a row that differs from it shows struck through. */
|
||||
saved: HubAccessList
|
||||
/** Only lists what is allowed, with nothing to change. */
|
||||
readOnly?: boolean
|
||||
onchange: (value: HubAccessList) => void
|
||||
}
|
||||
|
||||
let { value, saved, readOnly = false, onchange }: Props = $props()
|
||||
|
||||
const BULK_WRITE_CONFIRM = 10
|
||||
const COUNT_CAP = 500
|
||||
|
||||
type HubEntry = ListHubIntegrationsResponse[number]
|
||||
/** Hub entries by lowercased name, which is how the server reads the list and the Hub's
|
||||
* integration page its slug. The Hub can hold both `Slack` and `slack`, and counts each apart. */
|
||||
let hubNames: Record<string, HubEntry[]> = $state({})
|
||||
let loading = $state(!$disableHubStore)
|
||||
let hubUnavailable = $state($disableHubStore)
|
||||
if (!$disableHubStore) {
|
||||
listHubIntegrationsShared()
|
||||
.then(
|
||||
(i) => {
|
||||
const names: Record<string, HubEntry[]> = {}
|
||||
for (const e of i) (names[e.name.toLowerCase()] ??= []).push(e)
|
||||
hubNames = names
|
||||
},
|
||||
() => (hubUnavailable = true)
|
||||
)
|
||||
.finally(() => (loading = false))
|
||||
}
|
||||
|
||||
// A listed integration shows even if the Hub is down or no longer has it. The saved ones come
|
||||
// first, and a row does not move while its level changes.
|
||||
const all = $derived.by(() => {
|
||||
const first = new Set(Object.keys(saved))
|
||||
const names = readOnly
|
||||
? Object.keys(value)
|
||||
: [...first, ...Object.keys(value), ...Object.keys(hubNames)]
|
||||
return Array.from(new Set(names))
|
||||
.map((name) => ({ name, label: integrationDisplayName(name) }))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
Number(first.has(b.name)) - Number(first.has(a.name)) || a.label.localeCompare(b.label)
|
||||
)
|
||||
})
|
||||
|
||||
const level = (name: string): Level => value[name] ?? 'none'
|
||||
const savedLevel = (name: string): Level => saved[name] ?? 'none'
|
||||
const LEVEL_LABELS: Record<Level, string> = { none: 'None', read: 'Read', write: 'Write' }
|
||||
const LEVEL_TOOLTIPS: Record<Level, string> = {
|
||||
none: 'No script',
|
||||
read: 'Only the scripts that do not change data',
|
||||
write: 'Every approved script'
|
||||
}
|
||||
|
||||
const VIEWS: { id: string; label: string; keep: (name: string) => boolean; empty: string }[] = [
|
||||
{ id: 'all', label: 'All integrations', keep: () => true, empty: 'No integrations here.' },
|
||||
{
|
||||
id: 'allowed',
|
||||
label: 'Allowed',
|
||||
keep: (n) => level(n) !== 'none',
|
||||
empty: 'No integration is allowed yet.'
|
||||
},
|
||||
{
|
||||
id: 'none',
|
||||
label: 'Not allowed',
|
||||
keep: (n) => level(n) === 'none',
|
||||
empty: 'Every integration is allowed.'
|
||||
},
|
||||
{
|
||||
id: 'changed',
|
||||
label: 'Changed',
|
||||
keep: (n) => level(n) !== savedLevel(n),
|
||||
empty: 'Nothing changed yet.'
|
||||
}
|
||||
]
|
||||
let viewId = $state('all')
|
||||
// Read-only hides the view menu, so the one left selected must not filter the list.
|
||||
const view = $derived((!readOnly && VIEWS.find((v) => v.id === viewId)) || VIEWS[0])
|
||||
let search = $state('')
|
||||
const query = $derived(search.trim().toLowerCase())
|
||||
const found = $derived(
|
||||
all.filter(
|
||||
({ name, label }) =>
|
||||
query === '' || name.includes(query) || label.toLowerCase().includes(query)
|
||||
)
|
||||
)
|
||||
const shown = $derived(found.filter(({ name }) => view.keep(name)))
|
||||
|
||||
// Only what is on screen can be selected, so a bulk change never reaches a hidden row.
|
||||
let selected: string[] = $state([])
|
||||
const selection = $derived(shown.filter((i) => selected.includes(i.name)).map((i) => i.name))
|
||||
// The level every selected row has, if they all have the same.
|
||||
const selectionLevel = $derived.by(() => {
|
||||
const levels = new Set(selection.map(level))
|
||||
return levels.size === 1 ? [...levels][0] : undefined
|
||||
})
|
||||
// Remounts the bulk control after a refused change, which it would otherwise show as made.
|
||||
let bulkControlKey = $state(0)
|
||||
let lastToggled: string | undefined = undefined
|
||||
let shiftHeld = false
|
||||
|
||||
function toggleSelected(name: string) {
|
||||
const names = shown.map((i) => i.name)
|
||||
const from = lastToggled === undefined ? -1 : names.indexOf(lastToggled)
|
||||
if (shiftHeld && from >= 0) {
|
||||
const to = names.indexOf(name)
|
||||
const range = names.slice(Math.min(from, to), Math.max(from, to) + 1)
|
||||
selected = Array.from(new Set([...selection, ...range]))
|
||||
} else {
|
||||
selected = selection.includes(name)
|
||||
? selection.filter((n) => n !== name)
|
||||
: [...selection, name]
|
||||
}
|
||||
lastToggled = name
|
||||
}
|
||||
|
||||
function apply(names: string[], to: Level) {
|
||||
const next = { ...value }
|
||||
for (const n of names) {
|
||||
if (to === 'none') delete next[n]
|
||||
else next[n] = to
|
||||
}
|
||||
onchange(next)
|
||||
}
|
||||
|
||||
const plural = (n: number) => `${n} integration${n === 1 ? '' : 's'}`
|
||||
|
||||
const confirmation = createAsyncConfirmationModal()
|
||||
|
||||
async function setMany(names: string[], to: Level) {
|
||||
const changed = names.filter((n) => level(n) !== to)
|
||||
if (changed.length === 0) return
|
||||
const raised = changed.filter((n) => savedLevel(n) !== 'write')
|
||||
if (to === 'write' && raised.length > BULK_WRITE_CONFIRM) {
|
||||
const ok = await confirmation.ask({
|
||||
title: `Allow writing on ${plural(raised.length)}?`,
|
||||
confirmationText: 'Set to write',
|
||||
type: 'info',
|
||||
children:
|
||||
'<span>Members whose role cannot write code may then use all of their approved Hub scripts, including those that change data.</span>'
|
||||
})
|
||||
if (!ok) {
|
||||
bulkControlKey++
|
||||
return
|
||||
}
|
||||
}
|
||||
apply(changed, to)
|
||||
}
|
||||
|
||||
const changes = $derived.by(() => {
|
||||
const names = Array.from(new Set([...Object.keys(saved), ...Object.keys(value)]))
|
||||
const count = (f: (n: string) => boolean) => names.filter(f).length
|
||||
return [
|
||||
[count((n) => !saved[n]), 'added'],
|
||||
[count((n) => !!saved[n] && !!value[n] && saved[n] !== value[n]), 'changed'],
|
||||
[count((n) => !value[n]), 'removed']
|
||||
]
|
||||
.filter(([n]) => n)
|
||||
.map(([n, what]) => `${n} ${what}`)
|
||||
.join(', ')
|
||||
})
|
||||
|
||||
const summary = $derived.by(() => {
|
||||
const levels = Object.values(value)
|
||||
const read = levels.filter((l) => l === 'read').length
|
||||
return levels.length === 0
|
||||
? 'No Hub scripts are allowed'
|
||||
: `${levels.length} allowed: ${read} read, ${levels.length - read} write`
|
||||
})
|
||||
const everyAllowed = $derived(
|
||||
!readOnly && !hubUnavailable && all.every(({ name }) => level(name) !== 'none')
|
||||
)
|
||||
|
||||
const capped = (n: number) => (n > COUNT_CAP ? `${COUNT_CAP}+` : `${n}`)
|
||||
/** Summed over every spelling; nothing on a Hub that does not count. */
|
||||
function countsLabel(name: string): string | undefined {
|
||||
const entries = hubNames[name] ?? []
|
||||
if (entries.length === 0 || entries.some((e) => e.approved_scripts === undefined)) return
|
||||
const total = entries.reduce((n, e) => n + (e.approved_scripts ?? 0), 0)
|
||||
const readOnly = entries.reduce((n, e) => n + (e.read_only_scripts ?? 0), 0)
|
||||
return total === 0
|
||||
? 'No approved script'
|
||||
: `${capped(total)} ${total === 1 ? 'script' : 'scripts'}, ${capped(readOnly)} read-only`
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet icon(name: string)}
|
||||
<!-- The fallback icon ignores its size. -->
|
||||
<div class="shrink-0 [&_svg]:size-[18px]">
|
||||
<IconedResourceType {name} silent height="18px" width="18px" />
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<TextInput
|
||||
bind:value={search}
|
||||
size="sm"
|
||||
class="w-52 max-w-full"
|
||||
inputProps={{ placeholder: 'Search integrations', 'aria-label': 'Search integrations' }}
|
||||
/>
|
||||
{#if !readOnly}
|
||||
<DropdownV2
|
||||
placement="bottom-start"
|
||||
fixedHeight={false}
|
||||
items={VIEWS.map((v) => ({
|
||||
displayName: v.label,
|
||||
selected: v.id === view.id,
|
||||
action: () => (viewId = v.id)
|
||||
}))}
|
||||
>
|
||||
{#snippet buttonReplacement()}
|
||||
<Button
|
||||
nonCaptureEvent
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
title="Filter the list"
|
||||
endIcon={{ icon: ChevronDown }}
|
||||
>
|
||||
{view.label}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownV2>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class={twMerge(
|
||||
'flex rounded-md border border-border-light overflow-hidden',
|
||||
readOnly ? 'max-h-[320px]' : 'h-[320px]'
|
||||
)}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Escape' && selection.length > 0) {
|
||||
e.preventDefault()
|
||||
selected = []
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div class="relative flex flex-col grow min-w-0 min-h-0 bg-surface-tertiary">
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div
|
||||
class={twMerge('grow min-h-0 overflow-y-auto', selection.length > 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}
|
||||
<div class="p-3">
|
||||
<Alert type="info" size="xs" title="The Hub is unavailable">
|
||||
Only the integrations already allowed are shown.
|
||||
</Alert>
|
||||
</div>
|
||||
{/if}
|
||||
{#if loading && !readOnly}
|
||||
<div class="p-3"><Skeleton layout={[[2], 0.5, [2], 0.5, [2]]} /></div>
|
||||
{:else}
|
||||
<div class="flex flex-col divide-y divide-border-light">
|
||||
{#each shown as { name, label } (name)}
|
||||
{@const page = hubNames[name] && `${$hubBaseUrlStore}/integrations/${name}`}
|
||||
{@const count = countsLabel(name)}
|
||||
<div class="group/row flex items-center gap-3 px-3 py-1.5 hover:bg-surface-hover">
|
||||
<!-- As on Home: the icon until the row is hovered or anything is selected, then
|
||||
the checkbox, stacked so nothing shifts. -->
|
||||
<div class="shrink-0 relative size-[18px]">
|
||||
<div
|
||||
class={twMerge(
|
||||
'absolute inset-0',
|
||||
readOnly
|
||||
? ''
|
||||
: selection.length > 0
|
||||
? 'invisible'
|
||||
: 'group-hover/row:invisible'
|
||||
)}
|
||||
>
|
||||
{@render icon(name)}
|
||||
</div>
|
||||
{#if !readOnly}
|
||||
<Checkbox
|
||||
class={twMerge(
|
||||
'absolute inset-px w-4 h-4',
|
||||
selection.length > 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}
|
||||
</div>
|
||||
<div class="grow min-w-0 flex flex-wrap items-center gap-x-2">
|
||||
{#if page}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
href={page}
|
||||
target="_blank"
|
||||
title="Open its scripts on the Hub"
|
||||
endIcon={{ icon: ExternalLink, classes: 'text-hint' }}
|
||||
wrapperClasses="min-w-0"
|
||||
btnClasses="min-w-0 px-0 hover:bg-transparent hover:underline"
|
||||
>
|
||||
<span class="text-xs font-semibold text-emphasis truncate">{label}</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<span class="text-xs font-semibold text-emphasis truncate">{label}</span>
|
||||
{/if}
|
||||
{#if count}
|
||||
<span class="text-2xs text-secondary">{count}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if level(name) !== savedLevel(name)}
|
||||
<span class="shrink-0 text-2xs text-secondary" title="Saved value">
|
||||
<span class="line-through">{LEVEL_LABELS[savedLevel(name)]}</span> →
|
||||
</span>
|
||||
{/if}
|
||||
<div class="shrink-0">
|
||||
<!-- Bound, not passed: once clicked, the group keeps its own copy of a plain
|
||||
prop and misses a bulk change. The setter also hears bulk changes. -->
|
||||
<ToggleButtonGroup
|
||||
noWFull
|
||||
disabled={readOnly}
|
||||
bind:selected={
|
||||
() => level(name), (v) => v !== level(name) && apply([name], v as Level)
|
||||
}
|
||||
>
|
||||
{#snippet children({ item })}
|
||||
<ToggleButton value="none" label="None" small {item} />
|
||||
<ToggleButton value="read" label="Read" small {item} />
|
||||
<ToggleButton value="write" label="Write" small {item} />
|
||||
{/snippet}
|
||||
</ToggleButtonGroup>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<p class="px-3 py-4 text-xs text-secondary">
|
||||
{query !== '' ? `No integration matches "${search.trim()}".` : view.empty}
|
||||
</p>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if selection.length > 0}
|
||||
<div class="absolute bottom-3 inset-x-0 flex justify-center pointer-events-none">
|
||||
<div
|
||||
transition:fly={{ y: 16, duration: 150 }}
|
||||
class="pointer-events-auto flex items-center gap-2 rounded-md border bg-surface px-2 py-1.5 shadow-lg whitespace-nowrap"
|
||||
>
|
||||
<span class="text-xs font-semibold text-emphasis">
|
||||
{selection.length < shown.length
|
||||
? `${selection.length} selected`
|
||||
: `All ${shown.length} selected`}
|
||||
</span>
|
||||
<div class="h-4 border-l"></div>
|
||||
<span class="text-xs text-secondary">Set to</span>
|
||||
{#key bulkControlKey}
|
||||
<!-- The group ignores `undefined`, so a mixed selection is a value no button has. -->
|
||||
<ToggleButtonGroup noWFull selected={selectionLevel ?? ''}>
|
||||
{#snippet children({ item })}
|
||||
{#each ['none', 'read', 'write'] as const as to (to)}
|
||||
<ToggleButton
|
||||
value={to}
|
||||
label={LEVEL_LABELS[to]}
|
||||
tooltip={LEVEL_TOOLTIPS[to]}
|
||||
small
|
||||
{item}
|
||||
onActivate={() => setMany(selection, to)}
|
||||
/>
|
||||
{/each}
|
||||
{/snippet}
|
||||
</ToggleButtonGroup>
|
||||
{/key}
|
||||
<div class="h-4 border-l"></div>
|
||||
{#if selection.length < shown.length}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: SquareCheckBig }}
|
||||
title="Select every integration shown"
|
||||
onclick={() => (selected = shown.map((i) => i.name))}
|
||||
>
|
||||
All
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
iconOnly
|
||||
startIcon={{ icon: X }}
|
||||
title="Clear selection (Esc)"
|
||||
aria-label="Clear selection"
|
||||
onclick={() => (selected = [])}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="text-xs text-secondary">
|
||||
{summary}{#if changes !== ''}. <span class="font-semibold text-emphasis">{changes}</span
|
||||
>{#if everyAllowed}. New Hub integrations start at None{/if}{/if}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ConfirmationModal {...confirmation.props} />
|
||||
@@ -0,0 +1,81 @@
|
||||
<script lang="ts">
|
||||
import { Section } from '$lib/components/common'
|
||||
import SettingsFooter from '$lib/components/workspaceSettings/SettingsFooter.svelte'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import HubAccessEditor from './HubAccessEditor.svelte'
|
||||
import { HUB_ACCESS_DESCRIPTION } from '$lib/workspaceRoles'
|
||||
import { WorkspaceService, type HubAccessList, type WorkspaceRoles } from '$lib/gen'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import { untrack } from 'svelte'
|
||||
|
||||
interface Props {
|
||||
workspace: string
|
||||
/** The workspace's roles as last read; undefined while loading. */
|
||||
data: WorkspaceRoles | undefined
|
||||
onSaved: () => void
|
||||
}
|
||||
|
||||
let { workspace, data, onSaved }: Props = $props()
|
||||
|
||||
function canonical(list: HubAccessList | null | undefined): string {
|
||||
return JSON.stringify(list ? Object.entries(list).sort() : null)
|
||||
}
|
||||
|
||||
const stored = $derived(data && canonical(data.hub_access))
|
||||
|
||||
/** `null` follows the instance's list. Reset only when the stored list changed: saving the roles
|
||||
* reloads `data` too, and must not drop an edit here. */
|
||||
let draft: HubAccessList | null = $derived.by(() => {
|
||||
void stored
|
||||
return untrack(() => data?.hub_access ?? null)
|
||||
})
|
||||
const dirty = $derived(stored !== undefined && canonical(draft) !== stored)
|
||||
|
||||
async function save() {
|
||||
await WorkspaceService.updateWorkspaceHubAccess({
|
||||
workspace,
|
||||
requestBody: { hub_access: draft }
|
||||
})
|
||||
sendUserToast('Hub scripts saved')
|
||||
onSaved()
|
||||
}
|
||||
</script>
|
||||
|
||||
<Section
|
||||
label="Hub scripts"
|
||||
collapsable={true}
|
||||
description="{HUB_ACCESS_DESCRIPTION} This workspace uses the instance's list, or replaces it with its own."
|
||||
>
|
||||
{#snippet action()}
|
||||
<SettingsFooter
|
||||
inline
|
||||
class="w-auto"
|
||||
hasUnsavedChanges={dirty}
|
||||
onSave={save}
|
||||
onDiscard={() => (draft = data?.hub_access ?? null)}
|
||||
saveLabel="Save Hub scripts"
|
||||
/>
|
||||
{/snippet}
|
||||
|
||||
{#if !data}
|
||||
<span class="text-xs text-secondary">Loading Hub scripts...</span>
|
||||
{:else}
|
||||
<div class="flex flex-col gap-3">
|
||||
<Toggle
|
||||
checked={draft === null}
|
||||
options={{ right: 'Use the instance list' }}
|
||||
on:change={(e) => (draft = e.detail ? null : { ...(data?.instance_hub_access ?? {}) })}
|
||||
/>
|
||||
<!-- A fresh editor per mode: a selection kept from editing would otherwise still change
|
||||
the list, and so stop following the instance's. -->
|
||||
{#key draft === null}
|
||||
<HubAccessEditor
|
||||
value={draft ?? data.instance_hub_access}
|
||||
saved={data.hub_access ?? data.instance_hub_access}
|
||||
readOnly={draft === null}
|
||||
onchange={(v) => (draft = v)}
|
||||
/>
|
||||
{/key}
|
||||
</div>
|
||||
{/if}
|
||||
</Section>
|
||||
@@ -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<string, RoleOverride>()
|
||||
let loadedFrom: WorkspaceRoles | undefined = undefined
|
||||
const open = new SvelteMap<string, boolean>()
|
||||
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<string, string> = Object.create(null)
|
||||
|
||||
@@ -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 @@
|
||||
<div class="pt-12"></div>
|
||||
|
||||
{#if $workspaceStore}
|
||||
<WorkspaceRoleOverrides workspace={$workspaceStore} data={workspaceRoles} onSaved={loadRoles} />
|
||||
<!-- Unsaved edits must not follow a workspace switch: Save would write them to the new one. -->
|
||||
{#key $workspaceStore}
|
||||
<WorkspaceRoleOverrides workspace={$workspaceStore} data={workspaceRoles} onSaved={loadRoles} />
|
||||
|
||||
<div class="pt-12"></div>
|
||||
|
||||
<WorkspaceHubAccess workspace={$workspaceStore} data={workspaceRoles} onSaved={loadRoles} />
|
||||
{/key}
|
||||
{/if}
|
||||
|
||||
<div class="pt-12"></div>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user