From f2a6b9cac957cfd3fe85f691b434bd5440e533e0 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 16 Mar 2017 20:28:50 +0800 Subject: [PATCH] MDL-58278 mod_assign: Ignore send notify with mw When marking workflow is on and the grade is not released we never send notifications anyway. Instead of preventing the grading form from submitting (validation error) we silently ignore it. --- mod/assign/gradeform.php | 5 ----- mod/assign/locallib.php | 8 ++++++++ mod/assign/tests/locallib_test.php | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mod/assign/gradeform.php b/mod/assign/gradeform.php index 36c2737785d..d2980840c25 100644 --- a/mod/assign/gradeform.php +++ b/mod/assign/gradeform.php @@ -78,11 +78,6 @@ class mod_assign_grade_form extends moodleform { $errors = parent::validation($data, $files); $instance = $this->assignment->get_instance(); - if ($instance->markingworkflow && !empty($data['sendstudentnotifications']) && - $data['workflowstate'] != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { - $errors['workflowstate'] = get_string('studentnotificationworkflowstateerror', 'assign'); - } - // Advanced grading. if (!array_key_exists('grade', $data)) { return $errors; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 8ad4244dd7f..bc34932805f 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -7736,6 +7736,14 @@ class assign { $feedbackmodified) { $this->update_grade($grade, !empty($formdata->addattempt)); } + + // We never send notifications if we have marking workflow and the grade is not released. + if ($this->get_instance()->markingworkflow && + isset($formdata->workflowstate) && + $formdata->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { + $formdata->sendstudentnotifications = false; + } + // Note the default if not provided for this option is true (e.g. webservices). // This is for backwards compatibility. if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) { diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index de14bfcc712..fac227384ff 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -1244,10 +1244,12 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase { $data->grade = '50.0'; // This student will not receive notification. + $data->sendstudentnotifications = 1; $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); // This student will receive notification. + $data->sendstudentnotifications = 1; $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_RELEASED; $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0);