diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 6924aad7e0b96..32c3e5597c1f5 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -2316,7 +2316,7 @@ public static function get_submission_status_parameters() { 'assignid' => new external_value(PARAM_INT, 'assignment instance id'), 'userid' => new external_value(PARAM_INT, 'user id (empty for current user)', VALUE_DEFAULT, 0), 'groupid' => new external_value(PARAM_INT, 'filter by users in group (used for generating the grading summary). - Empty or 0 for all groups information.', VALUE_DEFAULT, 0), + 0 for all groups information, any other empty value will calculate currrent group.', VALUE_DEFAULT, 0), ) ); } @@ -2368,8 +2368,9 @@ public static function get_submission_status($assignid, $userid = 0, $groupid = throw new moodle_exception('notingroup'); } } else { - // A null gorups means that following functions will calculate the current group. - $groupid = null; + // A null group means that following functions will calculate the current group. + // A groupid set to 0 means all groups. + $groupid = ($params['groupid'] == 0) ? 0 : null; } if ($assign->can_view_grades($groupid)) { $gradingsummary = $assign->get_assign_grading_summary_renderable($groupid); diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index c038b55fa7359..a152bbd768a88 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -2133,6 +2133,7 @@ public function test_get_submission_status_in_submission_status() { * Test get_submission_status using the teacher role. */ public function test_get_submission_status_in_submission_status_for_teacher() { + global $DB; $this->resetAfterTest(true); list($assign, $instance, $student1, $student2, $teacher, $g1, $g2) = $this->create_submission_for_testing_status(true); @@ -2166,11 +2167,22 @@ public function test_get_submission_status_in_submission_status_for_teacher() { $this->assertEquals(0, $result['gradingsummary']['submissionssubmittedcount']); // G2 students didn't submit yet. $this->assertEquals(0, $result['gradingsummary']['submissionsneedgradingcount']); // G2 students didn't submit yet. - // Should return also 1 participant if we allow the function to auto-select the group. + // Should not return information for all users (missing access to all groups capability for non-editing teacher). $result = mod_assign_external::get_submission_status($assign->get_instance()->id); $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result); $this->assertCount(0, $result['warnings']); - $this->assertEquals(1, $result['gradingsummary']['participantcount']); + $this->assertFalse(isset($result['gradingsummary'])); + + // Should return all participants if we grant accessallgroups capability to the normal teacher role. + $context = context_course::instance($assign->get_instance()->course); + $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); + assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id, true); + accesslib_clear_all_caches_for_unit_testing(); + + $result = mod_assign_external::get_submission_status($assign->get_instance()->id); + $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result); + $this->assertCount(0, $result['warnings']); + $this->assertEquals(2, $result['gradingsummary']['participantcount']); $this->assertEquals(0, $result['gradingsummary']['submissiondraftscount']); $this->assertEquals(1, $result['gradingsummary']['submissionssubmittedcount']); // One student from G1 submitted. $this->assertEquals(1, $result['gradingsummary']['submissionsneedgradingcount']); // One student from G1 submitted.