mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 16:20:25 +00:00
fix: make bypassing a disable-forking rule an explicit choice when forking (#12195)
* fix: make bypassing a disable-forking rule an explicit choice when forking Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep forking disabled until the base's protection rules are read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name bypass groups in the fork restriction alert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: space the fork page header from the form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
18156291d4
commit
09082918a6
@@ -16,7 +16,7 @@
|
||||
|
||||
<CenteredModal title="{isFork ? 'Forking' : 'New'} Workspace" centerVertically={false}>
|
||||
{#if isFork}
|
||||
<div class="flex flex-block gap-2">
|
||||
<div class="flex flex-block gap-2 mb-6">
|
||||
<GitForkIcon size={16} />
|
||||
<span class="text-xs text-normal">Forking </span>
|
||||
<span class="text-xs text-emphasis font-semibold">
|
||||
|
||||
@@ -38,8 +38,10 @@
|
||||
import {
|
||||
canUserBypassRuleKindInRulesets,
|
||||
fetchProtectionRulesForWorkspace,
|
||||
getActiveRulesetsForKindInRulesets,
|
||||
isRuleActiveInRulesets,
|
||||
isRuleUnconditionallyActiveInRulesets
|
||||
isRuleUnconditionallyActiveInRulesets,
|
||||
readProtectionRulesForWorkspace
|
||||
} from '$lib/workspaceProtectionRules.svelte'
|
||||
import { resource } from 'runed'
|
||||
import { getUserExt } from '$lib/user'
|
||||
@@ -292,24 +294,58 @@
|
||||
// ParentWorkspaceProtectionAlert.
|
||||
const baseRuleContext = resource(
|
||||
() => (isFork ? baseWorkspaceId : undefined),
|
||||
async (ws) => {
|
||||
async (ws, _prev, { signal }) => {
|
||||
if (!ws) return undefined
|
||||
const [rules, user] = await Promise.all([
|
||||
fetchProtectionRulesForWorkspace(ws),
|
||||
getUserExt(ws)
|
||||
])
|
||||
return { rules, user }
|
||||
const [rules, user] = await Promise.all([readProtectionRulesForWorkspace(ws), getUserExt(ws)])
|
||||
if (signal.aborted) throw new DOMException('superseded', 'AbortError')
|
||||
return { ws, rules, user }
|
||||
}
|
||||
)
|
||||
let requireIsolation = $derived.by(() => {
|
||||
const ctx = baseRuleContext.current
|
||||
const rules = ctx?.rules ?? []
|
||||
return (
|
||||
!!ctx &&
|
||||
isRuleActiveInRulesets(ctx.rules, 'RequireIsolatedForks') &&
|
||||
!canUserBypassRuleKindInRulesets(ctx.rules, 'RequireIsolatedForks', ctx.user)
|
||||
isRuleActiveInRulesets(rules, 'RequireIsolatedForks') &&
|
||||
!canUserBypassRuleKindInRulesets(rules, 'RequireIsolatedForks', ctx.user)
|
||||
)
|
||||
})
|
||||
|
||||
// The server lets admins and the rulesets' bypass list fork past `DisableWorkspaceForking`
|
||||
// silently, so the form makes that an explicit choice, as direct deployment does. It fails
|
||||
// closed: until the selected base's rules are read, nobody can tell whether a bypass applies.
|
||||
let baseRulesForSelection = $derived.by(() => {
|
||||
const ctx = baseRuleContext.current
|
||||
return ctx && ctx.ws === baseWorkspaceId ? ctx : undefined
|
||||
})
|
||||
let baseRulesUnreadable = $derived(
|
||||
!!baseRulesForSelection && baseRulesForSelection.rules === undefined
|
||||
)
|
||||
let forkingRulesets = $derived(
|
||||
getActiveRulesetsForKindInRulesets(
|
||||
baseRulesForSelection?.rules ?? [],
|
||||
'DisableWorkspaceForking'
|
||||
)
|
||||
)
|
||||
let canBypassForkingRule = $derived(
|
||||
canUserBypassRuleKindInRulesets(
|
||||
forkingRulesets,
|
||||
'DisableWorkspaceForking',
|
||||
baseRulesForSelection?.user
|
||||
)
|
||||
)
|
||||
let forkingBypassConfirmed = $state(false)
|
||||
$effect(() => {
|
||||
baseWorkspaceId
|
||||
forkingBypassConfirmed = false
|
||||
})
|
||||
let forkingBlocked = $derived(
|
||||
isFork &&
|
||||
!!baseWorkspaceId &&
|
||||
(baseRulesForSelection?.rules === undefined ||
|
||||
(forkingRulesets.length > 0 && !(canBypassForkingRule && forkingBypassConfirmed)))
|
||||
)
|
||||
|
||||
let workspaceColor: string | undefined = $state(undefined)
|
||||
let colorEnabled = $state(false)
|
||||
let errorHandlerFallbackToInstanceAlerts = $state(false)
|
||||
@@ -788,6 +824,40 @@
|
||||
{/if}
|
||||
</Alert>
|
||||
{/if}
|
||||
{#if isFork && baseRulesUnreadable}
|
||||
<Alert type="error" title="Could not read {currentWorkspaceName}'s protection rules">
|
||||
Forking stays disabled until they can be checked. Reload the page to try again.
|
||||
</Alert>
|
||||
{:else if isFork && forkingRulesets.length > 0}
|
||||
<Alert
|
||||
type={canBypassForkingRule ? 'warning' : 'error'}
|
||||
title="Forking {currentWorkspaceName} is restricted"
|
||||
>
|
||||
<div class="flex flex-col gap-2">
|
||||
<p>
|
||||
The protection rule{forkingRulesets.length > 1 ? 's' : ''}
|
||||
<b>{forkingRulesets.map((r) => r.name).join(', ')}</b>
|
||||
disable{forkingRulesets.length > 1 ? '' : 's'} forking this workspace.
|
||||
{#if canBypassForkingRule}
|
||||
You can bypass {forkingRulesets.length > 1 ? 'them' : 'it'} as
|
||||
{baseRulesForSelection?.user?.is_admin ||
|
||||
baseRulesForSelection?.user?.is_super_admin
|
||||
? 'an admin'
|
||||
: 'one of its bypass users or groups'}.
|
||||
{:else}
|
||||
Only workspace admins and the rule's bypass users and groups can fork it.
|
||||
{/if}
|
||||
</p>
|
||||
{#if canBypassForkingRule}
|
||||
<Toggle
|
||||
size="xs"
|
||||
bind:checked={forkingBypassConfirmed}
|
||||
options={{ right: 'Bypass the restriction and fork anyway' }}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
</Alert>
|
||||
{/if}
|
||||
{#if !isFork}
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="text-xs font-semibold text-emphasis">Workspace name</span>
|
||||
@@ -1215,6 +1285,7 @@
|
||||
<Button
|
||||
variant="accent"
|
||||
disabled={checking ||
|
||||
forkingBlocked ||
|
||||
errorId != '' ||
|
||||
!name ||
|
||||
(!automateUsernameCreation && (errorUser != '' || !username)) ||
|
||||
|
||||
Reference in New Issue
Block a user