From ff4f2c02efa15b71aff09f173ee5de91c24622f3 Mon Sep 17 00:00:00 2001 From: Leon Stringer Date: Mon, 20 Jan 2025 17:34:08 +0000 Subject: [PATCH] MDL-83195 mod_assign: Individual grade release Fix pushing individual grades into the gradebook (as opposed to the batch release of grades) when "Allow partial release of grades while marking anonymously" is enabled. This change reworks MDL-73626's fix for the same issue for releasing multiple grades in a batch operation. --- mod/assign/lang/en/assign.php | 3 ++- mod/assign/locallib.php | 26 +++++++++++++++----------- mod/assign/tests/locallib_test.php | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index 8d3da83a9b360..2e58f166e92ee 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -118,7 +118,8 @@ $string['batchsetmarkingworkflowstateforusers'] = 'Set marking workflow state for {$a} selected user(s).'; $string['beginassignment'] = 'Begin assignment'; $string['blindmarking'] = 'Anonymous submissions'; -$string['blindmarkingenabledwarning'] = 'Anonymous submissions are enabled for this activity. Grades will not be added to the gradebook until student identities are revealed via the grading action menu.'; +$string['blindmarkingenabledwarning'] = 'Anonymous submissions are enabled for this activity.'; +$string['blindmarkingnogradewarning'] = 'Anonymous submissions are enabled for this activity. Grades will not be added to the gradebook until student identities are revealed via the grading action menu.'; $string['blindmarking_help'] = 'Anonymous submissions hide the identity of students from markers. Anonymous submission settings will be locked once a submission or grade has been made in relation to this assignment.'; $string['cachedef_overrides'] = 'User and group override information'; $string['calendardue'] = '{$a} is due'; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index c3d59f642025a..d3d327f20a16f 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4572,7 +4572,11 @@ protected function view_grading_table() { } if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) { - $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage'); + if ($this->is_marking_anonymous()) { + $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage'); + } else { + $o .= $this->get_renderer()->notification(get_string('blindmarkingnogradewarning', 'assign'), 'notifymessage'); + } } // Load and print the table of submissions. @@ -6012,7 +6016,7 @@ protected function gradebook_item_update($submission=null, $grade=null) { require_once($CFG->dirroot.'/mod/assign/lib.php'); // Do not push grade to gradebook if blind marking is active as // the gradebook would reveal the students. - if ($this->is_blind_marking()) { + if ($this->is_blind_marking() && !$this->is_marking_anonymous()) { return false; } @@ -8386,15 +8390,6 @@ protected function process_set_batch_marking_workflow_state() { $grade->feedbackfiles = $plugin->files_for_gradebook($grade); } $this->update_grade($grade); - $assign = clone $this->get_instance(); - $assign->cmidnumber = $this->get_course_module()->idnumber; - // Set assign gradebook feedback plugin status. - $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); - - // If markinganonymous is enabled then allow to release grades anonymously. - if (isset($assign->markinganonymous) && $assign->markinganonymous == 1) { - assign_update_grades($assign, $userid); - } $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger(); } @@ -9697,6 +9692,15 @@ public function is_attempt_in_progress(?int $userid = null, int $groupid = 0, in return !empty($submission) && $submission->status !== ASSIGN_SUBMISSION_STATUS_SUBMITTED && $timedattemptstarted; } + + /** + * Is "Allow partial release of grades while marking anonymously" enabled? + * + * @return bool + */ + public function is_marking_anonymous(): bool { + return isset($this->get_instance()->markinganonymous) && $this->get_instance()->markinganonymous; + } } /** diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index a8e7f6fa45174..16d4a6fbe2f9a 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -4626,4 +4626,31 @@ public function test_is_userid_filtered(): void { $this->AssertTrue($assign->is_userid_filtered($student1->id)); $this->AssertTrue($assign->is_userid_filtered($student2->id)); } + + /** + * Test that assignment grades are pushed to the gradebook when anonymous + * submissions and marking workflow are enabled (MDL-83195). + * @covers \assign::gradebook_item_update + */ + public function test_release_grade_anon(): void { + $this->resetAfterTest(); + $course = $this->getDataGenerator()->create_course(); + $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + $assign = $this->create_instance($course, [ + 'blindmarking' => 1, + 'markingworkflow' => 1, + 'markinganonymous' => 1, + ]); + + // Add a grade and change the workflow status to "Released". + $this->mark_submission($teacher, $assign, $student, 50.0, [ + 'workflowstate' => ASSIGN_MARKING_WORKFLOW_STATE_RELEASED, + ]); + + // Make sure the grade has been pushed to the gradebook. + $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $assign->get_instance()->id, $student->id); + $this->assertEquals(50, (int)$gradinginfo->items[0]->grades[$student->id]->grade); + } }