role_context_capabilities should handle current context too and role override simply use parent context
This commit is contained in:
@@ -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');
|
||||
|
||||
+3
-8
@@ -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) {
|
||||
@@ -2579,4 +2574,4 @@ function get_user_capability_course($capability, $userid='') {
|
||||
}
|
||||
return $usercourses;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user