diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 2da9021b80d..68b17d18975 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -2350,6 +2350,8 @@ class mod_assign_external extends external_api { throw new required_capability_exception($context, 'mod/assign:viewgrades', 'nopermission', ''); } + $assign->update_effective_access($user->id); + $gradingsummary = $lastattempt = $feedback = $previousattempts = null; // Get the renderable since it contais all the info we need. diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index 89cd0fd16e8..8994bdfd7eb 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -2228,6 +2228,65 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $this->assertEquals($teacher->id, $result['feedback']['grade']['grader']); } + /** + * Test get_submission_status with override for student. + */ + public function test_get_submission_status_with_override() { + global $DB; + + $this->resetAfterTest(true); + + list($assign, $instance, $student1, $student2, $teacher, $g1, $g2) = $this->create_submission_for_testing_status(); + + $overridedata = new \stdClass(); + $overridedata->assignid = $assign->get_instance()->id; + $overridedata->userid = $student1->id; + $overridedata->allowsubmissionsfromdate = time() + YEARSECS; + $DB->insert_record('assign_overrides', $overridedata); + + $result = mod_assign_external::get_submission_status($assign->get_instance()->id); + // We expect debugging because of the $PAGE object, this won't happen in a normal WS request. + $this->assertDebuggingCalled(); + $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result); + + $this->assertCount(0, $result['warnings']); + $this->assertFalse(isset($result['gradingsummary'])); + $this->assertFalse(isset($result['feedback'])); + $this->assertFalse(isset($result['previousattempts'])); + + $this->assertTrue($result['lastattempt']['submissionsenabled']); + $this->assertFalse($result['lastattempt']['canedit']); // False because of override. + $this->assertFalse($result['lastattempt']['cansubmit']); + $this->assertFalse($result['lastattempt']['locked']); + $this->assertFalse($result['lastattempt']['graded']); + $this->assertEmpty($result['lastattempt']['extensionduedate']); + $this->assertFalse($result['lastattempt']['blindmarking']); + $this->assertCount(0, $result['lastattempt']['submissiongroupmemberswhoneedtosubmit']); + $this->assertEquals('notgraded', $result['lastattempt']['gradingstatus']); + + // Same assignment but user without override. + $this->setUser($student2); + + $result = mod_assign_external::get_submission_status($assign->get_instance()->id); + $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result); + + // The submission is now in draft mode. + $this->assertCount(0, $result['warnings']); + $this->assertFalse(isset($result['gradingsummary'])); + $this->assertFalse(isset($result['feedback'])); + $this->assertFalse(isset($result['previousattempts'])); + + $this->assertTrue($result['lastattempt']['submissionsenabled']); + $this->assertTrue($result['lastattempt']['canedit']); // True because there is not override for this user. + $this->assertFalse($result['lastattempt']['cansubmit']); + $this->assertFalse($result['lastattempt']['locked']); + $this->assertFalse($result['lastattempt']['graded']); + $this->assertEmpty($result['lastattempt']['extensionduedate']); + $this->assertFalse($result['lastattempt']['blindmarking']); + $this->assertCount(0, $result['lastattempt']['submissiongroupmemberswhoneedtosubmit']); + $this->assertEquals('notgraded', $result['lastattempt']['gradingstatus']); + } + /** * get_participant should throw an excaption if the requested assignment doesn't exist. *