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
@@ -3,7 +3,7 @@
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from models import Article, Author, Category, User, slugify
|
||||
from models import Article, Author, Category, Item, User, slugify
|
||||
|
||||
|
||||
class TestAuthor:
|
||||
@@ -49,8 +49,16 @@ class TestUser:
|
||||
session.refresh(user)
|
||||
assert user.id is not None
|
||||
assert user.created_at is not None
|
||||
assert user.is_admin is False # default: no admin rights (M6)
|
||||
assert session.get(User, user.id).username == "alice"
|
||||
|
||||
def test_is_admin_can_be_set(self, session) -> None:
|
||||
user = User(username="root", password_hash="abc$def", is_admin=True)
|
||||
session.add(user)
|
||||
session.commit()
|
||||
session.refresh(user)
|
||||
assert user.is_admin is True
|
||||
|
||||
def test_unique_username_enforced(self, session) -> None:
|
||||
session.add(User(username="alice", password_hash="abc$def"))
|
||||
session.commit()
|
||||
@@ -154,3 +162,34 @@ class TestArticle:
|
||||
with pytest.raises(IntegrityError):
|
||||
session.commit()
|
||||
session.rollback()
|
||||
|
||||
|
||||
class TestItem:
|
||||
def test_create_and_commit_defaults(self, session) -> None:
|
||||
item = Item(title="Breaking: things happen")
|
||||
session.add(item)
|
||||
session.commit()
|
||||
session.refresh(item)
|
||||
assert item.id is not None
|
||||
assert item.url == ""
|
||||
assert item.points == 0
|
||||
assert item.username == "anonymous"
|
||||
assert item.content == ""
|
||||
assert item.created_at is not None
|
||||
|
||||
def test_create_with_all_fields(self, session) -> None:
|
||||
item = Item(
|
||||
title="Show HN: a new tool",
|
||||
url="https://example.com/show-hn",
|
||||
points=42,
|
||||
username="alice",
|
||||
content="<p>Hello <strong>world</strong></p>",
|
||||
)
|
||||
session.add(item)
|
||||
session.commit()
|
||||
session.refresh(item)
|
||||
assert item.title == "Show HN: a new tool"
|
||||
assert item.url == "https://example.com/show-hn"
|
||||
assert item.points == 42
|
||||
assert item.username == "alice"
|
||||
assert item.content == "<p>Hello <strong>world</strong></p>"
|
||||
Reference in new issue
Block a user