MDL-59160 core_group: Return if the user can access all groups in WS

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.
This commit is contained in:
Juan Leyva 2017-06-08 13:04:10 +01:00
parent 6bb80a1917
commit 0f398b500d
3 changed files with 15 additions and 0 deletions

View 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(),
)
);

View 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']);
}
/**

View 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 ===