Add per-user project-access restriction; generalize mediaauth into a unified auth proxy
shared/backend/auth: adds SchemaOptions.ProjectScoping and Store methods
(SetUserProjects/UserProjects/UserProjectsByUser/IsProjectAllowed,
SetKnownProjects/KnownProjects) backing AuthGuard's new per-user
project-access restriction.
shared/backend/authclient: Client can now identify its calling project to
AuthServer via WithProjectKey (sent as X-Project-Key on every request), so
AuthServer can enforce the restriction above per project.
shared/backend/mediaauth: generalized from a media-family-only package
into the one shared auth-proxy engine every AuthGuard-integrated project
should use. New accepts a projectKey; the login-required/setup-claim
storage it needs is now expressed as a small Store interface
(NewWithStore lets any project's own storage satisfy it, not just the
media family's shared `settings` table, which pgSettingsStore still backs
for existing callers). ManagedUpdateUser/ManagedDeleteUser now resolve
their {id} path param via chi.URLParam OR the stdlib 1.22+ ServeMux's
PathValue, so non-chi consumers work unchanged.
packages/web-ui: UserManagement gains an optional `projects` prop (a
per-account project-access picker), used only by AuthGuard's own admin UI.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6ac2fcefeb
commit
663d498a03
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