feat: add admin dashboard, audit logs, token expiry check and test suite

Frontend Features:
- Add ProtectedRoute component with token expiry validation
- Create AdminDashboardPage with system statistics and user management
- Create AuditLogsPage with filtering and pagination
- Add admin-only navigation (Shield icon) for ymirliu@panjit.com.tw
- Add admin API methods to apiV2 service
- Add admin type definitions (SystemStats, AuditLog, etc.)

Token Management:
- Auto-redirect to login on token expiry
- Check authentication on route change
- Show loading state during auth check
- Admin privilege verification

Backend Testing:
- Add pytest configuration (pytest.ini)
- Create test fixtures (conftest.py)
- Add unit tests for auth, tasks, and admin endpoints
- Add integration tests for complete workflows
- Test user isolation and admin access control

Documentation:
- Add TESTING.md with comprehensive testing guide
- Include test running instructions
- Document fixtures and best practices

Routes:
- /admin - Admin dashboard (admin only)
- /admin/audit-logs - Audit logs viewer (admin only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-11-16 18:01:50 +08:00
parent fd98018ddd
commit 8f94191914
13 changed files with 1554 additions and 45 deletions

View File

@@ -1,5 +1,4 @@
import { Routes, Route, Navigate } from 'react-router-dom'
import { useAuthStore } from '@/store/authStore'
import LoginPage from '@/pages/LoginPage'
import UploadPage from '@/pages/UploadPage'
import ProcessingPage from '@/pages/ProcessingPage'
@@ -7,20 +6,10 @@ import ResultsPage from '@/pages/ResultsPage'
import ExportPage from '@/pages/ExportPage'
import SettingsPage from '@/pages/SettingsPage'
import TaskHistoryPage from '@/pages/TaskHistoryPage'
import AdminDashboardPage from '@/pages/AdminDashboardPage'
import AuditLogsPage from '@/pages/AuditLogsPage'
import Layout from '@/components/Layout'
/**
* Protected Route Component
*/
function ProtectedRoute({ children }: { children: React.ReactNode }) {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
if (!isAuthenticated) {
return <Navigate to="/login" replace />
}
return <>{children}</>
}
import ProtectedRoute from '@/components/ProtectedRoute'
function App() {
return (
@@ -44,6 +33,24 @@ function App() {
<Route path="export" element={<ExportPage />} />
<Route path="tasks" element={<TaskHistoryPage />} />
<Route path="settings" element={<SettingsPage />} />
{/* Admin routes - require admin privileges */}
<Route
path="admin"
element={
<ProtectedRoute requireAdmin>
<AdminDashboardPage />
</ProtectedRoute>
}
/>
<Route
path="admin/audit-logs"
element={
<ProtectedRoute requireAdmin>
<AuditLogsPage />
</ProtectedRoute>
}
/>
</Route>
{/* Catch all */}