feat: add admin area with item CRUD, Lexical editor and access control (M6)
Backend: - Item model (title, url, points, username, content, created_at) - is_admin flag on User + startup migration for pre-existing DBs - get_current_admin dependency (401 without/invalid token, 403 for non-admins); server-side check on every admin endpoint - /api/v1/admin/items CRUD: pagination, case-insensitive title/url search, sort by title/created_at/points, in-memory rate limiting (1000 req/60s per admin -> 429) - seed_admin.py (ADMIN_USERNAME/ADMIN_PASSWORD), documented in backend/.env.example Frontend: - Auth context exposes is_admin; RequireAdmin route guard (redirects signed-out users, renders 403 page for non-admins) - AdminLayout with responsive dark sidebar; Admin link in header for admins only - AdminDashboard: paginated table (page size 10/20/50), 300ms debounced search, sortable title/points/created_at columns, edit/delete row actions - EditItemPage: create + edit with client-side validation and a Lexical (0.25) WYSIWYG editor (bold/italic/underline, H1-H6, lists, code blocks, links, undo/redo), optional debounced auto-save - DeleteConfirmation modal with warning icon and explicit "Yes, delete" confirmation - Unit tests (34) and mocked E2E workflow tests (10) All acceptance criteria for milestones/m6-setup-admin-area-prompt.md verified: 108 backend, 87 frontend unit and 29 E2E tests pass.
This commit is contained in:
1 parent
b186d0f797
commit
b440809548
38 files changed
+5415
-50
No files matched your search
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Admin area types (mirror the backend `schemas.item` payloads).
|
||||
*
|
||||
* The backend returns snake_case JSON; these interfaces keep the wire
|
||||
* shape 1:1 (no remapping) because they are only consumed by the admin
|
||||
* pages.
|
||||
*/
|
||||
|
||||
/** One news item as managed in the admin area. */
|
||||
export interface AdminItem {
|
||||
id: number;
|
||||
title: string;
|
||||
url: string;
|
||||
points: number;
|
||||
/** Username the item belongs to (denormalized). */
|
||||
username: string;
|
||||
/** HTML body produced by the Lexical editor. */
|
||||
content: string;
|
||||
/** ISO-8601 timestamp. */
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** Payload of `GET /api/v1/admin/items` (paginated list). */
|
||||
export interface AdminItemsPage {
|
||||
items: AdminItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
}
|
||||
|
||||
/** Sortable columns of the item list. */
|
||||
export type AdminSortBy = 'title' | 'created_at' | 'points';
|
||||
|
||||
export type AdminSortOrder = 'asc' | 'desc';
|
||||
|
||||
/** Query parameters of the item list endpoint. */
|
||||
export interface AdminListParams {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
/** Case-insensitive match on title OR url. */
|
||||
search: string;
|
||||
sortBy: AdminSortBy;
|
||||
sortOrder: AdminSortOrder;
|
||||
}
|
||||
|
||||
/** Payload of `POST /api/v1/admin/items` and `PUT /api/v1/admin/items/{id}`. */
|
||||
export interface AdminItemInput {
|
||||
title: string;
|
||||
url: string;
|
||||
points: number;
|
||||
username: string;
|
||||
content: string;
|
||||
}
|
||||
@@ -7,9 +7,13 @@ export interface TokenResponse {
|
||||
/** Signed JWT (7-day expiry) — store and send back as `Bearer` token. */
|
||||
token: string;
|
||||
username: string;
|
||||
/** Whether the account may access the admin area (M6). */
|
||||
is_admin?: boolean;
|
||||
}
|
||||
|
||||
/** Payload of `GET /api/v1/auth/me`. */
|
||||
export interface MeResponse {
|
||||
username: string;
|
||||
/** Whether the account may access the admin area (M6). */
|
||||
is_admin?: boolean;
|
||||
}
|
||||
Reference in new issue
Block a user