MDL-59160 core_group: Return if the user can access all groups in WS
authorJuan Leyva <juanleyvadelgado@gmail.com>
Thu, 8 Jun 2017 12:04:10 +0000 (13:04 +0100)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Mon, 19 Jun 2017 14:53:38 +0000 (15:53 +0100)
The core_group_get_activity_allowed_groups WS should be returning not
only the groups but also if the user is allowed to access all the
activity groups.

group/externallib.php
group/tests/externallib_test.php
lib/upgrade.txt

index 5359a37..c3d2530 100644 (file)
@@ -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(),
             )
         );
index 97a6cf9..dcbb0ef 100644 (file)
@@ -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']);
     }
 
     /**
index 09c2839..0044bd3 100644 (file)
@@ -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 ===