From 3d034f77a8e90df70cc1ae7739c1276c8a317aca Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:18:23 +0000 Subject: [PATCH] accesslib: has_cap_fad() - merge switchrole with defaultuserrole If you are a teacher in course X, you have at least teacher-in-X + defaultloggedinuser-sitewide. So in the course you'll have techer+defaultloggedinuser. We try to mimic that in switchrole. Thanks to Petr for pointing me to a similar fix in CVS. Probably related: MDL-10945 --- lib/accesslib.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index c6f3330a5f..7554d41a87 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -533,6 +533,13 @@ function path_inaccessdata($path, $ad) { * in our bottom up processing so they don't "see" that * there are real RAs that can do all sorts of things. * + * Switch Role merges with default role + * ------------------------------------ + * If you are a teacher in course X, you have at least + * teacher-in-X + defaultloggedinuser-sitewide. So in the + * course you'll have techer+defaultloggedinuser. + * We try to mimic that in switchrole. + * * "Guest default role" exception * ------------------------------ * @@ -597,17 +604,21 @@ function has_cap_fad($capability, $context, $ad, $doanything) { $ctxp = $contexts[$n]; if (isset($ad['rsw'][$ctxp])) { // Found a switchrole assignment - $roleid = $ad['rsw'][$ctxp]; - // Walk the path for capabilities - // from the bottom up... - for ($m=$cc-1;$m>=0;$m--) { - $capctxp = $contexts[$m]; - if (isset($ad['rdef']["{$capctxp}:$roleid"][$capability])) { - $perm = $ad['rdef']["{$capctxp}:$roleid"][$capability]; - if ($perm === CAP_PROHIBIT) { - return false; - } else { - $can += $perm; + // check for that role _plus_ the default user role + $ras = array($ad['rsw'][$ctxp],$CFG->defaultuserroleid); + for ($rn=0;$rn<2;$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($ad['rdef']["{$capctxp}:$roleid"][$capability])) { + $perm = $ad['rdef']["{$capctxp}:$roleid"][$capability]; + if ($perm === CAP_PROHIBIT) { + return false; + } else { + $can += $perm; + } } } } -- 2.39.5