From dbcfda9641f6bd66c2d41425630978ba29c0076f Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Mon, 10 Dec 2018 09:27:36 +0000 Subject: [PATCH] MDL-64336 assign: Submissions should be visible while frozen Before this change if a student visited an assignment that is frozen they would only see the title and description even if they had made a submission to it. After the change they will be able to see the status of their submission and any feedback and grades they have recived. It will also make the Moodle app recognise that submission should not happen because the assignment is frozen. Tests based on ones created by Andrew Nicols --- mod/assign/externallib.php | 5 +++-- mod/assign/locallib.php | 11 ++++++++--- mod/assign/tests/locallib_test.php | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 49320c76680..c2290d46982 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -2375,7 +2375,8 @@ class mod_assign_external extends external_api { } // Retrieve the rest of the renderable objects. - if (has_capability('mod/assign:submit', $assign->get_context(), $user)) { + $cansubmit = has_capability('mod/assign:submit', $context, $user, false); + if ($cansubmit || $assign->get_user_submission($user->id, false) !== false) { $lastattempt = $assign->get_assign_submission_status_renderable($user, true); } @@ -2431,7 +2432,7 @@ class mod_assign_external extends external_api { } // Can edit its own submission? - $lastattempt->caneditowner = $assign->submissions_open($user->id) && $assign->is_any_submission_plugin_enabled(); + $lastattempt->caneditowner = $cansubmit && $assign->submissions_open($user->id) && $assign->is_any_submission_plugin_enabled(); $result['lastattempt'] = $lastattempt; } diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 38dbb836cea..4292a4cfce4 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4867,7 +4867,7 @@ class assign { if (has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) { return true; } - if ($userid == $USER->id && has_capability('mod/assign:submit', $this->context)) { + if ($userid == $USER->id) { return true; } return false; @@ -5438,8 +5438,9 @@ class assign { $o = ''; if ($this->can_view_submission($user->id)) { - - if (has_capability('mod/assign:submit', $this->get_context(), $user, false)) { + $cansubmit = has_capability('mod/assign:submit', $this->get_context(), $user, false); + if ($cansubmit || $this->get_user_submission($user->id, false) !== false) { + // The user can submit, or has a submission. $submissionstatus = $this->get_assign_submission_status_renderable($user, $showlinks); $o .= $this->get_renderer()->render($submissionstatus); } @@ -5468,6 +5469,10 @@ class assign { * @return bool */ protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null) { + if (!has_capability('mod/assign:submit', $this->get_context(), $userid, false)) { + // The user does not have the capability to submit. + return false; + } if ($teamsubmission) { if ($teamsubmission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) { // The assignment submission has been completed. diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 173ed88d21d..d11abd0c647 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -2329,6 +2329,25 @@ class mod_assign_locallib_testcase extends advanced_testcase { $this->setUser($student); $output = $assign->view_student_summary($student, true); $this->assertNotRegexp('/Feedback/', $output, 'Do not show feedback if the grade is hidden in the gradebook'); + + // Freeze the context. + $this->setAdminUser(); + $context = $assign->get_context(); + $CFG->contextlocking = true; + $context->set_locked(true); + + // No feedback should be available because the grade is hidden. + $this->setUser($student); + $output = $assign->view_student_summary($student, true); + $this->assertNotRegexp('/Feedback/', $output, 'Do not show feedback if the grade is hidden in the gradebook'); + + // Show the feedback again - it should still be visible even in a frozen context. + $this->setUser($teacher); + $gradeitem->set_hidden(0, false); + + $this->setUser($student); + $output = $assign->view_student_summary($student, true); + $this->assertRegexp('/Feedback/', $output, 'Show feedback if there is a grade'); } public function test_show_student_summary_with_feedback() {