Refactor permissions logic in controllers and models for clarity, defining roles for students, instructors, TAs, and site admins.#370
Draft
cycomachead wants to merge 1 commit intomainfrom
Conversation
Refactor permissions logic to distinguish between course admins (Instructors/Lead TAs) and regular staff (TAs). - Course admins can manage settings, form configurations, and course deletion. - Regular TAs can view enrollments, sync data, and approve/deny requests, but cannot modify course settings. - Site admins are granted full access across all courses. - Updated ApplicationController and Course model with `course_admin?` and `staff?` helpers to centralize authorization logic. - Updated views and sidebars to conditionally display actions based on the new role definitions. Co-authored-by: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
General Info
Changes
This PR refactors the permissions logic across controllers, models, and views to implement a clear role-based access control (RBAC) system with four distinct permission tiers:
Key Changes
Coursemodel — Addedstaff?(user)helper for all staff + site admins. Updatedcourse_admin?(user)anduser_role(user)to properly include site admins, ensuring they always receive instructor-level access.ApplicationController— Replaced the singleensure_instructor_rolewith two distinct guards:ensure_course_admin— for settings, form configuration, and course deletion (instructors/lead TAs/site admins only)ensure_staff_role— for enrollments, approvals, and syncing (all staff + site admins)set_coursenow also sets@is_course_adminand@is_staffinstance variables for use in controllers and views.CoursesController—enrollmentsandsync_enrollmentsare now accessible to all staff (previously instructor-only).editanddeleteare restricted to course admins.AssignmentsController—toggle_enablednow checkscourse_admin?instead of a raw role string comparison, and usescurrent_userdirectly rather than accepting a role via params.CourseSettingsController&FormSettingsController— Switched fromensure_instructor_roletoensure_course_admin, so only instructors and lead TAs can modify course/form settings.RequestsController&RequestService— Renamedcheck_instructor_permission→check_staff_permission. All staff can now approve/deny requests and create requests on behalf of students.UserToCoursesController—ensure_course_adminnow delegates toCourse#course_admin?(which includes site admins) instead of checking the enrollment record directly.Views — Sidebar Settings and Form links are conditionally shown only to course admins. The assignment toggle switch is disabled for non-course-admins. The enrollment sync button is shown to all staff.
Tests — Updated to use valid roles (
'teacher'instead of'instructor'), removed staleallow_any_instance_ofstubs in favor of real database records, and updated the TA sync test to expect success (200) rather than forbidden (403).Testing
UserToCourserecords rather than mockeduser_rolecalls, making the tests more representative of actual behavior.Documentation
No external documentation changes required. The permission model is documented inline via comments in
Coursemodel andApplicationController.Checklist
Superconductor Ticket Implementation | App Preview | Guided Review