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
This commit is contained in:
Neill Magill 2018-12-10 09:27:36 +00:00
parent 003dadc64d
commit be1c2eded5
3 changed files with 30 additions and 5 deletions

View file

@ -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;
}

View file

@ -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.

View file

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