Daniel Samson
b440809548
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.
2026-10-30 21:36:15 +00:00
Daniel Samson
b186d0f797
feat: add JWT authentication with auth pages and tests (M5)
...
Backend (FastAPI):
- core/auth.py: PBKDF2-HMAC-SHA256 password hashing (120k iterations,
random salt), HS256 JWT creation/verification (7-day expiry,
HN_SECRET_KEY via config) and get_current_user Bearer dependency
- models/user.py: User model (username unique/indexed, password_hash,
created_at); schemas/auth.py: register/login/token/user schemas
- api/v1/auth.py: POST /api/v1/auth/register (201), /login, /logout
(204), GET /me; 400 on duplicate username, 401 on bad credentials,
invalid/expired/unknown tokens
- requirements: PyJWT; env templates + docker-compose expose
HN_SECRET_KEY (dev default, override in production)
- tests: 24 new backend tests (hashing, tokens, all endpoints)
Frontend (React + TypeScript):
- api/client.ts: AUTH_TOKEN localStorage persistence, automatic
Bearer token attachment, 401 clears the stored token, typed
login/register/logout/me helpers
- auth.tsx: AuthProvider (session restore + login/register/logout)
and RequireAuth route guard
- pages: Login, Register, SignOut and a protected /account
placeholder; header shows sign-in/register or user/sign-out
- styles: auth component classes in globals.css
- tests: unit tests for the client, provider and pages; Playwright
E2E spec covering register/login/logout, session restore, invalid
token cleanup and protected-route redirects (API mocked)
Note: the milestone's /api/auth/* paths map to the project's
established /api/v1/* prefix (see M2); the HN_SECRET_KEY default is
newzy-dev-secret-change-me.
2026-10-30 17:03:00 +00:00
Daniel Samson
9a6f75ebd8
feat: add FastAPI backend with SQLite models and Docker setup
...
Implement milestone M2 (backend setup):
- FastAPI app factory (core/app.py) with CORS, lifespan table
creation, and global error handlers using a standardized
{detail, code, errors?} envelope
- Endpoints: GET /health, GET /api/v1/health, GET /api/v1/version
- SQLAlchemy 2.0 ORM: Article, Author, Category models with
relationships, unique constraints, and FK pragma for SQLite
- Pydantic v2 schemas (create/update/read) for all models
- Env-driven config (DATABASE_URL, CORS_ORIGINS) + .env.example
- pytest suite (19 tests, ~95% coverage) with per-test SQLite
databases via fixtures
- Dockerfile (python:3.11-slim) and docker-compose.yml with a
persistent ./data/db volume and healthcheck
2026-10-30 12:44:54 +00:00