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.
This was referenced Nov 26, 2026
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.
svaka2000
added a commit
to svaka2000/Spring-JJ
that referenced
this pull request
Nov 26, 2026
…or's types GroupChatSendTest built GroupChatApiController, GroupChatRealtimeService and GroupChatReadService by naming their constructors. Open PRs add constructor dependencies to the controller and the realtime service (Open-Coding-Society#302 a MessageReactionService, Open-Coding-Society#303 a MentorAccess), so once one of them and this test were both on master, the tests would stop compiling, with no merge conflict to show it. TestBeans builds a class through its biggest constructor: each parameter gets the first object the test passes that fits it, and a Mockito mock otherwise. The test then keeps compiling and running whatever dependencies those classes gain.
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.
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.
Mentors (accounts with ROLE_MENTOR and no teacher or admin role) can't reach students privately through Spring's chat routes anymore. Spring checks this itself, so no page can get around it.
/api/chat/{groupId}, the UI Builder's "message the owner", and group events from a signed-in chat socket follow the same rules./api/chat/{groupId}also checks membership again, for everyone: only a group's members, teachers and admins read it. Its check had been commented out, and no page reads this route."mentor": trueorfalse, so a page can show a team's mentors.reason(likementor_no_direct_messages) so a page can say why in its own words. Bulk group creation lists a refused group undererrorsinstead.How it fits with Darshan's work:
Other notes:
MentorRules(mvc/groups), andMentorAccessloads a group's members for them. The socket check reads roles from the socket's sign-in first, so only a mentor's events are looked up in the database.permissions.jsondoesn't change. The checks are inside the handlers, and the RBAC README says those stay in code.docs/group-chat-architecture.mdhas a Mentors section listing every route, andAGENTS.mdhas a line about it.MentorRulesTest,DirectMessageMentorTest,GroupChatMentorTest,GroupMembersMentorTest,GroupChatSocketMentorTestandLegacyChatMentorTest, plus one inUiBuilderPageServiceTest../mvnw testpasses except the 12PersonCapstoneApprovalRouteTesterrors that master has too (noCallsPropertiesbean).GroupChatApiController. Whichever of the two merges second keeps both arguments and adds the mentor check to the reaction routes.How to try it:
roles_jsonto["ROLE_USER","ROLE_MENTOR"]in thepersontable, and sign in withPOST /authenticate(signing in through the site asks Flask, which can take a hand-set role away).POST /api/dm/conversationswith{"otherPersonIds": [<a student's id>]}: 403mentor_no_direct_messages.POST /api/groups/{id}/members/{mentorId}. As the mentor,GET /api/groups/chat/{id}/messagesworks. Have the other student leave, and the mentor gets 403mentor_team_too_small.