From be1c2eded5e5d310241ee4a0cfd08cd12aaab086 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 51886299d59..dd022601ad9 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 c86f7b5b0a3..2c56a03e27c 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4868,7 +4868,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; @@ -5441,8 +5441,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); } @@ -5471,6 +5472,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 9cd16757fad..7bc534c2a1f 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -2345,6 +2345,25 @@ class mod_assign_locallib_testcase extends advanced_testcase { $output = $assign->view_student_summary($student, true); $this->assertDoesNotMatchRegularExpression('/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->assertDoesNotMatchRegularExpression('/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->assertMatchesRegularExpression('/Feedback/', $output, 'Show feedback if there is a grade'); } public function test_show_student_summary_with_feedback() {