Repository navigation
Assignments: Let teachers follow an assignment to receive learner comment e-mails - #9282
Merged
ywarnier merged 3 commits intoOct 20, 2026
Merged
Conversation
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.
Fixes #1407
Problem
When a learner commented on their own submission on the legacy page (
main/work/view.php), every teacher of the course (or every coach of the session) got an e-mail, including teachers who had nothing to do with that assignment. The only way out was the course-wide settingemail_to_teachers_on_new_work_feedback(cf2bd42, 2017), which turns the e-mails off for everybody. Comments posted from the newer Vue/API assignment screens notified no teacher at all.What this PR does
Following an assignment is now a per-teacher choice, stored in its own table, and both comment paths use one shared service.
New table
c_student_publication_follow(id,publication_id→c_student_publication.iid,user_id→user.id,created_at). It has a unique key on (publication, user) andON DELETE CASCADEon both foreign keys. It comes with the entityCStudentPublicationFollowandCStudentPublicationFollowRepository.c_student_publication_rel_useris deliberately not reused: it lists the users an assignment is restricted to, and mixing both meanings would change who can see restricted assignments.One notification path:
AssignmentFeedbackNotifier.addWorkComment()(work.lib.php) andCreateStudentPublicationCommentActioncall it when a learner comments.MessageManager::send_message_simple(), so the inbox message and e-mail behave as they always did.cid.Master switch is kept.
email_to_teachers_on_new_work_feedbackstill decides whether anyone is told: when it is not1, nobody is e-mailed, whatever they follow. This reads the setting exactly the way the legacy1 != api_get_course_setting(...)check did.The creator follows automatically on every creation path:
addDir()(work.php)POST /api/c_student_publications(CStudentPublicationPostStateProcessor, top-level folders only)McpCourseAssignmentCreatorThe creator can unfollow like anyone else.
Endpoints (in
StudentPublicationController, under/assignments):GET /assignments/{id}/follow: returns{following: bool}POST /assignments/{id}/follow: followDELETE /assignments/{id}/follow: unfollowAccess:
EDITvote on the assignment's resource node (ResourceNodeVoter).sidonly: they must be the course coach of the request's course (cid) in that session, or its general coach; the session must hold the course; and the assignment must be available in that session (a base-course link, or a link to that very session). This check lives in the smallAssignmentSessionCoachAccessservice, which reloads the course and session by id and uses the existingSession::hasCourse(),hasCourseCoachInCourse()andhasUserAsGeneralCoach()helpers.ResourceNodeVoteritself is unchanged: it still refuses coaches the right to edit base-course assignments.UserHelper::getCurrent()and is never read from the client.CsrfProtectionListener(Origin / Sec-Fetch checks).UI
AssignmentDetail.vue(teacher toolbar, also shown to session coaches): a Follow / Following toggle (bell-off-outline/bell). It stays hidden until the state is loaded and is never shown to learners.work_list_all.php(still linked from LP, view.php and others): anActionIcon::EMAIL_OFF/EMAIL_ONtoggle, the same icons the wiki uses for "Notify me". Clicking it calls the same POST/DELETE endpoint, so no new legacy handler or token was added.messages.pot,messages.en_US.poanden_US.json. "Follow" already existed in the catalogs and was added toen_US.json.Release note
Migration note (existing assignments)
V310/Version20261020120000creates the table. It also makes the creator of each existing assignment (theuser_idof every top-levelfolderrow whose user still exists) a follower, so that behaviour does not silently change to "no e-mails" after the upgrade.Trade-off: before this PR every course teacher was told. After the upgrade only the creator is, and co-teachers must click Follow on the assignments they care about. That is what the issue asks for (no more unwanted e-mails), but co-teachers who relied on the old e-mails will stop getting them until they opt in. The alternative was to make every current course teacher a follower of every existing assignment. That keeps the old behaviour exactly, but it also keeps the unwanted e-mails the issue complains about.
down()drops the table.How to test
php bin/console doctrine:migrations:migrate. Check thatc_student_publication_followexists and has one row per existing assignment creator.main/work/view.php). The teachers showing Following receive the "There's a new feedback in work" message/e-mail, and the others do not.?cid={cid}&sid={sid}): the toolbar shows Follow, and following works. A learner of that session commenting on their submission e-mails the coach. A coach of another session gets 403 when callingPOST /assignments/{id}/follow?cid={cid}&sid={sid}for that session, and is not e-mailed about comments made in it.POST /assignments/{id}/follow?cid={cid}: you get 403. A teacher of another course gets 403 too.Automated:
Documentation
A draft for the docs repository is attached separately (
3.x/en/teacher-guide/assessing-learners/assignments.md, new section "Following an Assignment"). It is not part of this PR's code.