Repository navigation
Conversation
A direct message that includes a mentor (ROLE_MENTOR and no teacher or admin role) can't be started, sent or edited, whoever is sending it. Reading old messages and deleting your own still work, so the navbar bell and /dm keep answering. Refusals answer 403 with an error and a reason (mentor_no_direct_messages) a page can show its own words for. The rules live in MentorRules, a class of static methods the controllers ask with the people they already loaded.
A mentor (ROLE_MENTOR and no teacher or admin role) reads, posts and shares files only in a group they are a member of, that isn't a class group and has at least 2 members who aren't mentors. Only a member who isn't a mentor, or a teacher, adds or removes a mentor; a mentor adds no one and may only leave. A new group may start with a mentor only if its maker could have added them. Mentors can't list, search, make, rename or delete groups, change group grades, join class groups or read another person's groups. Everyone else gets the answers they had before. Refusals answer 403 with a reason. Group responses mark each member as a mentor or not. MentorAccess loads a group's members (one query, since open-in-view is off) and whether it is a class group, and asks MentorRules.
after the mentor rules were written, so a mentor could list and download any group's shared files. Both now ask MentorAccess like the other group chat routes: a mentor gets them only for a group they belong to, that isn't a class group and has at least 2 members who aren't mentors. Everyone else gets the answers they had before.
…w the rules too
A review found three more ways around the mentor rules, and one rule
that was too strict.
- The older /api/chat/{groupId} keeps its own chat file per group. A
mentor reads and posts there only where they may use the group's chat.
- The UI Builder's "message the owner" opened a direct message without
the check, so it now refuses one that would include a mentor
(mentor_no_direct_messages, 403).
- A mentor's own group list holds only the groups they may use, so no
page offers one Spring would refuse, and they don't see its members.
- A mentor may now send an empty class list, to leave every class
group. Any class is still refused.
The docs also no longer say a socket sendFile needs no sign-in: the
socket drops events without a signed-in identity, but it doesn't check
the mentor rules for one that has it.
A socket can carry a signed-in identity (a Spring /login session gives the handshake its Principal), and GroupChatWebSocketController then ran sendMessage, sendFile, joinGroup, typing and heartbeat for any group. It now drops those events when the mentor rules refuse the signed-in mentor that group, as the REST routes do. Leaving always works, and everyone else's events work as before.
GET /api/chat/{groupId} had its membership check commented out, so any
signed-in account could read any group's older chat. It now answers 403
to anyone who isn't in the group, unless they're a teacher or admin.
Posting still needs membership, as before. No page reads this route.
POST /api/chat/{groupId} checked membership before the mentor rule, so a
mentor posting to a group they aren't in got a 403 with no reason. The
mentor rule now goes first and answers mentor_not_in_group; anyone else
outside the group still gets the plain 403.
A mentor's own group list already leaves out a group Spring refuses them (a class group, or a team that dropped below 2 members who aren't mentors). The unread count still counted those groups, and marking one read is refused, so the bell kept saying "New messages in 1 group" with no way to open or clear it. MentorAccess.refusesGroup answers for one group id, and getUnread drops every group it refuses. Everyone else's count is unchanged.
The mentor check loaded the person for every group event, typing and heartbeats included, for everyone with a signed-in socket. A socket from Spring's own pages carries the roles of its sign-in, so an event from anyone that sign-in doesn't call a mentor now skips the lookup. A mentor's events still load the person and the group, through the same MentorAccess.refusesGroup the unread count uses.
…ommand The Mentors section says the unread count leaves out a group the mentor may not use, and that the socket reads the sign-in's roles first (a role given since counts from the next sign-in). The test command in the doc and AGENTS.md missed the socket and older-chat tests; *Mentor*Test runs them all.
Adding or removing a member of an existing group now needs the caller to be one of the group's members, a teacher or an admin. Outside the mentor rules, anyone may still join or leave a group that isn't a class group. Through the member routes only teachers and admins add or remove people in a class group; students join and leave theirs through the classes on their Profile. Changing a group's name, period or course is for teachers and admins. A class group keeps its name, and a new name can't be another group's or a class group's name. No group name, made or renamed, can contain "/". Deleting is admin-only and never a class group, the same rule the Messages page uses to show Delete.
svaka2000
force-pushed
the
fix/group-membership-checks
branch
from
November 26, 2026 05:42
d5b8913 to
7ecc349
Compare
This was referenced Nov 26, 2026
Contributor
Author
|
Combined into #315 with the same commits. |
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.
This builds on #303 (mentors) and uses its
findMembersOfandisClassGroup, so it should merge after that one. Until then GitHub shows #303's commits here too.Adding or removing a member of an existing group, editing a group and deleting one now check who is asking. A class group is CSSE, CSP, CSA or CSH, whose members come from the classes on each student's Profile.
POSTandDELETE /api/groups/{id}/members/{personId}, only teachers and admins add or remove people in a class group. Students join and leave theirs through the classes on their Profile.PUT /api/groups/{id}) is for teachers and admins. Members can't, because anyone can join a group that isn't a class group and then counts as a member. No page in pages calls this route.reason.Other notes:
PUT /api/groups/{id}before its member changes, so only teachers and admins can save there now. On Group Management, Add Group Member and Remove from Group work for a group's members (not in a class group), teachers and admins, and Delete only for admins, never on a class group.GroupMembersMentorTestI renamedstudentsStillAddStudentsAsBeforetomembersStillAddStudentsAsBefore. It now signs in a team member, because someone outside a group can't add a person to it. I also updated Mentors: no direct messages, and only the groups they're added to #303's Mentors line inAGENTS.md, which said everyone else keeps the old answers.permissions.jsondoesn't change, because the checks are inside the handlers.GroupMembershipAccessTestand a line inAGENTS.md. The full suite has the same 14 errors as master (12 inPersonCapstoneApprovalRouteTest, 2 inImportPersonPasswordTest) and nothing else.How to try it:
./mvnw test -Dtest='GroupMembershipAccessTest,GroupMembersMentorTest'./dm: join a group from Find a group, add and remove people as a member, and leave.