Remove Admin option from header profile dropdown
User management is now centralized in AuthGuard's webui, so the per-project Admin dialog (user CRUD + require-login toggle) is redundant. The require-login toggle will move to ProjectConfigurator in the future. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72c3ba028c
commit
07cf3308da
5 files changed
+4
-167
No files matched your search
@@ -5,21 +5,12 @@
|
|||||||
import AuthPage from '$lib/components/AuthPage.svelte'
|
import AuthPage from '$lib/components/AuthPage.svelte'
|
||||||
import ProjectIcon from '$lib/components/ProjectIcon.svelte'
|
import ProjectIcon from '$lib/components/ProjectIcon.svelte'
|
||||||
import AboutWorkspace from '$lib/features/AboutWorkspace.svelte'
|
import AboutWorkspace from '$lib/features/AboutWorkspace.svelte'
|
||||||
import { AboutDialog, AdminDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
import { AboutDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
||||||
import type {
|
import type { AuthLoginInput, AuthSetupInput, ProfileUpdateInput } from '@gabriel20xx/web-ui'
|
||||||
AuthLoginInput,
|
|
||||||
AuthSetupInput,
|
|
||||||
ManagedUser,
|
|
||||||
ProfileUpdateInput,
|
|
||||||
UserCreateInput,
|
|
||||||
UserId,
|
|
||||||
UserRole,
|
|
||||||
UserUpdateInput,
|
|
||||||
} from '@gabriel20xx/web-ui'
|
|
||||||
import SettingsDialog from '$lib/components/SettingsDialog.svelte'
|
import SettingsDialog from '$lib/components/SettingsDialog.svelte'
|
||||||
import { getPanelForPath } from '$lib/app-config'
|
import { getPanelForPath } from '$lib/app-config'
|
||||||
import { pageActions } from '$lib/stores/page-actions.svelte'
|
import { pageActions } from '$lib/stores/page-actions.svelte'
|
||||||
import { del, get, post, put } from '$lib/api'
|
import { get, post, put } from '$lib/api'
|
||||||
import '$lib/language.svelte'
|
import '$lib/language.svelte'
|
||||||
import type { AppConfig, AuthState, AuthUser } from '$lib/types'
|
import type { AppConfig, AuthState, AuthUser } from '$lib/types'
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
@@ -36,7 +27,6 @@
|
|||||||
let settingsOpen = $state(false)
|
let settingsOpen = $state(false)
|
||||||
let aboutOpen = $state(false)
|
let aboutOpen = $state(false)
|
||||||
let profileOpen = $state(false)
|
let profileOpen = $state(false)
|
||||||
let adminOpen = $state(false)
|
|
||||||
|
|
||||||
// Header only renders its profile/settings menu when username is truthy - with login not
|
// Header only renders its profile/settings menu when username is truthy - with login not
|
||||||
// required and nobody signed in, auth.user is legitimately null (there's no session to read
|
// required and nobody signed in, auth.user is legitimately null (there's no session to read
|
||||||
@@ -56,11 +46,6 @@
|
|||||||
const activeNavItem = $derived(
|
const activeNavItem = $derived(
|
||||||
app.nav.find((item) => item.panel === getPanelForPath(app, page.url.pathname)) || app.nav[0],
|
app.nav.find((item) => item.panel === getPanelForPath(app, page.url.pathname)) || app.nav[0],
|
||||||
)
|
)
|
||||||
const currentRole = $derived<UserRole>(
|
|
||||||
auth.user?.role === 'superadmin' || auth.user?.role === 'admin' ? auth.user.role : 'user',
|
|
||||||
)
|
|
||||||
const currentUserId = $derived<UserId | undefined>(auth.user?.id)
|
|
||||||
const isAdmin = $derived(currentRole === 'admin' || currentRole === 'superadmin')
|
|
||||||
|
|
||||||
function openSettings() {
|
function openSettings() {
|
||||||
settingsOpen = true
|
settingsOpen = true
|
||||||
@@ -74,10 +59,6 @@
|
|||||||
profileOpen = true
|
profileOpen = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function openAdmin() {
|
|
||||||
adminOpen = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeSettings() {
|
function closeSettings() {
|
||||||
settingsOpen = false
|
settingsOpen = false
|
||||||
if (page.url.pathname === '/settings') void goto(homePath)
|
if (page.url.pathname === '/settings') void goto(homePath)
|
||||||
@@ -153,27 +134,6 @@
|
|||||||
auth = { ...auth, user: data.user, error: null }
|
auth = { ...auth, user: data.user, error: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listUsers(): Promise<ManagedUser[]> {
|
|
||||||
return get<ManagedUser[]>('/api/auth/users')
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createUser(input: UserCreateInput): Promise<void | ManagedUser> {
|
|
||||||
return post<ManagedUser>('/api/auth/users', input)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateUser(id: UserId, input: UserUpdateInput): Promise<void | ManagedUser> {
|
|
||||||
return put<ManagedUser>(`/api/auth/users/${encodeURIComponent(String(id))}`, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteUser(id: UserId): Promise<void> {
|
|
||||||
await del<{ ok: boolean }>(`/api/auth/users/${encodeURIComponent(String(id))}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateLoginRequired(loginRequired: boolean) {
|
|
||||||
await put<{ loginRequired: boolean }>('/api/auth/access', { loginRequired })
|
|
||||||
auth = { ...auth, authRequired: loginRequired }
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
void loadAuth()
|
void loadAuth()
|
||||||
})
|
})
|
||||||
@@ -204,7 +164,6 @@
|
|||||||
faviconHref="/favicon.svg"
|
faviconHref="/favicon.svg"
|
||||||
{navItems}
|
{navItems}
|
||||||
onAbout={openAbout}
|
onAbout={openAbout}
|
||||||
onAdmin={isAdmin ? openAdmin : undefined}
|
|
||||||
onLogout={logout}
|
onLogout={logout}
|
||||||
onProfile={openProfile}
|
onProfile={openProfile}
|
||||||
onSettings={openSettings}
|
onSettings={openSettings}
|
||||||
@@ -223,17 +182,6 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<SettingsDialog bind:open={settingsOpen} onClose={closeSettings} />
|
<SettingsDialog bind:open={settingsOpen} onClose={closeSettings} />
|
||||||
<AdminDialog
|
|
||||||
bind:open={adminOpen}
|
|
||||||
{currentRole}
|
|
||||||
{currentUserId}
|
|
||||||
onListUsers={listUsers}
|
|
||||||
onCreateUser={createUser}
|
|
||||||
onUpdateUser={updateUser}
|
|
||||||
onDeleteUser={deleteUser}
|
|
||||||
loginRequired={auth.authRequired}
|
|
||||||
onLoginRequiredChange={updateLoginRequired}
|
|
||||||
/>
|
|
||||||
<AboutDialog bind:open={aboutOpen} brand={app.name} description={app.description} onClose={closeAbout}>
|
<AboutDialog bind:open={aboutOpen} brand={app.name} description={app.description} onClose={closeAbout}>
|
||||||
{#snippet icon()}
|
{#snippet icon()}
|
||||||
<ProjectIcon icon={app.icon} class="size-8 text-primary" />
|
<ProjectIcon icon={app.icon} class="size-8 text-primary" />
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type {
|
|
||||||
UserCreateRequest,
|
|
||||||
UserDeleteRequest,
|
|
||||||
UserId,
|
|
||||||
UserListRequest,
|
|
||||||
UserRole,
|
|
||||||
UserUpdateRequest
|
|
||||||
} from '../types';
|
|
||||||
import Dialog from './Dialog.svelte';
|
|
||||||
import UserManagement from './UserManagement.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
currentRole = 'user',
|
|
||||||
currentUserId,
|
|
||||||
description = 'Manage accounts and access for this application.',
|
|
||||||
loginRequired = true,
|
|
||||||
onCreateUser,
|
|
||||||
onDeleteUser,
|
|
||||||
onLoginRequiredChange,
|
|
||||||
onListUsers,
|
|
||||||
onUpdateUser,
|
|
||||||
open = $bindable(false),
|
|
||||||
title = 'Admin'
|
|
||||||
}: {
|
|
||||||
currentRole?: UserRole;
|
|
||||||
currentUserId?: UserId;
|
|
||||||
description?: string;
|
|
||||||
loginRequired?: boolean;
|
|
||||||
onCreateUser?: UserCreateRequest;
|
|
||||||
onDeleteUser?: UserDeleteRequest;
|
|
||||||
onLoginRequiredChange?: (required: boolean) => void | Promise<void>;
|
|
||||||
onListUsers?: UserListRequest;
|
|
||||||
onUpdateUser?: UserUpdateRequest;
|
|
||||||
open?: boolean;
|
|
||||||
title?: string;
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
let loginRequiredValue = $state<boolean>(true);
|
|
||||||
let loginSettingError = $state('');
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
loginRequiredValue = loginRequired;
|
|
||||||
});
|
|
||||||
|
|
||||||
async function updateLoginRequired(required: boolean) {
|
|
||||||
const previous = loginRequiredValue;
|
|
||||||
loginRequiredValue = required;
|
|
||||||
loginSettingError = '';
|
|
||||||
try {
|
|
||||||
await onLoginRequiredChange?.(required);
|
|
||||||
} catch (error) {
|
|
||||||
loginRequiredValue = previous;
|
|
||||||
loginSettingError = error instanceof Error ? error.message : 'The setting could not be saved.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<Dialog bind:open {description} {title}>
|
|
||||||
{#if onLoginRequiredChange}
|
|
||||||
<div class="sc-field">
|
|
||||||
<label class="flex items-center gap-3">
|
|
||||||
<input
|
|
||||||
class="size-4 accent-primary"
|
|
||||||
type="checkbox"
|
|
||||||
checked={loginRequiredValue}
|
|
||||||
onchange={(event) => updateLoginRequired((event.currentTarget as HTMLInputElement).checked)}
|
|
||||||
/>
|
|
||||||
<span>
|
|
||||||
<span class="block font-medium">Require login to access app</span>
|
|
||||||
<span class="sc-muted">Admins and superadmins can change this setting.</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
{#if loginSettingError}<p class="sc-error" role="alert">{loginSettingError}</p>{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<UserManagement
|
|
||||||
currentRole={currentRole}
|
|
||||||
currentUserId={currentUserId}
|
|
||||||
onCreate={onCreateUser}
|
|
||||||
onDelete={onDeleteUser}
|
|
||||||
onList={onListUsers}
|
|
||||||
onUpdate={onUpdateUser}
|
|
||||||
/>
|
|
||||||
</Dialog>
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
headerActions,
|
headerActions,
|
||||||
navItems = [],
|
navItems = [],
|
||||||
onAbout,
|
onAbout,
|
||||||
onAdmin,
|
|
||||||
onLogout,
|
onLogout,
|
||||||
onNavigate,
|
onNavigate,
|
||||||
onProfile,
|
onProfile,
|
||||||
@@ -37,7 +36,6 @@
|
|||||||
headerActions?: Snippet;
|
headerActions?: Snippet;
|
||||||
navItems?: NavItem[];
|
navItems?: NavItem[];
|
||||||
onAbout?: () => void | Promise<void>;
|
onAbout?: () => void | Promise<void>;
|
||||||
onAdmin?: () => void | Promise<void>;
|
|
||||||
onLogout?: () => void | Promise<void>;
|
onLogout?: () => void | Promise<void>;
|
||||||
onNavigate?: (item: NavItem) => void;
|
onNavigate?: (item: NavItem) => void;
|
||||||
onProfile?: () => void;
|
onProfile?: () => void;
|
||||||
@@ -68,7 +66,6 @@
|
|||||||
actions={headerActions}
|
actions={headerActions}
|
||||||
{navItems}
|
{navItems}
|
||||||
{onAbout}
|
{onAbout}
|
||||||
{onAdmin}
|
|
||||||
{onLogout}
|
{onLogout}
|
||||||
{onNavigate}
|
{onNavigate}
|
||||||
{onProfile}
|
{onProfile}
|
||||||
|
|||||||
@@ -100,7 +100,6 @@
|
|||||||
navItems = [],
|
navItems = [],
|
||||||
actions,
|
actions,
|
||||||
onAbout,
|
onAbout,
|
||||||
onAdmin,
|
|
||||||
onLogout,
|
onLogout,
|
||||||
onNavigate,
|
onNavigate,
|
||||||
onProfile,
|
onProfile,
|
||||||
@@ -116,7 +115,6 @@
|
|||||||
navItems?: NavItem[];
|
navItems?: NavItem[];
|
||||||
actions?: Snippet;
|
actions?: Snippet;
|
||||||
onAbout?: () => void | Promise<void>;
|
onAbout?: () => void | Promise<void>;
|
||||||
onAdmin?: () => void | Promise<void>;
|
|
||||||
onLogout?: () => void | Promise<void>;
|
onLogout?: () => void | Promise<void>;
|
||||||
onNavigate?: (item: NavItem) => void;
|
onNavigate?: (item: NavItem) => void;
|
||||||
onProfile?: () => void | Promise<void>;
|
onProfile?: () => void | Promise<void>;
|
||||||
@@ -128,12 +126,8 @@
|
|||||||
let navOpen = $state(false);
|
let navOpen = $state(false);
|
||||||
let profileOpen = $state(false);
|
let profileOpen = $state(false);
|
||||||
|
|
||||||
// onAdmin is only ever passed by the caller when the signed-in user's role qualifies, so its
|
|
||||||
// presence alone is enough to decide visibility here - same as onProfile/onLogout below.
|
|
||||||
const hasProfileMenu = $derived(
|
const hasProfileMenu = $derived(
|
||||||
Boolean(
|
Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)),
|
||||||
username && (onProfile || onAdmin || (showSettings && onSettings) || onAbout || aboutHref || onLogout),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
function closeMenus(): void {
|
function closeMenus(): void {
|
||||||
@@ -225,21 +219,6 @@
|
|||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if onAdmin}
|
|
||||||
<button
|
|
||||||
class="sc-profile-menu-item"
|
|
||||||
role="menuitem"
|
|
||||||
type="button"
|
|
||||||
onclick={() => {
|
|
||||||
profileOpen = false;
|
|
||||||
void onAdmin?.();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ShieldCheck aria-hidden="true" size={15} strokeWidth={2} />
|
|
||||||
Admin
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if showSettings && onSettings}
|
{#if showSettings && onSettings}
|
||||||
<button
|
<button
|
||||||
class="sc-profile-menu-item"
|
class="sc-profile-menu-item"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export { default as AboutDialog } from './components/AboutDialog.svelte';
|
export { default as AboutDialog } from './components/AboutDialog.svelte';
|
||||||
export { default as AdminDialog } from './components/AdminDialog.svelte';
|
|
||||||
export { default as AppShell } from './components/AppShell.svelte';
|
export { default as AppShell } from './components/AppShell.svelte';
|
||||||
export { default as AuthPage } from './components/AuthPage.svelte';
|
export { default as AuthPage } from './components/AuthPage.svelte';
|
||||||
export { default as Badge } from './components/Badge.svelte';
|
export { default as Badge } from './components/Badge.svelte';
|
||||||
|
|||||||
Reference in new issue
Block a user