3.6 KiB
3.6 KiB
Superadmin CRUD Implementation Plan
Objective: Implement a superadmin role to manage courses and tutors, ensuring only authorized users can perform system-wide administrative actions. This feature will be developed in an isolated git worktree.
Key Context & Decisions
- Role Strategy: A new
is_superadminboolean column will be added to thetutorsdatabase table. - UI Structure: A dedicated
/admin/tutorspage will handle tutor management. Course management will remain on/admin/coursesbut will be enhanced with superadmin-only actions (e.g., assigning tutors to courses). - Workspace: Development will be done in
.worktrees/feature-superadmin-crud.
Implementation Steps
1. Workspace Isolation via Git Worktree
- Create a new git worktree:
git worktree add .worktrees/feature-superadmin-crud -b feature-superadmin-crud - All subsequent steps will be performed inside this isolated workspace.
2. Database & Models
- Create migration
backend/migrations/002_add_superadmin.sqlto addis_superadmin BOOLEAN NOT NULL DEFAULT 0to thetutorstable. - Update
backend/demo/demo_seed.sqlto set the defaultadmin@tutortool.comas a superadmin (is_superadmin = 1). - Update
backend/src/models.rsto includeis_superadmin: boolin theTutorstruct. - Add
CreateTutorandTutorResponsestructs tobackend/src/models.rs.
3. Auth & Core Backend
- Modify
backend/src/auth.rsto includeis_superadmin: boolinTutorClaims. This allows auth guards to check permissions efficiently. - Update
backend/src/routes/auth_routes.rslogin handler to fetchis_superadminand encode it in the JWT. - Add a helper function to verify superadmin access to reject unauthorized requests.
4. Tutors API
- Create
backend/src/routes/tutors.rswith endpoints:GET /api/admin/tutors(list all tutors)POST /api/admin/tutors(create a tutor, hashing their password)DELETE /api/admin/tutors/:id(delete a tutor)
- Merge these routes in
backend/src/routes/mod.rs.
5. Course Assignments API
- Modify
backend/src/routes/courses.rs:- Enhance
GET /api/admin/coursesto return ALL courses ifclaims.is_superadminis true, otherwise only return assigned courses. - Restrict
POST /api/admin/coursesto superadmins only. - Add
POST /api/admin/courses/:id/tutorsto assign a tutor to a course (superadmin only). - Add
DELETE /api/admin/courses/:id/tutors/:tutor_idto remove a tutor from a course (superadmin only). - Add
GET /api/admin/courses/:id/tutorsto list tutors assigned to a course.
- Enhance
6. Frontend Auth & API Client
- Update
frontend/src/lib/types.tsto includeTutorand the newis_superadminflag in token payload or state. - Add the new endpoints to
frontend/src/lib/api.tsunderapi.admin.tutorsand enhanceapi.admin.courses.
7. Frontend UI: Tutors Management
- Update
frontend/src/lib/components/TutorShell.svelteto conditionally render a "Tutor:innen" link in the sidebar if the user is a superadmin. - Create
frontend/src/routes/admin/tutors/+page.sveltefollowing the paper-bg design system. Include a list of tutors and a form to add a new tutor.
8. Frontend UI: Courses Enhancements
- Modify
frontend/src/routes/admin/courses/+page.svelteto show a "Tutor:innen zuweisen" (Assign Tutors) section for each course if the logged-in user is a superadmin. - Restrict the course creation form to superadmins only.
Verification & Testing
- Run
cargo testin the backend to ensure existing tests pass and new route isolation works. - Perform a manual end-to-end test using the
make devscript in the new worktree to verify the UI.