This commit is contained in:
1 parent
1d99f0272d
commit
b1412a9016
7 files changed
+476
-51
No files matched your search
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type {
|
||||
KnownProject,
|
||||
ManagedUser,
|
||||
UserCreateInput,
|
||||
UserCreateRequest,
|
||||
@@ -19,7 +20,8 @@
|
||||
onCreate,
|
||||
onDelete,
|
||||
onList,
|
||||
onUpdate
|
||||
onUpdate,
|
||||
projects
|
||||
}: {
|
||||
currentRole?: UserRole;
|
||||
currentUserId?: UserId;
|
||||
@@ -27,6 +29,15 @@
|
||||
onDelete?: UserDeleteRequest;
|
||||
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
|
||||
* component simply doesn't render.
|
||||
*/
|
||||
projects?: KnownProject[];
|
||||
} = $props();
|
||||
|
||||
let users = $state<ManagedUser[]>([]);
|
||||
@@ -102,10 +113,25 @@
|
||||
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 ?? [])];
|
||||
error = '';
|
||||
notice = '';
|
||||
}
|
||||
|
||||
function toggleEditProject(key: string, checked: boolean): void {
|
||||
const current = editUser.projects ?? [];
|
||||
editUser.projects = checked ? [...current, key] : current.filter((project) => project !== key);
|
||||
}
|
||||
|
||||
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(', ');
|
||||
}
|
||||
|
||||
function stopEditing(): void {
|
||||
editingId = null;
|
||||
editUser = {};
|
||||
@@ -195,6 +221,21 @@
|
||||
{#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">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={(editUser.projects ?? []).includes(project.key)}
|
||||
onchange={(event) => toggleEditProject(project.key, event.currentTarget.checked)}
|
||||
/>
|
||||
{project.label}
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
{/if}
|
||||
<div class="sc-user-actions"><Button disabled={saving} size="sm" type="submit">Save</Button><Button disabled={saving} size="sm" type="button" variant="secondary" onclick={stopEditing}>Cancel</Button></div>
|
||||
</form>
|
||||
{:else}
|
||||
@@ -202,6 +243,9 @@
|
||||
<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}
|
||||
<div class="sc-user-actions">
|
||||
<Button disabled={saving} size="sm" type="button" variant="secondary" onclick={() => startEditing(user)}>Edit</Button>
|
||||
<Button disabled={saving || String(user.id) === String(currentUserId) || user.role === 'superadmin'} size="sm" type="button" variant="danger" onclick={() => void deleteUser(user)}>Remove</Button>
|
||||
|
||||
Reference in new issue
Block a user