fix: Add Subjects to School button is missing for OPS user in Teacher mode#4734
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a list of roles authorized to modify subjects (SUBJECT_MODIFICATION_ROLES) and updates the permission check in SubjectSelection.tsx to allow users with these roles to perform modifications. The review feedback points out a potential runtime error where roles might be undefined or null, and suggests using optional chaining (roles?.includes(role)) to prevent a TypeError.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const hasSubjectModificationRole = SUBJECT_MODIFICATION_ROLES.some((role) => | ||
| roles.includes(role), | ||
| ); |
There was a problem hiding this comment.
Using roles.includes(role) directly can throw a TypeError if roles is undefined or null. Since roles is retrieved from the Redux store and might not be immediately available (as indicated by the defensive check const userRoles = roles || [] on line 99), we should use optional chaining roles?.includes(role) to prevent potential runtime crashes.
| const hasSubjectModificationRole = SUBJECT_MODIFICATION_ROLES.some((role) => | |
| roles.includes(role), | |
| ); | |
| const hasSubjectModificationRole = SUBJECT_MODIFICATION_ROLES.some((role) => | |
| roles?.includes(role), | |
| ); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac39df6919
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| setCanModify( | ||
| schoolMatches && | ||
| (normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole), |
There was a problem hiding this comment.
Allow ops roles to bypass school matching
When an ops user opens a school's subjects from the school list, DetailList.handleSubjectIconClick navigates with only { schoolId } and does not update Util.getCurrentSchool(). If the user previously had another school selected, currentSchool.id becomes the target school after the fetch while selectedSchoolId remains stale, so this schoolMatches && ... gate still hides the Add button even though hasSubjectModificationRole is true. I inspected the ManageSchools/DetailList flow; this keeps the button missing for ops users browsing a different school than the one currently stored.
Useful? React with 👍 / 👎.
No description provided.