feat: store thumbnails in project mounts with legacy fallback
- Add thumbnail upload, lookup, deletion, and scratch-fetch helpers - Distinguish missing mounts from other listing failures
This commit is contained in:
1 parent
483a1a278b
commit
6aec03fb3d
16 files changed
+846
-126
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type {
|
||||
KnownProject,
|
||||
KnownRole,
|
||||
ManagedUser,
|
||||
UserCreateInput,
|
||||
UserCreateRequest,
|
||||
@@ -21,7 +21,7 @@
|
||||
onDelete,
|
||||
onList,
|
||||
onUpdate,
|
||||
projects
|
||||
roles
|
||||
}: {
|
||||
currentRole?: UserRole;
|
||||
currentUserId?: UserId;
|
||||
@@ -30,14 +30,13 @@
|
||||
onList?: UserListRequest;
|
||||
onUpdate?: UserUpdateRequest;
|
||||
/**
|
||||
* Every project an account can be restricted to logging into
|
||||
* (AuthGuard's project-scope feature). Only AuthGuard's own admin UI
|
||||
* passes this - every other project's UserManagement usage (proxying to
|
||||
* AuthGuard's admin/users endpoints without knowing about registered
|
||||
* projects) omits it, and the whole project-access section of this
|
||||
* The custom roles an account can be placed in (AuthGuard's role-based
|
||||
* project access: a role decides which projects its members may log into).
|
||||
* Only AuthGuard's own admin UI passes this - every other project's
|
||||
* UserManagement usage omits it, and the whole role section of this
|
||||
* component simply doesn't render.
|
||||
*/
|
||||
projects?: KnownProject[];
|
||||
roles?: KnownRole[];
|
||||
} = $props();
|
||||
|
||||
let users = $state<ManagedUser[]>([]);
|
||||
@@ -113,28 +112,26 @@
|
||||
function startEditing(user: ManagedUser): void {
|
||||
editingId = user.id;
|
||||
editUser = { username: user.username, email: user.email, role: roleForForm(user.role) };
|
||||
if (projects && projects.length > 0) editUser.projects = [...(user.projects ?? [])];
|
||||
if (roles && roles.length > 0) editUser.roleIds = [...(user.roleIds ?? [])];
|
||||
error = '';
|
||||
notice = '';
|
||||
}
|
||||
|
||||
function toggleEditProject(key: string, checked: boolean): void {
|
||||
const current = editUser.projects ?? [];
|
||||
editUser.projects = checked ? [...current, key] : current.filter((project) => project !== key);
|
||||
function toggleEditRole(id: number, checked: boolean): void {
|
||||
const current = editUser.roleIds ?? [];
|
||||
editUser.roleIds = checked ? [...current, id] : current.filter((roleId) => roleId !== id);
|
||||
}
|
||||
|
||||
function toggleNewProject(key: string, checked: boolean): void {
|
||||
const current = newUser.projects ?? [];
|
||||
newUser.projects = checked ? [...current, key] : current.filter((project) => project !== key);
|
||||
function toggleNewRole(id: number, checked: boolean): void {
|
||||
const current = newUser.roleIds ?? [];
|
||||
newUser.roleIds = checked ? [...current, id] : current.filter((roleId) => roleId !== id);
|
||||
}
|
||||
|
||||
function projectLabel(key: string): string {
|
||||
return projects?.find((project) => project.key === key)?.label ?? key;
|
||||
}
|
||||
|
||||
function projectSummary(user: ManagedUser): string {
|
||||
if (!user.projects || user.projects.length === 0) return 'All projects';
|
||||
return user.projects.map(projectLabel).join(', ');
|
||||
// Names the roles an account is in, in the order the roles are listed. An account in none of
|
||||
// them keeps every project.
|
||||
function roleSummary(user: ManagedUser): string {
|
||||
const names = (roles ?? []).filter((role) => (user.roleIds ?? []).includes(role.id)).map((role) => role.name);
|
||||
return names.length > 0 ? names.join(', ') : 'All projects';
|
||||
}
|
||||
|
||||
function stopEditing(): void {
|
||||
@@ -203,17 +200,17 @@
|
||||
{#if canAssignAdmin}<option value="admin">Admin</option>{/if}
|
||||
</select>
|
||||
</div>
|
||||
{#if projects && projects.length > 0}
|
||||
<fieldset class="sc-user-projects">
|
||||
<legend>Projects (none checked = all projects)</legend>
|
||||
{#each projects as project (project.key)}
|
||||
<label class="sc-user-project-option">
|
||||
{#if roles && roles.length > 0}
|
||||
<fieldset class="sc-user-roles">
|
||||
<legend>Roles (none checked = all projects)</legend>
|
||||
{#each roles as role (role.id)}
|
||||
<label class="sc-user-role-option">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={(newUser.projects ?? []).includes(project.key)}
|
||||
onchange={(event) => toggleNewProject(project.key, event.currentTarget.checked)}
|
||||
checked={(newUser.roleIds ?? []).includes(role.id)}
|
||||
onchange={(event) => toggleNewRole(role.id, event.currentTarget.checked)}
|
||||
/>
|
||||
{project.label}
|
||||
{role.name}
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
@@ -241,17 +238,17 @@
|
||||
{#if canAssignAdmin}<option value="admin">Admin</option>{/if}
|
||||
{#if user.role === 'superadmin'}<option value="superadmin">Superadmin</option>{/if}
|
||||
</select>
|
||||
{#if projects && projects.length > 0}
|
||||
<fieldset class="sc-user-projects">
|
||||
<legend>Projects (none checked = all projects)</legend>
|
||||
{#each projects as project (project.key)}
|
||||
<label class="sc-user-project-option">
|
||||
{#if roles && roles.length > 0}
|
||||
<fieldset class="sc-user-roles">
|
||||
<legend>Roles (none checked = all projects)</legend>
|
||||
{#each roles as role (role.id)}
|
||||
<label class="sc-user-role-option">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={(editUser.projects ?? []).includes(project.key)}
|
||||
onchange={(event) => toggleEditProject(project.key, event.currentTarget.checked)}
|
||||
checked={(editUser.roleIds ?? []).includes(role.id)}
|
||||
onchange={(event) => toggleEditRole(role.id, event.currentTarget.checked)}
|
||||
/>
|
||||
{project.label}
|
||||
{role.name}
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
@@ -263,8 +260,8 @@
|
||||
<div><strong>{user.username}</strong><span>{user.email}</span></div>
|
||||
<span class="sc-user-role">{user.role}</span>
|
||||
<span class="sc-muted sc-user-last-login" title="Last login">{formatLastLogin(user.lastLoginAt)}</span>
|
||||
{#if projects && projects.length > 0}
|
||||
<span class="sc-muted sc-user-projects-summary" title="Project access">{projectSummary(user)}</span>
|
||||
{#if roles && roles.length > 0}
|
||||
<span class="sc-muted sc-user-roles-summary" title="Roles">{roleSummary(user)}</span>
|
||||
{/if}
|
||||
<div class="sc-user-actions">
|
||||
<Button disabled={saving} size="sm" type="button" variant="secondary" onclick={() => startEditing(user)}>Edit</Button>
|
||||
|
||||
@@ -41,6 +41,7 @@ export type {
|
||||
AuthSetupInput,
|
||||
ContentSnippet,
|
||||
KnownProject,
|
||||
KnownRole,
|
||||
NavItem,
|
||||
ProfileUpdateInput,
|
||||
ManagedUser,
|
||||
|
||||
@@ -703,6 +703,27 @@ html[data-wide-layout='true'] .sc-header {
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--sc-ring) 22%, transparent);
|
||||
}
|
||||
|
||||
/* Checkboxes and radios share one look across apps. The box takes each app's primary color,
|
||||
so it follows that app's light and dark theme. Sizes match the legacy shared sheet. The rule
|
||||
sits in the base layer so Tailwind utilities (size-*, accent-*) still override it per element. */
|
||||
@layer base {
|
||||
input[type='checkbox'],
|
||||
input[type='radio'] {
|
||||
accent-color: var(--sc-primary);
|
||||
width: 1.05rem;
|
||||
height: 1.05rem;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
input[type='checkbox'] {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
input[type='radio'] {
|
||||
border-radius: 9999px;
|
||||
}
|
||||
}
|
||||
|
||||
.sc-form-actions,
|
||||
.sc-dialog-footer {
|
||||
display: flex;
|
||||
@@ -809,7 +830,7 @@ html[data-wide-layout='true'] .sc-header {
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.sc-user-projects-summary {
|
||||
.sc-user-roles-summary {
|
||||
max-width: 12rem;
|
||||
overflow: hidden;
|
||||
font-size: 0.8rem;
|
||||
@@ -817,7 +838,7 @@ html[data-wide-layout='true'] .sc-header {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sc-user-projects {
|
||||
.sc-user-roles {
|
||||
display: flex;
|
||||
flex: 1 1 100%;
|
||||
flex-wrap: wrap;
|
||||
@@ -828,14 +849,14 @@ html[data-wide-layout='true'] .sc-header {
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.sc-user-projects legend {
|
||||
.sc-user-roles legend {
|
||||
flex-basis: 100%;
|
||||
margin-bottom: 0.3rem;
|
||||
color: var(--sc-muted-fg);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.sc-user-project-option {
|
||||
.sc-user-role-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
@@ -1037,9 +1058,11 @@ html[data-wide-layout='true'] .sc-header {
|
||||
}
|
||||
|
||||
.sc-notification {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.625rem;
|
||||
min-width: 0;
|
||||
padding: 0.875rem 1rem;
|
||||
color: var(--sc-fg);
|
||||
background: var(--sc-surface-raised);
|
||||
@@ -1047,8 +1070,6 @@ html[data-wide-layout='true'] .sc-header {
|
||||
border-radius: var(--sc-radius-md);
|
||||
box-shadow: var(--sc-shadow-lg);
|
||||
pointer-events: auto;
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.sc-notification + .sc-notification {
|
||||
@@ -1060,7 +1081,6 @@ html[data-wide-layout='true'] .sc-header {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
|
||||
.sc-notification-icon {
|
||||
flex: 0 0 auto;
|
||||
margin-top: 0.125rem;
|
||||
@@ -1085,10 +1105,10 @@ html[data-wide-layout='true'] .sc-header {
|
||||
|
||||
.sc-notification-message {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.45;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,20 +59,26 @@ export interface ManagedUser {
|
||||
/** Null/undefined means the account has never completed a login. */
|
||||
lastLoginAt?: string | null;
|
||||
/**
|
||||
* Project keys this account is restricted to logging into (AuthGuard's
|
||||
* project-scope feature); an empty array (never undefined, when the
|
||||
* backend supports this feature at all) means unrestricted. Undefined on
|
||||
* a backend that doesn't report it at all.
|
||||
* Ids of the custom roles this account belongs to. Those roles decide which
|
||||
* projects the account may log into (AuthGuard's role-based project access);
|
||||
* an empty array means no custom role, which keeps every project open.
|
||||
* Undefined on a backend that doesn't report roles at all.
|
||||
*/
|
||||
projects?: string[];
|
||||
roleIds?: number[];
|
||||
}
|
||||
|
||||
/** One project an administrator may restrict a user's login access to - see UserManagement's `projects` prop. */
|
||||
/** One registered project an administrator can pick from. */
|
||||
export interface KnownProject {
|
||||
key: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/** One custom role an administrator may assign to a user - see UserManagement's `roles` prop. */
|
||||
export interface KnownRole {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* username/email are plain (never undefined) so <input> bindings stay simple
|
||||
* -- an empty string, not an absent key, is how this form represents "not
|
||||
@@ -86,11 +92,11 @@ export interface UserCreateInput {
|
||||
password: string;
|
||||
role?: UserRole;
|
||||
/**
|
||||
* Project keys this new account is restricted to. An empty array means
|
||||
* unrestricted; omitted when the host application does not expose project
|
||||
* scoping.
|
||||
* Ids of the custom roles this new account belongs to. An empty array means
|
||||
* no custom role (every project); omitted when the host application does not
|
||||
* expose roles.
|
||||
*/
|
||||
projects?: string[];
|
||||
roleIds?: number[];
|
||||
}
|
||||
|
||||
export interface UserUpdateInput {
|
||||
@@ -99,11 +105,11 @@ export interface UserUpdateInput {
|
||||
password?: string;
|
||||
role?: UserRole;
|
||||
/**
|
||||
* Replaces the account's full project-access list when present (an empty
|
||||
* array clears any restriction); omitted (undefined) leaves it untouched.
|
||||
* Only ever set when UserManagement was given a `projects` prop.
|
||||
* Replaces the account's full set of custom roles when present (an empty
|
||||
* array removes it from every role); omitted (undefined) leaves them
|
||||
* untouched. Only ever set when UserManagement was given a `roles` prop.
|
||||
*/
|
||||
projects?: string[];
|
||||
roleIds?: number[];
|
||||
}
|
||||
|
||||
export type UserListRequest = () => ManagedUser[] | Promise<ManagedUser[]>;
|
||||
|
||||
Reference in new issue
Block a user