Merge branch 'MDL-66113-master' of git://github.com/jleyva/moodle
authorSara Arjona <sara@moodle.com>
Tue, 17 Sep 2019 10:03:42 +0000 (12:03 +0200)
committerSara Arjona <sara@moodle.com>
Tue, 17 Sep 2019 10:03:42 +0000 (12:03 +0200)
mod/assign/externallib.php
mod/assign/tests/externallib_test.php

index 2da9021..68b17d1 100644 (file)
@@ -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.
index 89cd0fd..8994bdf 100644 (file)
@@ -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.
      *