Skip to content

Commit

Permalink
MDL-49398 accesslib: Change competency to use new accesslib function
Browse files Browse the repository at this point in the history
  • Loading branch information
tlevi authored and sk-unikent committed Jun 2, 2017
1 parent e705e69 commit 95c0b81
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions competency/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5154,9 +5154,12 @@ public static function filter_users_with_capability_on_user_context_sql($capabil
$syscontext = context_system::instance();
$hassystem = has_capability($capability, $syscontext, $userid);

$access = get_user_access_sitewide($userid);
$access = get_user_roles_sitewide_accessdata($userid);
// Build up a list of level 2 contexts (candidates to be user context).
$filtercontexts = array();
// Build list of roles to check overrides.
$roles = array();

foreach ($access['ra'] as $path => $role) {
$parts = explode('/', $path);
if (count($parts) == 3) {
Expand All @@ -5165,24 +5168,23 @@ public static function filter_users_with_capability_on_user_context_sql($capabil
// We know this is not a user context because there is another path with more than 2 levels.
unset($filtercontexts[$parts[2]]);
}
$roles = array_merge($roles, $role);
}

// Add all contexts in which a role may be overidden.
foreach ($access['rdef'] as $pathandroleid => $def) {
$matches = array();
if (!isset($def[$capability])) {
// The capability is not mentioned, we can ignore.
continue;
}

list($contextpath, $roleid) = explode(':', $pathandroleid, 2);
$parts = explode('/', $contextpath);
if (count($parts) != 3) {
// Only get potential user contexts, they only ever have 2 slashes /parentId/Id.
continue;
$rdefs = get_role_definitions($roles);
foreach ($rdefs as $roledef) {
foreach ($roledef as $path => $caps) {
if (!isset($caps[$capability])) {
// The capability is not mentioned, we can ignore.
continue;
}
$parts = explode('/', $path);
if (count($parts) === 3) {
// Only get potential user contexts, they only ever have 2 slashes /parentId/Id.
$filtercontexts[$parts[2]] = $parts[2];
}
}

$filtercontexts[$parts[2]] = $parts[2];
}

// No interesting contexts - return all or no results.
Expand Down

0 comments on commit 95c0b81

Please sign in to comment.