Reject unassociated teacher accounts in Join Code flow - #986
Open
mwtrew wants to merge 4 commits into
Open
Conversation
Also adds tests, updates the user factory to be aware of the new sub field, and updates some existing tests to take advantage of the factory.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Join Code flow to distinguish “student account” identities from “full” (teacher-expected) identities using Hydra’s sub claim, preventing unassociated teacher accounts from being enrolled via the student join path.
Changes:
- Add
User#student_account_type?(based onsub) and use it inJoinStatusServiceto return:not_a_studentfor non-student account types in the “new user” join path. - Update factories and request/service specs to model student
subvalues and cover the new behavior. - Extend
User.from_tokentest coverage to assertsubis preserved for both full and student accounts.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| app/services/join_status_service.rb | Rejects join attempts from non-student account types when the user has no role in the school yet. |
| app/models/user.rb | Adds sub to user attributes and introduces student_account_type? used by join logic. |
| spec/factories/user.rb | Sets sub for users/students so tests can model Hydra subject formats. |
| spec/services/join_status_service_spec.rb | Updates/expands coverage to assert :not_a_student for non-student account types and cross-school non-student roles. |
| spec/requests/join_controller_spec.rb | Updates auth stubbing to provide student-style Hydra sub for join flow request specs. |
| spec/models/user_spec.rb | Adds assertions that from_token preserves sub and covers #student_account_type?. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Test coverage93.43% line coverage reported by SimpleCov. |
raspberrypiherokubot
temporarily deployed
to
editor-api-p-bug-excs-s-cndzn1
August 26, 2026 13:33
Inactive
peconia
reviewed
Aug 26, 2026
zetter-rpf
approved these changes
Aug 26, 2026
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.
Also adds tests, updates the user factory to be aware of the new sub field, and updates some existing tests to take advantage of the factory.
Status
What's changed?
subfield from Hydra to prevent "full" (i.e. expected to be a teacher) accounts from erroneously going down the student add-to-class flow.