AI Implementation feature(882): Admin Area General Settings and Categories 1.00 (#22)
This commit was merged in pull request #22.
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
---
|
||||
type: guide
|
||||
title: Admin — Categories
|
||||
description: How an admin lists, creates, edits, and deletes challenge categories from the /admin/categories page, including system-row protection and challenge-attached protection.
|
||||
tags: [guide, admin, categories, tester]
|
||||
timestamp: 2026-07-22T12:00:00Z
|
||||
---
|
||||
|
||||
# When this view is available
|
||||
|
||||
The Categories admin page renders at `/admin/categories` for users with
|
||||
`role === 'admin'`. It is reached from the [Admin Shell](/guides/admin-shell.md)
|
||||
side-nav (categories are also embedded inside the General settings page).
|
||||
|
||||
| Layer | File | Check |
|
||||
|------------------|----------------------------------------------------------------------------|------------------------------------------------------|
|
||||
| Client route | `frontend/src/app/app.routes.ts` | `/admin/categories` child of `adminGuard`. |
|
||||
| Client component | `frontend/src/app/features/admin/categories/categories.component.ts` | `AdminCategoriesComponent.ngOnInit` fetches the list. |
|
||||
| Client modals | `frontend/src/app/features/admin/categories/category-form-modal.component.ts` | Create / edit modal. |
|
||||
| | `frontend/src/app/features/admin/categories/category-delete-modal.component.ts` | Delete confirmation modal. |
|
||||
| Server route | `backend/src/modules/admin/admin-categories.controller.ts` | `GET/POST /api/v1/admin/categories`, `PUT/DELETE /:id`. |
|
||||
|
||||
# How to access (tester steps)
|
||||
|
||||
1. Sign in as an admin user.
|
||||
2. Open **Admin area** → **Categories** in the side-nav, or visit
|
||||
`/admin/categories` directly. (The page also renders below the
|
||||
General settings form at `/admin/general`.)
|
||||
3. The page shows `Loading categories...` (`data-testid="cat-loading"`)
|
||||
while the list request is in flight, then renders one row per
|
||||
category sorted alphabetically by (lowercased) abbreviation.
|
||||
|
||||
# Visual elements
|
||||
|
||||
| Element | Selector | Purpose |
|
||||
|------------------------|--------------------------------------------|---------|
|
||||
| Page section | `[data-testid="admin-categories"]` | Root container. |
|
||||
| Add button (`+`) | `[data-testid="cat-add"]` | Opens the create modal. |
|
||||
| Loading | `[data-testid="cat-loading"]` | "Loading categories..." placeholder. |
|
||||
| Load error | `[data-testid="cat-error"]` | Red error text. |
|
||||
| List | `[data-testid="cat-list"]` | `<ul>` of category rows. |
|
||||
| Row | `[data-testid="cat-row-{ABBR}"]` | One `<li>` per category. |
|
||||
| Edit button | `[data-testid="cat-edit-{ABBR}"]` | Opens the edit modal. Disabled for system rows (the abbreviation input becomes `readonly`). |
|
||||
| Delete button | `[data-testid="cat-delete-{ABBR}"]` | Opens the delete confirmation modal. |
|
||||
| Form modal | `[data-testid="cat-form-modal"]` | Create/edit dialog (`cat-form-backdrop` is the click-outside dismiss layer). |
|
||||
| Delete modal | `[data-testid="cat-delete-modal"]` | Confirmation dialog (`cat-delete-backdrop` is the dismiss layer). |
|
||||
| Delete error | `[data-testid="cat-delete-error"]` | Inline error message after a failed delete. |
|
||||
|
||||
# Form modal fields
|
||||
|
||||
| Label | `data-testid` | Notes |
|
||||
|-------------------------------|----------------|-------|
|
||||
| Name | `cf-name` | Required, max 120 chars. |
|
||||
| Abbreviation (uppercase) | `cf-abbr` | Required, 2–6 chars; server upper-cases on save. `readonly` when editing a system row. |
|
||||
| Description | `cf-desc` | Optional, max 2000 chars. |
|
||||
| Icon (file picker) | `cf-icon` | Optional image; uploaded to `POST /api/v1/uploads/category-icon` and resized/normalized server-side. |
|
||||
| Cancel / OK | `cf-cancel`, `cf-ok` | OK disabled while form invalid or already submitting. |
|
||||
|
||||
# Expected behavior
|
||||
|
||||
## List
|
||||
|
||||
* The list is sorted by `LOWER(abbreviation)` ascending. Server returns
|
||||
rows already sorted; the client re-sorts defensively in
|
||||
`AdminCategoriesComponent.load()`.
|
||||
* System rows (`isSystem === true`) render with the edit/delete actions
|
||||
still visible, but the abbreviation field is locked when editing, and
|
||||
the delete confirmation modal hides the "OK" button (see "Delete
|
||||
behavior" below).
|
||||
|
||||
## Create
|
||||
|
||||
1. Click `cat-add` → `cat-form-modal` opens in create mode.
|
||||
2. Fill name, abbreviation, description. Optionally pick an icon file
|
||||
(preview appears immediately).
|
||||
3. Click `cf-ok`. The component calls
|
||||
`AdminService.createCategory({...})`, then — if an icon file was
|
||||
selected — `uploadCategoryIcon(id, file)` and finally
|
||||
`updateCategory(id, { iconPath: publicUrl })` to persist the icon
|
||||
URL.
|
||||
4. On success the modal closes and the list refreshes.
|
||||
|
||||
## Edit
|
||||
|
||||
1. Click `cat-edit-{ABBR}` → modal opens in edit mode, pre-filled with
|
||||
the row's values.
|
||||
2. For system rows, the abbreviation field is `readonly`.
|
||||
3. On save the component issues `updateCategory(id, {...})`. If an icon
|
||||
file is selected, the new icon is uploaded first and the returned
|
||||
`publicUrl` replaces `iconPath` in the same update.
|
||||
|
||||
## Delete behavior
|
||||
|
||||
* **System rows:** the delete modal renders
|
||||
*"This is a system category and cannot be deleted."* and the OK
|
||||
button is hidden. `canConfirm()` returns `false`. If somehow the
|
||||
request is dispatched, the backend returns `403 SYSTEM_PROTECTED`
|
||||
and the UI shows `System categories cannot be deleted.`.
|
||||
* **Rows with attached challenges:** the backend returns
|
||||
`409 CATEGORY_HAS_CHALLENGES` with `{ count }` in `details`. The UI
|
||||
maps this to `Cannot delete: category has N challenge(s) attached.`
|
||||
and renders it in `cat-delete-error`.
|
||||
* **Normal row:** the modal confirms the name + abbreviation, OK
|
||||
dispatches `DELETE /api/v1/admin/categories/:id`, and the list
|
||||
refreshes.
|
||||
|
||||
## Validation and error codes (server)
|
||||
|
||||
| Code | HTTP | Triggered by |
|
||||
|----------------------------|------|---------------------------------------------------------------|
|
||||
| `VALIDATION_FAILED` | 400 | `CreateCategorySchema` / `UpdateCategorySchema` fails (length, required). |
|
||||
| `NOT_FOUND` | 404 | `PUT`/`DELETE` on a non-existent id. |
|
||||
| `CONFLICT` | 409 | Duplicate abbreviation on create or on update (user row). |
|
||||
| `SYSTEM_PROTECTED` | 409 | Update attempts to change a system row's abbreviation. |
|
||||
| `SYSTEM_PROTECTED` | 403 | Delete on a system row. |
|
||||
| `CATEGORY_HAS_CHALLENGES` | 409 | Delete on a category with at least one attached challenge (carries `{ count }` in `details`). |
|
||||
|
||||
# Architecture map
|
||||
|
||||
| Step | Where | What happens |
|
||||
|------|-------------------------------------------------------------|-----------------------------------------------------------------------------|
|
||||
| 1 | `frontend/src/app/app.routes.ts` | `/admin/categories` lazy-loads `AdminCategoriesComponent`. |
|
||||
| 2 | `frontend/src/app/features/admin/categories/categories.component.ts` | `ngOnInit` calls `AdminService.listCategories()`. |
|
||||
| 3 | `frontend/src/app/core/services/admin.service.ts` | `listCategories`, `createCategory`, `updateCategory`, `deleteCategory`, `uploadCategoryIcon`. |
|
||||
| 4 | `frontend/src/app/features/admin/categories/category-form-modal.component.ts` | Holds the form state, emits `CategoryFormSubmit`. |
|
||||
| 5 | `frontend/src/app/features/admin/categories/category-delete-modal.component.ts` | Maps error codes to user-friendly messages. |
|
||||
| 6 | `backend/src/modules/admin/admin-categories.controller.ts` | `AdminGuard` + `@Roles('admin')` on every handler. |
|
||||
| 7 | `backend/src/modules/admin/categories.service.ts` | `list` (sorted by `LOWER(abbreviation)`), `create` (uppercase + dup-check), `update` (system-abbr-immutable), `remove` (system-protected, challenge-count check). |
|
||||
| 8 | `backend/src/modules/admin/dto/categories.dto.ts` | zod schemas with length constraints; param validator for `:id`. |
|
||||
| 9 | `backend/src/modules/uploads/uploads.controller.ts` | `POST /api/v1/uploads/category-icon` (multipart) — also admin-only. |
|
||||
|
||||
# Notes
|
||||
|
||||
* Abbreviations are uppercased server-side before persistence and
|
||||
uniqueness check (DB enforces uniqueness via the
|
||||
`uq_category_abbreviation` index — see
|
||||
[Challenge Tables](/database/challenges.md)).
|
||||
* System rows are seeded by the
|
||||
`UpdateSystemCategoryKeys1700000000300` migration and identified by
|
||||
a non-null `system_key` column.
|
||||
* The icon upload pipeline normalizes the image to a fixed size; the
|
||||
returned `publicUrl` is stored in `category.icon_path`.
|
||||
* The Categories component is embedded inside the General settings
|
||||
page, so changes to a category are visible on either route without
|
||||
an extra refresh.
|
||||
|
||||
# See also
|
||||
|
||||
- [Admin Shell](/guides/admin-shell.md) — side-nav layout and the General settings page that embeds categories.
|
||||
- [Admin — General Settings](/guides/admin-general-settings.md)
|
||||
- [Admin Endpoints](/api/admin.md) — `GET/POST/PUT/DELETE /api/v1/admin/categories`.
|
||||
- [Challenge Tables](/database/challenges.md) — `category` schema and migrations.
|
||||
- [Uploads Endpoints](/api/uploads.md) — `POST /api/v1/uploads/category-icon`.
|
||||
@@ -0,0 +1,126 @@
|
||||
---
|
||||
type: guide
|
||||
title: Admin — General Settings
|
||||
description: How an admin edits global platform settings (page title, logo, theme, event window, default challenge IP, registrations, welcome Markdown) from the /admin/general page.
|
||||
tags: [guide, admin, settings, general, tester]
|
||||
timestamp: 2026-07-22T12:00:00Z
|
||||
---
|
||||
|
||||
# When this view is available
|
||||
|
||||
The General Settings page is rendered at `/admin/general` for users with
|
||||
`role === 'admin'` once the instance is initialized. It is reached from
|
||||
the [Admin Shell](/guides/admin-shell.md) side-nav (`General` entry) or
|
||||
by navigating directly to the URL.
|
||||
|
||||
| Layer | File | Check |
|
||||
|------------------|----------------------------------------------------------------------------|------------------------------------------------|
|
||||
| Client route | `frontend/src/app/app.routes.ts` | `/admin/general` child of `adminGuard`. |
|
||||
| Client component | `frontend/src/app/features/admin/general.component.ts` | `AdminGeneralComponent.ngOnInit` fetches settings + themes. |
|
||||
| Client predicate | `frontend/src/app/features/admin/general.pure.ts` (`deriveEventState`) | Computes the read-only event-state label. |
|
||||
| Server route | `backend/src/modules/admin/admin-general.controller.ts` | `GET/PUT /api/v1/admin/general/settings` + `GET /api/v1/admin/general/themes`. |
|
||||
|
||||
# How to access (tester steps)
|
||||
|
||||
1. Sign in as an admin user (see [First-Run Bootstrap](/guides/bootstrap.md)
|
||||
if no admin exists).
|
||||
2. Open the username menu in the shell header and click **Admin area**,
|
||||
or use the side-nav's **General** entry, or visit `/admin/general`
|
||||
directly.
|
||||
3. The page renders a `Loading settings...` placeholder while the
|
||||
initial `GET /api/v1/admin/general/settings` + `GET .../themes`
|
||||
requests are in flight.
|
||||
|
||||
# Fields
|
||||
|
||||
The page is a single reactive form with these controls (every
|
||||
`data-testid` listed is asserted in the existing test suite):
|
||||
|
||||
| Label | `data-testid` | Backend field | Notes |
|
||||
|------------------------|---------------------------|-------------------------|-------|
|
||||
| Page title | `general-pageTitle` | `pageTitle` | Required, max 120 chars. |
|
||||
| Logo (file picker) | `general-logo-file` | `logo` (public URL) | Uploads via `POST /api/v1/uploads/logo`; the returned `publicUrl` is bound to a hidden input `general-logo`. |
|
||||
| Logo upload status | `general-logo-uploading` / `general-logo-error` / `general-logo-current` | — | Inline status text under the file picker. |
|
||||
| Global theme | `general-themeKey` | `themeKey` | `<select>` populated from `/themes`. Value is one of `THEME_IDS`. |
|
||||
| Event start (UTC) | `general-eventStart` | `eventStartUtc` | `datetime-local` input converted to ISO UTC on save. |
|
||||
| Event end (UTC) | `general-eventEnd` | `eventEndUtc` | Must be strictly after Event start. Invalid pair renders `general-endBeforeStart`. |
|
||||
| Default challenge IP | `general-defaultIp` | `defaultChallengeIp` | Required, max 255 chars. |
|
||||
| Enable registrations | `general-registrations` | `registrationsEnabled` | Boolean checkbox. When `false`, the public register endpoint returns `REGISTRATIONS_DISABLED`. |
|
||||
| Welcome description | `general-welcome` | `welcomeMarkdown` | Multi-line textarea; a live preview is rendered into `general-welcome-preview`. |
|
||||
| Event controls | `general-event-toggle` | (derived) | Disabled button whose text is the derived event state (`UNCONFIGURED` / `COUNTDOWN` / `RUNNING` / `STOPPED`). |
|
||||
| Save button | `general-save` | — | Disabled while `submitting()` or `form.invalid`. |
|
||||
| Save error / success | `general-save-error` / `general-save-ok` | — | Inline status. |
|
||||
|
||||
# Expected behavior
|
||||
|
||||
* **Initial load:** `loading() === true` renders `general-loading`. After
|
||||
both requests resolve, the form is patched with the values from the
|
||||
backend (UTC timestamps are converted to `datetime-local` strings via
|
||||
`toDatetimeLocal` so the native picker shows them).
|
||||
* **Logo upload:** selecting a file fires `POST /api/v1/uploads/logo`,
|
||||
then writes the returned `publicUrl` into the hidden `logo` control.
|
||||
If the upload fails, `general-logo-error` shows the message; the
|
||||
previous logo is preserved.
|
||||
* **Welcome Markdown preview:** every keystroke in `general-welcome`
|
||||
triggers `MarkdownService.render` and updates `general-welcome-preview`
|
||||
synchronously.
|
||||
* **Event-state derivation:** the disabled `general-event-toggle` label
|
||||
is computed from `deriveEventState(start, end)`:
|
||||
* both empty → `UNCONFIGURED`
|
||||
* `now < start` → `COUNTDOWN`
|
||||
* `start <= now < end` → `RUNNING`
|
||||
* `now >= end` → `STOPPED`
|
||||
* **End-before-start validation:** if the user picks an end that is not
|
||||
strictly after the start, the form becomes invalid and
|
||||
`general-endBeforeStart` appears under the end input. Save remains
|
||||
disabled.
|
||||
* **Save:** clicking Save sends `PUT /api/v1/admin/general/settings`
|
||||
with all fields. On success the form is patched with the response,
|
||||
`general-save-ok` renders briefly, and the backend emits an SSE
|
||||
`general` event via `SseHubService` so other tabs refresh their theme.
|
||||
* **Error states:** load failures render `general-error`; save failures
|
||||
render `general-save-error` with the `error.message` (or
|
||||
`error.error.message`) from the standard envelope.
|
||||
|
||||
# Visual elements
|
||||
|
||||
| Element | Selector |
|
||||
|-------------------------------|-----------------------------------------------------|
|
||||
| Page section | `[data-testid="admin-general"]` |
|
||||
| Loading placeholder | `[data-testid="general-loading"]` |
|
||||
| Load error | `[data-testid="general-error"]` |
|
||||
| Form | `[data-testid="general-form"]` |
|
||||
| Welcome preview | `[data-testid="general-welcome-preview"]` |
|
||||
| End-before-start message | `[data-testid="general-endBeforeStart"]` |
|
||||
|
||||
# Architecture map
|
||||
|
||||
| Step | Where | What happens |
|
||||
|------|------------------------------------------------------|---------------------------------------------------------------------------|
|
||||
| 1 | `frontend/src/app/app.routes.ts` | `/admin/general` lazy-loads `AdminGeneralComponent`. |
|
||||
| 2 | `frontend/src/app/features/admin/general.component.ts` | `ngOnInit` calls `AdminService.getGeneralSettings()` + `listAdminThemes()` in parallel. |
|
||||
| 3 | `frontend/src/app/core/services/admin.service.ts` | `getGeneralSettings()` → `GET /api/v1/admin/general/settings`; `listAdminThemes()` → `GET /api/v1/admin/general/themes`; `updateGeneralSettings()` → `PUT .../settings`; `uploadLogo()` → `POST /api/v1/uploads/logo`. |
|
||||
| 4 | `backend/src/modules/admin/admin-general.controller.ts` | `AdminGuard` + `@Roles('admin')` on every handler. |
|
||||
| 5 | `backend/src/modules/admin/general.service.ts` | `getSettings` reads 8 keys via `SettingsService`; `updateSettings` writes all 8, emits `{ topic: 'general', themeKey }` via `SseHubService`. |
|
||||
| 6 | `backend/src/modules/admin/dto/general.dto.ts` | `GeneralSettingsSchema` enforces string lengths, `themeKey` enum, and `eventEndUtc > eventStartUtc` via `superRefine`. |
|
||||
|
||||
# Notes
|
||||
|
||||
* The `general` SSE event (`{ topic: 'general', themeKey }`) is a
|
||||
lightweight signal so authenticated tabs can pick up the new theme
|
||||
without polling. Other tabs do not auto-refresh settings values.
|
||||
* The "Event controls" toggle is intentionally a derived display, not
|
||||
an editable control — adjust the UTC timestamps to change state.
|
||||
* All timestamps are stored as ISO-8601 UTC strings in the `setting`
|
||||
table; the UI converts to/from `datetime-local` for display.
|
||||
* Saving the form requires the page title and default challenge IP to
|
||||
be non-empty; the form is `invalid` and Save stays disabled until
|
||||
they are.
|
||||
|
||||
# See also
|
||||
|
||||
- [Admin Shell](/guides/admin-shell.md) — side-nav layout and guard chain.
|
||||
- [Admin — Categories](/guides/admin-categories.md) — categories management page that renders below General settings.
|
||||
- [Admin Endpoints](/api/admin.md) — `GET/PUT /api/v1/admin/general/*` reference.
|
||||
- [Uploads Endpoints](/api/uploads.md) — `POST /api/v1/uploads/logo` reference.
|
||||
- [Backend Module Map](/architecture/backend-modules.md)
|
||||
+70
-44
@@ -1,9 +1,9 @@
|
||||
---
|
||||
type: guide
|
||||
title: Admin Shell & User Management
|
||||
description: How an authenticated admin navigates the post-login shell and reaches the admin user-management area.
|
||||
title: Admin Shell & Side Navigation
|
||||
description: How an authenticated admin navigates the post-login admin area, the side-nav layout, and how the General and Categories pages are reached.
|
||||
tags: [guide, admin, shell, navigation, tester]
|
||||
timestamp: 2026-07-21T22:19:08Z
|
||||
timestamp: 2026-07-22T12:00:00Z
|
||||
---
|
||||
|
||||
# When this view is available
|
||||
@@ -13,10 +13,10 @@ It is gated by:
|
||||
|
||||
| Layer | File | Check |
|
||||
|------------------|--------------------------------------------------------------------------------------------|------------------------------------|
|
||||
| Client route | `frontend/src/app/app.routes.ts` | `/admin` uses `adminGuard`. |
|
||||
| Client route | `frontend/src/app/app.routes.ts` | `/admin` parent uses `adminGuard`; children inherit it. |
|
||||
| Client nav link | `frontend/src/app/features/home/home.component.ts` | Renders only when `showAdminNav()` is true. |
|
||||
| Client predicate | `frontend/src/app/features/home/home.shell.ts` (`shouldShowAdminNav`) | `isAuthenticated && role === 'admin'`. |
|
||||
| Server route | `backend/src/modules/admin/admin.controller.ts` (mounted under `@UseGuards(AdminGuard)` + `@Roles('admin')`) | Requires admin JWT. |
|
||||
| Server route | `backend/src/modules/admin/admin.controller.ts` + `admin-general.controller.ts` + `admin-categories.controller.ts` (mounted under `@UseGuards(AdminGuard)` + `@Roles('admin')`) | Requires admin JWT. |
|
||||
|
||||
A non-admin (or unauthenticated) request to `/admin` is intercepted by
|
||||
the client guard *before* any HTTP call is made, so the page never
|
||||
@@ -30,16 +30,34 @@ renders.
|
||||
3. The browser lands on `/` and renders the **Home shell** with a
|
||||
header containing the page title and a sign-in status line.
|
||||
4. Click the **Admin** nav link (`data-testid="nav-admin"`) in the
|
||||
shell header, or navigate directly to `/admin`.
|
||||
shell header, or open the username menu and choose **Admin area**,
|
||||
or navigate directly to `/admin`.
|
||||
5. The admin area renders inside the shell:
|
||||
- **Heading:** "Admin area"
|
||||
- **Loading state:** `Loading users...` (`data-testid="admin-loading"`)
|
||||
while the GET is in flight.
|
||||
- **User list:** an unordered list (`data-testid="admin-user-list"`)
|
||||
showing one `<li>` per user with the username in bold and the role
|
||||
in parentheses, e.g. `root (admin)`.
|
||||
- **Error state:** a red message (`data-testid="admin-error"`) when
|
||||
the request fails (e.g. backend down or auth expired).
|
||||
- **Aside** (`data-testid="admin-aside"`): heading "Admin area" and
|
||||
a vertical side-nav (`data-testid="admin-nav"`).
|
||||
- **Body** (`data-testid="admin-body"`): holds the
|
||||
`<router-outlet />` that renders the active child page.
|
||||
|
||||
# Side-nav entries
|
||||
|
||||
The side-nav is defined as a static `ENTRIES` array in
|
||||
`frontend/src/app/features/admin/admin-shell.component.ts`:
|
||||
|
||||
| Label | Path | Enabled | Renders |
|
||||
|-------------|-----------------------|---------|----------------------------------------------------------------------------------------------|
|
||||
| General | `/admin/general` | yes | [Admin — General Settings](/guides/admin-general-settings.md) (default — `/admin` redirects here). |
|
||||
| Challenges | `/admin/challenges` | no | Greyed-out placeholder (`.disabled` class). No route registered. |
|
||||
| Players | `/admin/players` | no | Greyed-out placeholder. No route registered. |
|
||||
| Blog | `/admin/blog` | no | Greyed-out placeholder. No route registered. |
|
||||
| System | `/admin/system` | no | Greyed-out placeholder. No route registered. |
|
||||
|
||||
Each `<li>` carries `data-testid="admin-nav-{id}"`. Disabled entries
|
||||
have `cursor: not-allowed` and `opacity: 0.45`. Clicking a disabled
|
||||
entry is a no-op (`go()` returns early when `!e.enabled`).
|
||||
|
||||
The active entry is highlighted by `[class.active]` whenever the
|
||||
current URL starts with the entry's path. General is the default child
|
||||
(`/admin` → `/admin/general`).
|
||||
|
||||
# Expected behavior
|
||||
|
||||
@@ -47,50 +65,56 @@ renders.
|
||||
|----------------------|---------------------------------------------------------|
|
||||
| Unauthenticated | Redirected to `/login` by `adminGuard`. |
|
||||
| Authenticated player | Redirected to `/` by `adminGuard`. |
|
||||
| Authenticated admin | Page renders, fetches `GET /api/v1/admin/users`, lists users. |
|
||||
| Authenticated admin | Page renders, defaults to `/admin/general`. |
|
||||
|
||||
* When `BootstrapService.initialized()` is still `false` the guard
|
||||
redirects to `/bootstrap` instead of `/login`, so the first admin
|
||||
flow is honored.
|
||||
* The Admin nav link is hidden for non-admin users — there is no
|
||||
visible UI affordance to reach `/admin` without the role.
|
||||
* The list endpoint uses the existing `authInterceptor` + `csrfInterceptor`,
|
||||
so no extra plumbing is required.
|
||||
* The Admin nav link in the shell header is hidden for non-admin users
|
||||
— there is no visible UI affordance to reach `/admin` without the
|
||||
role.
|
||||
* All admin HTTP requests use the existing `authInterceptor` +
|
||||
`csrfInterceptor`, so no extra plumbing is required.
|
||||
|
||||
# Visual elements
|
||||
|
||||
| Element | Selector | Purpose |
|
||||
|----------------------|-----------------------------------|----------------------------------------------|
|
||||
| Shell header | `.shell-header` | Page title + signed-in identity. |
|
||||
| Admin nav link | `[data-testid="nav-admin"]` | RouterLink to `/admin`; shown to admins only. |
|
||||
| Shell body | `.shell-body` | Holds `<router-outlet>` for child routes. |
|
||||
| Admin heading | `h2` inside `.admin-area` | "Admin area". |
|
||||
| Loading message | `[data-testid="admin-loading"]` | "Loading users...". |
|
||||
| Error message | `[data-testid="admin-error"]` | Red text; renders `error().error.message` or fallback. |
|
||||
| User list | `[data-testid="admin-user-list"]` | Renders one `<li>` per `AdminUser`. |
|
||||
| Element | Selector | Purpose |
|
||||
|------------------------|-------------------------------------------|--------------------------------------------------------------------------|
|
||||
| Shell aside | `[data-testid="admin-aside"]` | Side-nav container. Heading "Admin area". |
|
||||
| Side-nav list | `[data-testid="admin-nav"]` | `<ul>` of all five entries. |
|
||||
| Side-nav entry | `[data-testid="admin-nav-{id}"]` | One `<li>` per entry (General / Challenges / Players / Blog / System). |
|
||||
| Shell body | `[data-testid="admin-body"]` | Wraps `<router-outlet />` for the active child page. |
|
||||
|
||||
# Architecture map
|
||||
|
||||
| Step | Where | What happens |
|
||||
|------|----------------------------------------------------|-----------------------------------------------------------------------|
|
||||
| 1 | `frontend/src/app/app.routes.ts` | `/` is a parent route with `authGuard`; `/admin` child uses `adminGuard` + lazy-loads `AdminUsersComponent`. |
|
||||
| 2 | `frontend/src/app/core/guards/admin.guard.ts` | `adminGuard` calls `decideAdminGuard(...)` with bootstrap + auth state. |
|
||||
| 3 | `frontend/src/app/core/guards/admin.guard.decision.ts` | Pure function returning `{kind: 'allow'}` or `{kind: 'redirect', path}`. |
|
||||
| 4 | `frontend/src/app/features/home/home.component.ts` | Shell template renders header, conditional nav (`*ngIf="showAdminNav()"`), and `<router-outlet>`. |
|
||||
| 5 | `frontend/src/app/features/home/home.shell.ts` | `shouldShowAdminNav({isAuthenticated, role})` predicate (exported and unit-tested). |
|
||||
| 6 | `frontend/src/app/features/admin/admin-users.component.ts` | On init, calls `AdminService.listUsers()` and populates signals (`loading`, `error`, `users`). |
|
||||
| 7 | `frontend/src/app/core/services/admin.service.ts` | `GET /api/v1/admin/users` (credentials included); typed as `AdminUser[]`. |
|
||||
| 8 | `backend/src/modules/admin/admin.controller.ts` | `AdminController.list` returns `AdminService.listUsers({limit, cursor, role})`. |
|
||||
| Step | Where | What happens |
|
||||
|------|-------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| 1 | `frontend/src/app/app.routes.ts` | `/` is a parent route with `authGuard`; `/admin` child uses `adminGuard` + lazy-loads `AdminShellComponent` with its own child routes. |
|
||||
| 2 | `frontend/src/app/core/guards/admin.guard.ts` | `adminGuard` calls `decideAdminGuard(...)` with bootstrap + auth state. |
|
||||
| 3 | `frontend/src/app/core/guards/admin.guard.decision.ts` | Pure function returning `{kind: 'allow'}` or `{kind: 'redirect', path}`. |
|
||||
| 4 | `frontend/src/app/features/admin/admin-shell.component.ts` | Renders the aside + body; `ENTRIES` is the static side-nav list. |
|
||||
| 5 | `frontend/src/app/features/admin/general.component.ts` | `AdminGeneralComponent` (default `/admin/general`); embeds `AdminCategoriesComponent`. |
|
||||
| 6 | `frontend/src/app/features/admin/categories/categories.component.ts` | `AdminCategoriesComponent` (`/admin/categories`); also rendered inside the General page. |
|
||||
| 7 | `frontend/src/app/features/home/home.shell.ts` | `shouldShowAdminNav({isAuthenticated, role})` predicate (exported and unit-tested). |
|
||||
| 8 | `frontend/src/app/features/home/home.component.ts` | Shell template renders header, conditional nav (`*ngIf="showAdminNav()"`), and `<router-outlet>`. |
|
||||
| 9 | `frontend/src/app/core/services/admin.service.ts` | Typed wrappers for `/api/v1/admin/users`, `/admin/general/*`, `/admin/categories/*`, `/uploads/{logo,category-icon}`. |
|
||||
| 10 | `backend/src/modules/admin/admin.module.ts` | Registers `AdminController`, `AdminGeneralController`, `AdminCategoriesController` + their services. Imports `AuthModule`, `UsersModule`, `SettingsModule`, `CommonModule`, and `TypeOrmModule.forFeature([UserEntity, CategoryEntity, ChallengeEntity])`. |
|
||||
|
||||
# Notes
|
||||
|
||||
* The shell deliberately keeps `HomeComponent` as a thin layout owner —
|
||||
child routes (currently just `/admin`) render into its
|
||||
`<router-outlet>`. New admin sub-pages can be added as additional
|
||||
children without changing the shell.
|
||||
* The shell deliberately keeps `AdminShellComponent` as a thin layout
|
||||
owner — child routes (`general`, `categories`) render into its
|
||||
`<router-outlet>`. New admin sub-pages can be added by enabling
|
||||
entries in `ENTRIES` and registering a child route in `app.routes.ts`.
|
||||
* The guard decision function (`decideAdminGuard`) is a pure module so
|
||||
it is straightforward to unit-test without Angular DI. See
|
||||
`tests/frontend/admin-shell.spec.ts` and `tests/frontend/admin-navigation.spec.ts`.
|
||||
`tests/frontend/admin-shell.spec.ts` and
|
||||
`tests/frontend/admin-navigation.spec.ts`.
|
||||
* The Categories management page is intentionally embedded inside the
|
||||
General settings page (see
|
||||
[Admin — General Settings](/guides/admin-general-settings.md)) so an
|
||||
admin can adjust platform settings and challenge taxonomy in one
|
||||
place.
|
||||
|
||||
# See also
|
||||
|
||||
@@ -98,5 +122,7 @@ renders.
|
||||
- [Frontend Structure](/architecture/frontend-structure.md)
|
||||
- [Authenticated Shell](/guides/authenticated-shell.md) — header / LED / quick tabs / change-password modal / user menu (the surrounding shell this page renders into).
|
||||
- [Change Password](/guides/change-password.md)
|
||||
- [Admin — General Settings](/guides/admin-general-settings.md)
|
||||
- [Admin — Categories](/guides/admin-categories.md)
|
||||
- [REST API Overview](/api/rest-overview.md)
|
||||
- [Admin Endpoints](/api/admin.md)
|
||||
- [Admin Endpoints](/api/admin.md)
|
||||
|
||||
Reference in New Issue
Block a user