Skip to content

Commit

Permalink
MDL-83195 mod_assign: Individual grade release
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leonstr committed Dec 3, 2024
1 parent a8b2acd commit 28a874e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
20 changes: 10 additions & 10 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6035,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;
}

Expand Down Expand Up @@ -8385,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();
}
Expand Down Expand Up @@ -9714,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;
}
}

/**
Expand Down
27 changes: 27 additions & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 28a874e

Please sign in to comment.