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() {