Sync shared snapshot from 07cf330
This commit is contained in:
1 parent
cd0db77208
commit
557a61b4ee
5 files changed
+4
-167
No files matched your search
@@ -5,21 +5,12 @@
|
||||
import AuthPage from '$lib/components/AuthPage.svelte'
|
||||
import ProjectIcon from '$lib/components/ProjectIcon.svelte'
|
||||
import AboutWorkspace from '$lib/features/AboutWorkspace.svelte'
|
||||
import { AboutDialog, AdminDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
||||
import type {
|
||||
AuthLoginInput,
|
||||
AuthSetupInput,
|
||||
ManagedUser,
|
||||
ProfileUpdateInput,
|
||||
UserCreateInput,
|
||||
UserId,
|
||||
UserRole,
|
||||
UserUpdateInput,
|
||||
} from '@gabriel20xx/web-ui'
|
||||
import { AboutDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
||||
import type { AuthLoginInput, AuthSetupInput, ProfileUpdateInput } from '@gabriel20xx/web-ui'
|
||||
import SettingsDialog from '$lib/components/SettingsDialog.svelte'
|
||||
import { getPanelForPath } from '$lib/app-config'
|
||||
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 type { AppConfig, AuthState, AuthUser } from '$lib/types'
|
||||
import type { Snippet } from 'svelte'
|
||||
@@ -36,7 +27,6 @@
|
||||
let settingsOpen = $state(false)
|
||||
let aboutOpen = $state(false)
|
||||
let profileOpen = $state(false)
|
||||
let adminOpen = $state(false)
|
||||
|
||||
// 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
|
||||
@@ -56,11 +46,6 @@
|
||||
const activeNavItem = $derived(
|
||||
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() {
|
||||
settingsOpen = true
|
||||
@@ -74,10 +59,6 @@
|
||||
profileOpen = true
|
||||
}
|
||||
|
||||
function openAdmin() {
|
||||
adminOpen = true
|
||||
}
|
||||
|
||||
function closeSettings() {
|
||||
settingsOpen = false
|
||||
if (page.url.pathname === '/settings') void goto(homePath)
|
||||
@@ -153,27 +134,6 @@
|
||||
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(() => {
|
||||
void loadAuth()
|
||||
})
|
||||
@@ -204,7 +164,6 @@
|
||||
faviconHref="/favicon.svg"
|
||||
{navItems}
|
||||
onAbout={openAbout}
|
||||
onAdmin={isAdmin ? openAdmin : undefined}
|
||||
onLogout={logout}
|
||||
onProfile={openProfile}
|
||||
onSettings={openSettings}
|
||||
@@ -223,17 +182,6 @@
|
||||
{/if}
|
||||
|
||||
<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}>
|
||||
{#snippet icon()}
|
||||
<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,
|
||||
navItems = [],
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -37,7 +36,6 @@
|
||||
headerActions?: Snippet;
|
||||
navItems?: NavItem[];
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void;
|
||||
@@ -68,7 +66,6 @@
|
||||
actions={headerActions}
|
||||
{navItems}
|
||||
{onAbout}
|
||||
{onAdmin}
|
||||
{onLogout}
|
||||
{onNavigate}
|
||||
{onProfile}
|
||||
|
||||
@@ -100,7 +100,6 @@
|
||||
navItems = [],
|
||||
actions,
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -116,7 +115,6 @@
|
||||
navItems?: NavItem[];
|
||||
actions?: Snippet;
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void | Promise<void>;
|
||||
@@ -128,12 +126,8 @@
|
||||
let navOpen = $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(
|
||||
Boolean(
|
||||
username && (onProfile || onAdmin || (showSettings && onSettings) || onAbout || aboutHref || onLogout),
|
||||
),
|
||||
Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)),
|
||||
);
|
||||
|
||||
function closeMenus(): void {
|
||||
@@ -225,21 +219,6 @@
|
||||
</button>
|
||||
{/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}
|
||||
<button
|
||||
class="sc-profile-menu-item"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
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 AuthPage } from './components/AuthPage.svelte';
|
||||
export { default as Badge } from './components/Badge.svelte';
|
||||
|
||||
Reference in new issue
Block a user