Admin role, root/home URL split, activity permalinks
Three related changes.
1. **Admin role.** New `is_admin INTEGER NOT NULL DEFAULT 0` column on
users; added to MeResponse. Admin strictly implies moderator —
shared/roles.ts has a single isModerator()/isAdmin() pair so the
implication can't drift between callers. The duplicated isModerator()
helpers in server/activities.ts and server/feedback.ts now import
from there.
/api/admin endpoints (admin-only):
GET /admin/users — list users with their roles
PATCH /admin/users/:id/role — set is_moderator and/or is_admin
Last-admin guard: the role-update endpoint refuses to demote the only
remaining admin (409 cannot_demote_last_admin). Bootstrap is via
`sqlite3 ... UPDATE users SET is_admin=1` — documented in README.
Frontend Admin.svelte: table of users with toggles for moderator and
admin. Visible from the nav only when the current user is admin.
Toggling our own role refreshes session.user so the nav adapts
immediately.
2. **Root/home split.** The URL `/` always shows the public landing
(public + semi activities), even when the user is logged in. `/home`
is the authenticated dashboard. After login or signup the SPA pushes
`/home`; after logout it pushes `/`. popstate is wired so the
back/forward buttons work. Unknown paths fall through to the public
landing, not a 404.
3. **Activity permalinks at /a/:id.** New SPA route renders a single
activity via the existing GET /api/activities/:id endpoint (private
rows still require the owner's session to decrypt). A "Del" button
on each ActivityRow copies the absolute permalink to the clipboard.
Clipboard API has a prompt() fallback for environments where it's
blocked.
Server changes minimal: server/admin.ts is the new file; server/roles.ts
is the lifted helper; server/index.ts wires the admin routes; server/db.ts
gets one more ensureColumn() line.
26 tests still pass; typecheck clean; Vite build succeeds. Bundle grew
from 28.6 KB gzipped to 30.2 KB reflecting the Admin + permalink views.
This commit is contained in:
parent
f0b4d735b5
commit
bd82f71a01
16 changed files with 573 additions and 80 deletions
|
|
@ -72,10 +72,30 @@ export interface MeResponse {
|
|||
email: string;
|
||||
display_name: string | null;
|
||||
is_moderator: boolean;
|
||||
is_admin: boolean;
|
||||
username: string | null;
|
||||
public_list_enabled: boolean;
|
||||
}
|
||||
|
||||
// --- Admin -----------------------------------------------------------------
|
||||
/** A single row in the admin user list. Admin-only. */
|
||||
export interface AdminUser {
|
||||
id: string;
|
||||
email: string;
|
||||
display_name: string | null;
|
||||
username: string | null;
|
||||
public_list_enabled: boolean;
|
||||
is_moderator: boolean;
|
||||
is_admin: boolean;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
/** PATCH /api/admin/users/:id/role payload. Both fields optional. */
|
||||
export interface AdminRoleUpdate {
|
||||
is_moderator?: boolean;
|
||||
is_admin?: boolean;
|
||||
}
|
||||
|
||||
export interface ProfileUpdateRequest {
|
||||
// All optional — omit a field to leave it alone. Pass `null` to clear.
|
||||
display_name?: string | null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue