Skip to content

Commit

Permalink
role_context_capabilities should handle current context too and role …
Browse files Browse the repository at this point in the history
…override simply use parent context
  • Loading branch information
skodak committed Sep 20, 2006
1 parent bcaa8d9 commit 8521d83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 9 additions & 1 deletion admin/roles/override.php
Expand Up @@ -133,7 +133,15 @@
choose_from_menu ($overridableroles, 'roleid', $roleid, get_string('listallroles', 'role'), $script='rolesform.submit()');
echo '</div></form>';

$r_caps = role_context_capabilities($roleid, $context);
$parentcontexts = get_parent_contexts($context);
if (!empty($parentcontexts)) {
$parentcontext = array_shift($parentcontexts);
$parentcontext = get_context_instance_by_id($parentcontext);
} else {
$parentcontext = $context; // site level in override??
}

$r_caps = role_context_capabilities($roleid, $parentcontext);

$localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
'', 'capability, permission, id');
Expand Down
11 changes: 3 additions & 8 deletions lib/accesslib.php
Expand Up @@ -1971,13 +1971,8 @@ function fetch_context_capabilities($context) {
function role_context_capabilities($roleid, $context, $cap='') {
global $CFG;

$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
if ($sitecontext->id == $context->id) {
$contexts = array($sitecontext->id);
} else {
// first of all, figure out all parental contexts
$contexts = array_reverse(get_parent_contexts($context));
}
$contexts = get_parent_contexts($context);
$contexts[] = $context->id;
$contexts = '('.implode(',', $contexts).')';

if ($cap) {
Expand Down Expand Up @@ -2579,4 +2574,4 @@ function get_user_capability_course($capability, $userid='') {
}
return $usercourses;
}
?>
?>

0 comments on commit 8521d83

Please sign in to comment.