Grant teachers access to project context on student remix projects#889
Open
DNR500 wants to merge 1 commit into
Open
Grant teachers access to project context on student remix projects#889DNR500 wants to merge 1 commit into
DNR500 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the existing Cancancan authorization for school teachers so they can load project context (GET /api/projects/:identifier/context) for student remix projects they’re already allowed to read, fixing a 403 on cold loads after re-login.
Changes:
- Add
show_contextpermission to the teacher “read student remix” rule inAbility. - Expand
Abilityspecs to covershow_contextfor remix access (allowed for lesson owner/co-teacher, denied otherwise). - Add a request spec verifying teachers can successfully fetch context JSON for a student remix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/models/ability.rb | Grants teachers show_context on student remixes derived from lesson projects they teach. |
| spec/models/ability_spec.rb | Adds assertions that show_context matches existing remix read authorization behavior. |
| spec/requests/projects/show_context_spec.rb | Verifies the /context endpoint returns 200 and expected context JSON for a teacher viewing a student remix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) | ||
| ).pluck(:id) | ||
| can(%i[read], Project, remixed_from_id: teacher_project_ids) | ||
| can(%i[read show_context], Project, remixed_from_id: teacher_project_ids) |
Contributor
There was a problem hiding this comment.
I think this might apply.
Test coverage91.86% line coverage reported by SimpleCov. |
abcampo-iry
approved these changes
Jun 24, 2026
abcampo-iry
left a comment
Contributor
There was a problem hiding this comment.
Looks good, please have a look at the comment
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.
Fixes the problem described in issue 1522
Summary
Teachers can already read student remixes for lessons they teach, but were denied access to
GET /api/projects/:identifier/contexton those remix URLs. This PR addsshow_contextto the existing teacher remix read rule so a teacher reopening a saved link to a student's project gets full lesson/class/school context after re-login.Problem
When a teacher opens a saved link to a student's project (the remix identifier, e.g.
/school/project/{student-remix-id}) in a new session:GET /api/projects/{id}succeeds (teacher can read the remix)GET /api/projects/{id}/contextreturns 403Student remix rows have
lesson_id: niland point at the lesson template viaremixed_from_id. The context endpoint resolves lesson and class from the parent project (context.json.jbuilder), but teachers only hadreadon remixes - notshow_context.Without context, editor-standalone cannot load the lesson, detect "teacher viewing student work", or enter view-only mode on a cold load.
Solution
Add
show_contextto the same rule teachers already use to read student remixes:No change to the context response shape or jbuilder -
context.json.jbuilderalready resolveslesson_idandclass_idfrom@project.parent&.lesson.No new security boundary: teachers who can read a student remix (lesson owner or co-teacher of the class) can now load the context needed to display it. Teachers not in the class remain denied.
Changes
app/models/ability.rbshow_contextto teacher remix project rulespec/models/ability_spec.rbshow_contextallowed for lesson owner and co-teacher; denied for teacher not in classspec/requests/projects/show_context_spec.rbGET …/contexton student remix returns 200 with full JSONTest plan
bundle exec rspec spec/models/ability_spec.rb -e "remix of a teacher"bundle exec rspec spec/requests/projects/show_context_spec.rbGET /api/projects/{student-remix-id}/contextreturns 200school_id,lesson_id,class_id