$results = array(
'groups' => $usergroups,
+ 'canaccessallgroups' => has_capability('moodle/site:accessallgroups', $context, $user),
'warnings' => $warnings
);
return $results;
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(),
)
);
$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']) {
$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']);
}
/**
* 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 ===