Description
The course deletion route is protected by authentication and allows teachers and admins.
However, the controller currently deletes a course using only its _id. It does not verify that a teacher owns the course before deletion.
This may allow one teacher to delete a course created by another teacher.
Proposed solution
Update the deletion controller so that:
- Admin users may delete any course.
- Teacher users may delete only courses whose
userId matches their authenticated user ID.
- The authenticated user ID is taken from the verified token, not from the request body.
- A non-owner receives
403 Forbidden.
- A missing course receives
404 Not Found.
- Invalid MongoDB IDs receive a controlled
400 response.
- Associated local video files are handled safely according to the existing deletion policy.
- Backend tests verify teacher ownership and admin access.
Acceptance criteria
Suggested files
backend/controllers/userControllers.js
backend/middlewares/authMiddleware.js
backend/routers/userRoutes.js
backend/tests/course-ownership.test.js
Description
The course deletion route is protected by authentication and allows teachers and admins.
However, the controller currently deletes a course using only its
_id. It does not verify that a teacher owns the course before deletion.This may allow one teacher to delete a course created by another teacher.
Proposed solution
Update the deletion controller so that:
userIdmatches their authenticated user ID.403 Forbidden.404 Not Found.400response.Acceptance criteria
404.Suggested files