for ($n=$cc-1;$n>=0;$n--) {
$ctxp = $contexts[$n];
if (isset($sess['ra'][$ctxp])) {
- // Found a role assignment
- $roleid = $sess['ra'][$ctxp];
- // Walk the path for capabilities
- // from the bottom up...
- for ($m=$cc-1;$m>=0;$m--) {
- $capctxp = $contexts[$m];
- if (isset($sess['rdef']["{$capctxp}:$roleid"][$capability])) {
- $perm = $sess['rdef']["{$capctxp}:$roleid"][$capability];
- if ($perm === CAP_PROHIBIT) {
- return false;
- } else {
- $can += $perm;
+ // Found role assignments on this leaf
+ $ras = $sess['ra'][$ctxp];
+ $rc = count($ras);
+ for ($rn=0;$rn<$rc;$rn++) {
+ $roleid = $ras[$rn];
+ // Walk the path for capabilities
+ // from the bottom up...
+ for ($m=$cc-1;$m>=0;$m--) {
+ $capctxp = $contexts[$m];
+ if (isset($sess['rdef']["{$capctxp}:$roleid"][$capability])) {
+ $perm = $sess['rdef']["{$capctxp}:$roleid"][$capability];
+ if ($perm === CAP_PROHIBIT) {
+ return false;
+ } else {
+ $can += $perm;
+ }
}
}
}
// From the bottom up...
for ($n=$cc-1;$n>=0;$n--) {
$ctxp = $contexts[$n];
- if (isset($sess['ra'][$ctxp])) {
- // Found a role assignment
- $roleid = $sess['ra'][$ctxp];
- $roles[] = $roleid;
+ if (isset($sess['ra'][$ctxp]) && count($sess['ra'][$ctxp])) {
+ // Found assignments on this leaf
+ $addroles = $sess['ra'][$ctxp];
+ $roles = array_merge($roles, $addroles);
}
}
* We do _not_ delve deeper than courses because the number of
* overrides at the module/block levels is HUGE.
*
- * [ra] => [/path/] = roleid
+ * [ra] => [/path/] = array(roleid, roleid)
* [rdef] => [/path/:roleid][capability]=permission
* [loaded] => array('/path', '/path')
*
$raparents = array();
if ($rs->RecordCount()) {
while ($ra = rs_fetch_next_record($rs)) {
- $acc['ra'][$ra->path] = $ra->roleid;
+ // RAs leafs are arrays to support multi
+ // role assignments...
+ if (!isset($acc['ra'][$ra->path])) {
+ $acc['ra'][$ra->path] = array();
+ }
+ array_push($acc['ra'][$ra->path], $ra->roleid);
if (!empty($ra->capability)) {
$k = "{$ra->path}:{$ra->roleid}";
$acc['rdef'][$k][$ra->capability] = $ra->permission;
$newroles = array();
if ($rs->RecordCount()) {
while ($ra = rs_fetch_next_record($rs)) {
- $acc['ra'][$ra->path] = $ra->roleid;
+ if (!isset($acc['ra'][$ra->path])) {
+ $acc['ra'][$ra->path] = array();
+ }
+ array_push($acc['ra'][$ra->path], $ra->roleid);
if (!empty($ra->capability)) {
$k = "{$ra->path}:{$ra->roleid}";
$acc['rdef'][$k][$ra->capability] = $ra->permission;
$USER->access = get_user_access_sitewide($USER->id);
$USER->access = get_role_access($CFG->defaultuserroleid, $USER->access);
// define a "default" enrolment
- $USER->access['ra']["$base:def"] = $CFG->defaultuserroleid;
+ $USER->access['ra']["$base:def"] = array($CFG->defaultuserroleid);
if ($CFG->defaultuserroleid === $CFG->guestroleid ) {
if (isset($USER->access['rdef']["$base:{$CFG->guestroleid}"]['moodle/legacy:guest'])) {
unset($USER->access['rdef']["$base:{$CFG->guestroleid}"]['moodle/legacy:guest']);
} else {
if ($roleid = get_notloggedin_roleid()) {
$USER->access = get_role_access(get_notloggedin_roleid());
- $USER->access['ra']["$base:def"] = $roleid;
+ $USER->access['ra']["$base:def"] = array($roleid);
}
}
}