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
+55
-25
@@ -1,9 +1,12 @@
|
||||
import { BrowserRouter, Link, Route, Routes } from 'react-router-dom';
|
||||
import { AuthProvider, RequireAuth } from './auth';
|
||||
import { AuthProvider, RequireAdmin, RequireAuth } from './auth';
|
||||
import AdminLayout from './components/AdminLayout';
|
||||
import Layout from './components/ui/Layout';
|
||||
import Account from './pages/Account';
|
||||
import AdminDashboard from './pages/AdminDashboard';
|
||||
import ArticlePage from './pages/ArticlePage';
|
||||
import CategoriesPage from './pages/CategoriesPage';
|
||||
import EditItemPage from './pages/EditItemPage';
|
||||
import Home from './pages/Home';
|
||||
import Login from './pages/Login';
|
||||
import Register from './pages/Register';
|
||||
@@ -28,10 +31,15 @@ function NotFound() {
|
||||
* Root component: owns the React Router + auth setup.
|
||||
*
|
||||
* BrowserRouter wraps the whole app; AuthProvider restores the JWT
|
||||
* session and exposes login/register/logout (see src/auth.tsx); Layout
|
||||
* provides the shared shell (header/footer); Routes maps URLs to page
|
||||
* components in src/pages/. In-app navigation always uses
|
||||
* react-router-dom <Link>/<NavLink>.
|
||||
* session and exposes login/register/logout (see src/auth.tsx).
|
||||
*
|
||||
* Two shells are used:
|
||||
* - the admin area (`/admin/*`, M6) renders inside its own dark sidebar
|
||||
* layout (`AdminLayout`) and is guarded by `RequireAdmin`;
|
||||
* - everything else renders inside the public site `Layout`
|
||||
* (header/footer) with `RequireAuth` guarding the account page.
|
||||
*
|
||||
* In-app navigation always uses react-router-dom <Link>/<NavLink>.
|
||||
*/
|
||||
export default function App() {
|
||||
return (
|
||||
@@ -42,26 +50,48 @@ export default function App() {
|
||||
}}
|
||||
>
|
||||
<AuthProvider>
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/articles" element={<ArticlePage />} />
|
||||
<Route path="/articles/:id" element={<ArticlePage />} />
|
||||
<Route path="/categories" element={<CategoriesPage />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
<Route path="/sign-out" element={<SignOut />} />
|
||||
<Route
|
||||
path="/account"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<Account />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
<Routes>
|
||||
{/* Admin area (own shell, admin-only) */}
|
||||
<Route
|
||||
path="/admin"
|
||||
element={
|
||||
<RequireAdmin>
|
||||
<AdminLayout />
|
||||
</RequireAdmin>
|
||||
}
|
||||
>
|
||||
<Route index element={<AdminDashboard />} />
|
||||
<Route path="items/new" element={<EditItemPage />} />
|
||||
<Route path="items/:id/edit" element={<EditItemPage />} />
|
||||
</Route>
|
||||
|
||||
{/* Public site */}
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/articles" element={<ArticlePage />} />
|
||||
<Route path="/articles/:id" element={<ArticlePage />} />
|
||||
<Route path="/categories" element={<CategoriesPage />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
<Route path="/sign-out" element={<SignOut />} />
|
||||
<Route
|
||||
path="/account"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<Account />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</AuthProvider>
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user