From bec8c1a664ad65d6ef4b673d28325a20bea82b99 Mon Sep 17 00:00:00 2001 From: Leon Stringer Date: Mon, 20 Jan 2025 17:24:33 +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 e5b0c553ffb80..671672f0eae19 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -145,7 +145,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 "Actions" 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 "Actions" 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 7dc4c7ccdf402..480cd6be838b9 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4580,7 +4580,11 @@ protected function view_grading_table() { $o .= $actionformtext; 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'); + } } // Print the table of submissions. @@ -6031,7 +6035,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; } @@ -8381,15 +8385,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(); } @@ -9710,6 +9705,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 18c33186707fb..aa409b3313e30 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -4816,4 +4816,31 @@ public function test_get_error_messages(): void { $this->assertIsArray($result); $this->assertNotEmpty($result); } + + /** + * 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); + } }