diff --git a/group/externallib.php b/group/externallib.php index 5359a373f17..c3d25304e1e 100644 --- a/group/externallib.php +++ b/group/externallib.php @@ -1386,6 +1386,7 @@ class core_group_external extends external_api { $results = array( 'groups' => $usergroups, + 'canaccessallgroups' => has_capability('moodle/site:accessallgroups', $context, $user), 'warnings' => $warnings ); return $results; @@ -1401,6 +1402,8 @@ class core_group_external extends external_api { return new external_single_structure( array( 'groups' => new external_multiple_structure(self::group_description()), + 'canaccessallgroups' => new external_value(PARAM_BOOL, + 'Whether the user will be able to access all the activity groups.', VALUE_OPTIONAL), 'warnings' => new external_warnings(), ) ); diff --git a/group/tests/externallib_test.php b/group/tests/externallib_test.php index 97a6cf93184..dcbb0ef2742 100644 --- a/group/tests/externallib_test.php +++ b/group/tests/externallib_test.php @@ -523,6 +523,7 @@ class core_group_externallib_testcase extends externallib_advanced_testcase { $groups = core_group_external::get_activity_allowed_groups($cm1->id); $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups); $this->assertCount(2, $groups['groups']); + $this->assertFalse($groups['canaccessallgroups']); foreach ($groups['groups'] as $group) { if ($group['name'] == $group1data['name']) { @@ -539,12 +540,21 @@ class core_group_externallib_testcase extends externallib_advanced_testcase { $groups = core_group_external::get_activity_allowed_groups($cm1->id, $student->id); $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups); $this->assertCount(2, $groups['groups']); + // We are checking the $student passed as parameter so this will return false. + $this->assertFalse($groups['canaccessallgroups']); // Check warnings. Trying to get groups for a user not enrolled in course. $groups = core_group_external::get_activity_allowed_groups($cm1->id, $otherstudent->id); $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups); $this->assertCount(1, $groups['warnings']); + $this->assertFalse($groups['canaccessallgroups']); + // Checking teacher groups. + $groups = core_group_external::get_activity_allowed_groups($cm1->id); + $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups); + $this->assertCount(2, $groups['groups']); + // Teachers by default can access all groups. + $this->assertTrue($groups['canaccessallgroups']); } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 09c2839f65e..0044bd34e54 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -10,6 +10,8 @@ information provided here is intended especially for developers. * Removed accesslib private functions: load_course_context(), load_role_access_by_context(), dedupe_user_access() (MDL-49398). * Internal "accessdata" structure format has changed to improve ability to perform role definition caching (MDL-49398). * Role definitions are no longer cached in user session (MDL-49398). +* External function core_group_external::get_activity_allowed_groups now returns an additional field: canaccessallgroups. + It indicates whether the user will be able to access all the activity groups. === 3.3.1 ===