Skip to content

Group grades: only teachers, admins and the group's graders change them - #310

Closed
svaka2000 wants to merge 12 commits into
Open-Coding-Society:masterfrom
svaka2000:fix/group-grades-check
Closed

svaka2000 wants to merge 12 commits into
Open-Coding-Society:masterfrom
svaka2000:fix/group-grades-check

Conversation

@svaka2000

Copy link
Copy Markdown
Contributor

This builds on #309 (member checks), which builds on #303 (mentor rules), so it merges after both. Until then GitHub shows their commits here too.

A group's grades are a list on the group (gradesJson), with one entry per assignment. /api/groups/{id}/grades now checks who is asking before it changes them.

  • Replacing (PUT) or clearing (DELETE) a group's grades is for teachers and admins, because both change every assignment's entry at once.
  • Adding or replacing one assignment's entry (POST) also copies it into each member's own grades. That's for teachers, admins and whoever grades the group on that assignment: the assignment's creators and assigned graders, and the graders of the group's submission to it.
  • An entry whose assignmentId is missing or isn't a whole number is for teachers and admins only, since there's no assignment to check.
  • Any other signed-in account gets 403, and nothing is saved. Mentors are still refused first, by Mentors: no direct messages, and only the groups they're added to #303's mentor rule.
  • Reading a group's grades (GET) doesn't change.

Other notes:

  • Nothing in the pages repo, or in Spring's own templates and scripts, calls these routes.
  • permissions.json doesn't change, because the checks are inside the handlers.
  • I added GroupGradesAccessTest and a line in AGENTS.md. The full suite has the same 14 errors as master (12 in PersonCapstoneApprovalRouteTest, 2 in ImportPersonPasswordTest) and nothing else.
  • I ran Spring locally and used curl. A teacher replaced, added to and cleared a group's grades, and a student in the group got 403 on all three.

How to try it:

  1. Run ./mvnw test -Dtest='GroupGradesAccessTest,GroupMembersMentorTest'.

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.
Replacing or clearing a group's grades (PUT and DELETE
/api/groups/{id}/grades) is for teachers and admins, since that
changes every assignment's entry at once. Adding one assignment's
entry (POST), which also copies it into each member's own grades, is
for them and for whoever grades the group on that assignment: its
creators and graders, and the graders of the group's submission to
it. Mentors still get the mentor refusal first.
@svaka2000

Copy link
Copy Markdown
Contributor Author

Combined into #315 with the same commits.

@svaka2000 svaka2000 closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant