Files
news-benchmark/milestone/m6-setup-admin-area-scoring.md
Daniel Samson 4c82e4f54c feat: add M6 setup admin area milestone
Backend (FastAPI):
- is_admin field added to User model with default False
- Admin-only dependency validates JWT AND is_admin flag
- Protected CRUD endpoints for items management
- Pagination, search by title/url, sort by title/date

Frontend (React + TypeScript):
- AdminLayout with sidebar navigation protected by auth check
- AdminDashboard with pagination controls and page size selector
- EditItemPage with Lexical WYSIWYG editor toolbar
- DeleteConfirmation modal requires explicit confirmation
- Warning icon and consequences message before delete

Security:
- Server-side 403 Forbidden for non-admin users
- JWT token validation required on all admin routes
2026-10-29 16:23:52 +00:00

12 KiB

M6: Setup Admin Area - Scoring Rubric

Acceptance Criteria Scoring Table

Score Criteria
0 Agent failed to implement acceptance criteria:
- No is_admin field added to User model
- Admin endpoints not created or unprotected
- No admin routes in frontend
- Delete without confirmation
- Lexical editor not integrated
1 Agent partially implemented acceptance criteria that builds successfully:
- User model has is_admin but no validation logic
- One admin endpoint working (e.g., list only)
- Frontend has placeholder route but no functionality<br- No delete confirmation<br- Basic list view without pagination
2 Agent fully implemented acceptance criteria that builds successfully:
is_admin field in User model with default value
- Backend admin dependency checks JWT AND is_admin flag (403 for non-admins)<br- GET /api/admin/items returns paginated data<br- Frontend AdminLayout component created with sidebar navigation<br- Delete action exists but confirmation missing
3 Agent fully implemented acceptance criteria that builds successfully, includes working pagination with page/page_size parameters in response<br- Search functionality filters by title/url (case-insensitive)<br- Sort controls toggle asc/desc order for title and date columns
4 Agent fully implemented acceptance criteria that builds successfully, includes EditItemPage component pre-filling form with item data<br- Admin API client methods defined for create/update/delete/list<br- Form validation prevents empty submissions
5 Agent fully implemented acceptance criteria that builds successfully, includes Lexical WYSIWYG editor integration in edit form<br- Editor has toolbar (bold, italic, headings, lists)<br- Rich text content saved correctly to database
6 Agent fully implemented acceptance criteria that builds successfully, includes DeleteConfirmation modal with warning icon<br- Requires explicit "Yes, delete" click to confirm<br- Warning message explains consequences
7 Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 5 AND:<br- SweetAlert2 or custom modal with proper overlay styling<br- Modal dismisses on outside click (escapes modal area)<br- Cancel button properly exits without deleting

Scoring Breakdown by Criterion

Database Schema (Max 3 points)

  • 0 pts: No is_admin field in User model
    - Missing migration or no field added
  • 1 pt: is_admin Boolean field exists but wrong default
    - Not stored in database
  • 2 pts: is_admin Boolean field with default=False<br- Properly typed in SQLAlchemy model
  • 3 pts: Migration creates column correctly<br- Sample data seeded (admin user exists)

Backend Admin Protection (Max 4 points)

  • 0 pts: No admin-only dependency or check
    - All endpoints publicly accessible
  • 1 pt: JWT token checked but not is_admin flag
    - Returns 200 for non-admins
  • 2 pts: Admin dependency validates token AND checks is_admin<br- Raises 403 for non-admin users (correct status code)
  • 3 pts: Error message includes "Admin access required"<br- Security headers set appropriately
  • 4 pts: All CRUD endpoints protected by admin check<br- Server-side validation not dependent on client

Admin List Endpoint (Max 4 points)

  • 0 pts: No /api/admin/items endpoint
    - Returns empty/error response
  • 1 pt: Endpoint exists but returns all items without pagination
    - Infinite list
  • 2 pts: Pagination parameters work (page, page_size)<br- Response includes items array and count
  • 3 pts: Search parameter filters by title OR url<br- Case-insensitive search implemented
  • 4 pts: Sort parameters work for title AND created_at<br- Both ascending and descending orders

Create Endpoint (Max 3 points)

  • 0 pts: No POST /api/admin/items endpoint
    - Cannot create items via admin API
  • 1 pt: Endpoint exists but doesn't require admin flag
    - Non-admins can create
  • 2 pts: Admin-only creation with proper validation<br- Returns created item or appropriate error
  • 3 pts: Input validation (title required, URL format check)<br- Database transaction commits successfully

Update Endpoint (Max 3 points)

  • 0 pts: No PUT /api/admin/items/{id} endpoint
    - Cannot update existing items
  • 1 pt: Endpoint exists but open to all users
    - Non-admins can modify items
  • 2 pts: Admin-only updates with proper field mapping<br- Updates id, title, url, points, content correctly
  • 3 pts: Optimistic UI feedback on frontend (pending save)<br- Error handling for failed updates

Delete Endpoint (Max 3 points)

  • 0 pts: No DELETE /api/admin/items/{id} endpoint
    - Cannot delete items via API
  • 1 pt: Endpoint exists but returns success immediately
    - No confirmation mechanism
  • 2 pts: Admin-only deletion with proper verification<br- Removes item from database correctly
  • 3 pts: Optional soft delete (published=False) implemented<br- Hard delete works and removes records

Frontend Layout (Max 4 points)

  • 0 pts: No admin layout or sidebar navigation
    - Admin pages inaccessible
  • 1 pt: Protected route exists but AuthContext check missing
    - Non-admins can access UI
  • 2 pts: AdminLayout renders only for is_admin=true users<br- Sidebar navigation with back button works
  • 3 pts: Layout collapses on mobile (responsive)<br- Breadcrumbs or title indicates admin area
  • 4 pts: Error state if not admin shows friendly message<br- Protected routes redirect to home/login

List View Components (Max 6 points)

  • 0 pts: No list view component
    - Items page missing entirely
  • 1 pt: Basic table/list but no pagination controls<br- All items displayed at once
  • 2 pts: Pagination controls functional (prev/next, page numbers)<br- Page size selector present and working
  • 3 pts: Card-based or table layout with hover effects<br- Loading state shows during fetch
  • 4 pts: Item count displays (X of Y items total)<br- Empty state shown when no items match search
  • 5 pts: Search debounced (300ms delay before API call)<br- Results update without page refresh
  • 6 pts: Edit and delete buttons on each row<br- Action icons or clearly labeled text

Edit View Components (Max 4 points)

  • 0 pts: No edit page or form missing
    - Cannot create/edit items
  • 1 pt: Create/Edit form exists but missing fields<br- Only title input, no content editor
  • 2 pts: Form includes all required fields (title, url, points, content)<br- Save button triggers API request
  • 3 pts: Form pre-fills with existing item data for edit mode<br- Loading state during save operation
  • 4 pts: Cancel button reverts to unsaved state<br- Success notification on completion

Delete Confirmation (Max 5 points)

  • 0 pts: No confirmation dialog
    - Direct delete without warning
  • 1 pt: Modal appears but no warning icon or message<br- Just "Are you sure?" text only
  • 2 pts: Warning icon present (exclamation/triangle)<br- Title explains deletion action
  • 3 pts: Message describes consequences clearly<br- "This action cannot be undone" message present
  • 4 pts: Two buttons: Cancel and Delete<br- Delete button requires explicit confirmation ("Yes, delete")
  • 5 pts: Outside click dismisses modal<br- ESC key closes dialog

Lexical Editor (Max 5 points)

  • 0 pts: No WYSIWYG editor
    - Text area only, no formatting
  • 1 pt: Basic textarea but not integrated with React properly<br- Plain text save only
  • 2 pts: Lexical editor imported and mounted<br- ContentEditable div present
  • 3 pts: Toolbar shows formatting buttons (bold, italic)<br- Buttons clickable but may not work yet
  • 4 pts: Bold/italic/headings/lists actually formatted<br- HTML output contains proper tags
  • 5 pts: Rich text content saves to database correctly<br- Retrieved content displays with formatting

Frontend API Client (Max 4 points)

  • 0 pts: No adminApi client file
    - Hardcoded fetch URLs scattered throughout
  • 1 pt: Admin methods exist but no Bearer token attachment
    - Authentication fails silently
  • 2 pts: create, read, update, delete methods implemented<br- All four CRUD operations callable
  • 3 pts: Pagination parameters included in list request<br- Search/sort params work correctly
  • 4 pts: Error handling wraps all API calls properly<br- Throws errors on 403/404 responses

Total Possible Score: 51 points

Evaluation Notes

  • Partial credit given for incomplete but working implementations (Score 1)
  • Full credit requires all acceptance criteria met with passing verification (Score 2 minimum)
  • Higher scores require additional value-add content beyond baseline requirements
  • Score 0 indicates agent did not attempt the task or security is compromised

Critical Security Requirements

MUST HAVE for Score >2:

  • is_admin field exists in database
  • Backend validates BOTH JWT token AND is_admin flag
  • Non-admin users receive 403 Forbidden status
  • Error message indicates admin access required

MUST HAVE for Score >4:

  • All CRUD endpoints protected server-side
  • Search filters by title OR url (not just client-side)
  • Sort parameters actually change database query order

MUST HAVE for Score >6:

  • Delete requires explicit confirmation dialog
  • Warning message explains consequences
  • Cancel button available and functional

Bonus Points Consideration

+1 point for:

  • Soft delete implementation (sets published=False instead of removing record)
  • Audit logging placeholder (logs admin action to database table or file)

+2 points for:

  • Loading skeleton while fetching items list
  • Empty state UI when no search results found
  • Pagination metadata in response (total_pages, current_page)

+3 points for:

  • Responsive design on mobile devices
  • Keyboard shortcuts (Ctrl+S to save, ESC to cancel)
  • Keyboard navigation (Tab between form fields, Enter to save)

Test Scenarios to Verify Score 5+

  1. Non-Admin Access:

    • User with is_admin=False calls /api/admin/items → 403 Forbidden
    • Frontend detects 403 and shows access denied message
    • JWT token valid but insufficient permissions
  2. Admin Authentication:

    • Admin user with valid token calls /api/admin/items → 200 OK
    • Response includes pagination metadata (page, page_size, total_pages)
    • Items array contains all expected properties
  3. Pagination:

    • Request page=2, page_size=10 returns second page of items
    • Total count accurate across pages
    • Page size selector changes items per page
  4. Search:

    • Search "test" finds items with "test" in title OR url
    • Case-insensitive search (works for "Test", "TEST", "test")
    • Empty search returns all items
  5. Sorting:

    • Sort by title asc shows A-Z order
    • Sort by created_at desc shows newest first
    • Toggle switches between orders successfully
  6. Delete Confirmation:

    • Click delete → confirmation modal appears
    • Warning icon visible (red or yellow triangle)
    • Message includes "cannot be undone" warning
    • Cancel button dismisses without deleting
    • Outside click dismisses modal
    • Only explicit "Yes, Delete" triggers API request
  7. Lexical Editor:

    • Type text with bold formatting applied
    • Save button stores content as rich HTML
    • Retrieved content displays formatting correctly
    • Undo/redo functionality works (if implemented)
  8. Form Validation:

    • Empty title field blocks save operation
    • Invalid URL format triggers error message
    • Loading state shows while submitting
    • Success notification appears on completion