diff --git a/frontend/src/lib/components/settings/MemberWorkspaceSettings.svelte b/frontend/src/lib/components/settings/MemberWorkspaceSettings.svelte new file mode 100644 index 0000000000..1b62115862 --- /dev/null +++ b/frontend/src/lib/components/settings/MemberWorkspaceSettings.svelte @@ -0,0 +1,58 @@ + + +
+
+ You are a member of {workspaceName} +

+ Only workspace admins can change its settings. Ask one of them if something here needs to + change. +

+
+ + (confirmOpen = true) } + ]} + > + Leaving removes your access to {workspaceName} right away: its scripts, flows, apps, resources + and runs. You cannot rejoin by yourself. A workspace admin has to add you again. + +
+ + (confirmOpen = false)} + onConfirmed={() => { + confirmOpen = false + void leave() + }} +> +

+ You will lose access to {workspaceName}. Only a workspace admin can add you back. +

+
diff --git a/frontend/src/lib/components/sidebar/SettingsMenu.svelte b/frontend/src/lib/components/sidebar/SettingsMenu.svelte index 13f38840d4..4267df7508 100644 --- a/frontend/src/lib/components/sidebar/SettingsMenu.svelte +++ b/frontend/src/lib/components/sidebar/SettingsMenu.svelte @@ -24,12 +24,10 @@ import { goto } from '$lib/navigation' import { type Item } from '$lib/utils' import { logout } from '$lib/logoutKit' - import { leaveCurrentWorkspace } from './leaveWorkspace' import { isCloudHosted } from '$lib/cloud' import DropdownV2 from '$lib/components/DropdownV2.svelte' - import ConfirmationModal from '../common/confirmationModal/ConfirmationModal.svelte' import DeleteForkedWorkspaceModal from './DeleteForkedWorkspaceModal.svelte' - import { workspaceIsFork, isForkOwner } from '$lib/utils/workspaceHierarchy' + import { workspaceIsFork } from '$lib/utils/workspaceHierarchy' import DarkModeObserver from '../DarkModeObserver.svelte' import DiscordIcon from '../icons/brands/Discord.svelte' import MenuLink from './MenuLink.svelte' @@ -57,9 +55,8 @@ // Session mode: workspace the workspace-settings entry should target — // the session's own (possibly forked) workspace, which can differ from // the rail's active workspace, so the entry's href carries it as the - // `workspace` query param. Also hides "Leave workspace" (leaving a - // workspace from the session rail makes no sense). Unset = navigation - // mode, entry targets the active workspace. + // `workspace` query param. Unset = navigation mode, entry targets the + // active workspace. workspaceSettingsTarget = undefined, numUnacknowledgedCriticalAlerts = 0, // Overridable so the kitchen-sink page can preview the cloud variant @@ -80,14 +77,6 @@ : undefined ) - // The fork-owner grant must be checked against the workspace the settings entry - // actually points at — the session target when in session mode, else the active - // workspace — otherwise ownership of the wrong workspace could hide the entry or - // expose a dead link to a fork the user doesn't own. - const settingsWs = $derived(workspaceSettingsTarget ? settingsTargetWs : currentWs) - const canManageWorkspace = $derived( - $userStore?.is_admin || $superadmin || isForkOwner(settingsWs, $userStore?.email) - ) // Fork/dev workspaces are detected by their parent link, not the `wm-fork-` id prefix. A dev // workspace is excluded: it is a standing environment its whole team works in, torn down by // detaching it in the dev-workspace settings, so offering a one-click delete beside the account @@ -101,7 +90,6 @@ !currentWs.is_dev_workspace ) - let leaveWorkspaceModal = $state(false) let deleteForkModal = $state() const { recent: recentChangelogs, hasNew } = readRecentChangelogs() @@ -157,20 +145,10 @@ // Account / instance actions gathered under one "Settings" dropdown, shared by // the session rail and the global sidebar so both expose the same entry point. - // Logout lives inside the user submenu with the other account-scoped entries. - // Workspace- and instance-scoped entries anchor the bottom of the menu, - // instance settings last. + // Workspace- and instance-scoped entries sit between the account entries and Logout. + // Leaving a workspace lives on the workspace settings page, which every member reaches, + // not in this menu next to Logout: only a workspace admin can undo a leave. const workspaceInstanceItems = $derived([ - ...(!canManageWorkspace && !workspaceSettingsTarget - ? [ - { - displayName: 'Leave workspace', - icon: LogOut, - type: 'delete' as const, - action: () => (leaveWorkspaceModal = true) - } - ] - : []), // Fork deletion is a global-sidebar action on the active workspace, so keep it // out of the session rail's per-target settings entry (`workspaceSettingsTarget`). ...(currentWsIsThrowawayFork && !workspaceSettingsTarget @@ -183,23 +161,19 @@ } ] : []), - ...(canManageWorkspace - ? [ - workspaceSettingsTarget - ? { - displayName: `${settingsTargetWs?.name ?? workspaceSettingsTarget} settings`, - icon: Building, - // The `workspace` query param switches the app to the target - // workspace on arrival (full loads and client-side navs alike). - href: `/workspace_settings?workspace=${workspaceSettingsTarget}` - } - : { - displayName: `${currentWs?.name ?? $workspaceStore ?? 'Workspace'} settings`, - icon: Building, - href: '/workspace_settings' - } - ] - : []), + workspaceSettingsTarget + ? { + displayName: `${settingsTargetWs?.name ?? workspaceSettingsTarget} settings`, + icon: Building, + // The `workspace` query param switches the app to the target + // workspace on arrival (full loads and client-side navs alike). + href: `/workspace_settings?workspace=${workspaceSettingsTarget}` + } + : { + displayName: `${currentWs?.name ?? $workspaceStore ?? 'Workspace'} settings`, + icon: Building, + href: '/workspace_settings' + }, ...($superadmin ? [ { @@ -268,18 +242,16 @@ disabled: true } ] - : []), - { displayName: 'Logout', icon: LogOut, action: () => logout() } + : []) ] }, - ...workspaceInstanceItems.map((item, i) => (i === 0 ? { ...item, separatorTop: true } : item)) + ...workspaceInstanceItems.map((item, i) => (i === 0 ? { ...item, separatorTop: true } : item)), + { displayName: 'Logout', icon: LogOut, action: () => logout(), separatorTop: true } ]) const logsItems = $derived([ { displayName: 'Audit logs', icon: Eye, href: '/audit_logs' }, - ...($devopsRole - ? [{ displayName: 'Service logs', icon: Logs, href: '/service_logs' }] - : []), + ...($devopsRole ? [{ displayName: 'Service logs', icon: Logs, href: '/service_logs' }] : []), ...($enterpriseLicense ? [ { @@ -408,26 +380,6 @@ {/snippet} - - { - leaveWorkspaceModal = false - }} - on:confirmed={() => { - leaveWorkspaceModal = false - void leaveCurrentWorkspace() - }} -> -
- Are you sure you want to leave this workspace? -
-
- diff --git a/frontend/src/lib/components/sidebar/SidebarContent.svelte b/frontend/src/lib/components/sidebar/SidebarContent.svelte index f08446d4ed..88a34bbdd1 100644 --- a/frontend/src/lib/components/sidebar/SidebarContent.svelte +++ b/frontend/src/lib/components/sidebar/SidebarContent.svelte @@ -4,14 +4,12 @@ superadmin, usedTriggerKinds, userStore, - userWorkspaces, workspaceStore, isCriticalAlertsUIOpen, enterpriseLicense, devopsRole, roleCapabilities } from '$lib/stores' - import { isForkOwner } from '$lib/utils/workspaceHierarchy' import { SIDEBAR_SHOW_SCHEDULES } from '$lib/consts' import { NAV_PAGES } from './navPages' import { @@ -23,7 +21,6 @@ FolderCog, Github, HelpCircle, - LogOut, Newspaper, Route, Settings, @@ -40,7 +37,6 @@ import { slide } from 'svelte/transition' import UserMenu from './UserMenu.svelte' import DiscordIcon from '../icons/brands/Discord.svelte' - import ConfirmationModal from '../common/confirmationModal/ConfirmationModal.svelte' import { twMerge } from 'tailwind-merge' import { page } from '$app/state' import SideBarNotification from './SideBarNotification.svelte' @@ -65,7 +61,6 @@ import MenuButton from './MenuButton.svelte' import GoogleCloudIcon from '../icons/triggers/GoogleCloudIcon.svelte' import AzureIcon from '../icons/triggers/AzureIcon.svelte' - import { leaveCurrentWorkspace } from './leaveWorkspace' import type { VisibilityKey } from '$lib/roleCapabilities' import { markChangelogsOpened, readRecentChangelogs } from './changelogs' @@ -173,8 +168,6 @@ excludeMainLabels = [] }: Props = $props() - let leaveWorkspaceModal = $state(false) - function computeAllNotificationsCount(menuItems: any[]) { let count = 0 for (const menuItem of menuItems) { @@ -183,7 +176,6 @@ return count } - const currentWs = $derived($userWorkspaces?.find((w) => w.id === $workspaceStore)) function allows(key: VisibilityKey) { return $roleCapabilities.visibility[key] } @@ -372,11 +364,6 @@ let showTriggersGroup = $derived( showAddTriggerMenu || triggerMenuLinks.some((link) => !link.disabled) ) - // Admins, superadmins, and fork creators reach workspace settings (the latter - // for the fork members screen; see isForkOwner / backend authorize_fork_owner_add_user). - const canManageWorkspace = $derived( - $userStore?.is_admin || $superadmin || isForkOwner(currentWs, $userStore?.email) - ) let secondaryMenuLinks = $derived([ // { // label: 'Workspace', @@ -399,18 +386,14 @@ aiDescription: 'Button to navigate to account settings', faIcon: undefined }, - ...(canManageWorkspace - ? [ - { - label: 'Workspace', - href: '/workspace_settings', - icon: FolderCog, - aiId: 'sidebar-menu-link-workspace', - aiDescription: 'Button to navigate to workspace settings', - faIcon: undefined - } - ] - : []), + { + label: 'Workspace', + href: '/workspace_settings', + icon: FolderCog, + aiId: 'sidebar-menu-link-workspace', + aiDescription: 'Button to navigate to workspace settings', + faIcon: undefined + }, ...($superadmin ? [ { @@ -422,19 +405,6 @@ faIcon: undefined } ] - : []), - ...(!$superadmin && !$userStore?.is_admin - ? [ - { - label: 'Leave workspace', - action: () => { - leaveWorkspaceModal = true - }, - class: 'text-red-400', - icon: LogOut, - faIcon: undefined - } - ] : []) ], disabled: !$roleCapabilities.code @@ -721,22 +691,3 @@ {/if} - - - { - leaveWorkspaceModal = false - }} - on:confirmed={() => { - void leaveCurrentWorkspace() - }} -> -
- Are you sure you want to leave this workspace? -
-
diff --git a/frontend/src/lib/components/sidebar/leaveWorkspace.ts b/frontend/src/lib/components/sidebar/leaveWorkspace.ts deleted file mode 100644 index 043748b0c4..0000000000 --- a/frontend/src/lib/components/sidebar/leaveWorkspace.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { get } from 'svelte/store' -import { goto } from '$lib/navigation' -import { WorkspaceService } from '$lib/gen' -import { sendUserToast } from '$lib/toast' -import { clearStores } from '$lib/storeUtils' -import { workspaceStore } from '$lib/stores' - -// Leave the active workspace and land on the workspace list. Shared by the -// settings dropdown and the sidebar menu. -export async function leaveCurrentWorkspace(): Promise { - await WorkspaceService.leaveWorkspace({ workspace: get(workspaceStore) ?? '' }) - sendUserToast('You left the workspace') - clearStores() - await goto('/user/workspaces') -} diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 2f645f8953..fc5600e592 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -28,6 +28,7 @@ import WorkspaceUserSettings from '$lib/components/settings/WorkspaceUserSettings.svelte' import ForkMemberSettings from '$lib/components/settings/ForkMemberSettings.svelte' import SettingsPageHeader from '$lib/components/settings/SettingsPageHeader.svelte' + import MemberWorkspaceSettings from '$lib/components/settings/MemberWorkspaceSettings.svelte' import { WORKSPACE_SHOW_SLACK_CMD, WORKSPACE_SHOW_WEBHOOK_CLI_SYNC } from '$lib/consts' import { OauthService, @@ -2840,10 +2841,8 @@ export async function main( {:else} - + + {/if}