Improved has_capability for admins using switchrole in modules

This commit is contained in:
moodler
2006-10-11 05:49:26 +00:00
parent 37fb48e0f5
commit f4e2d38aaf
+22 -2
View File
@@ -312,8 +312,28 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
if ($doanything) {
// Check site
if (empty($USER->switchrole[$context->id])) { // Ignore site setting if switchrole is active
/// First make sure that we aren't in a "switched role"
$switchroleactive = false; // Assume it isn't active in this context
if (!empty($USER->switchrole)) { // Switchrole is active somewhere!
if (!empty($USER->switchrole[$context->id])) { // Because of current context
$switchroleactive = true;
} else { // Check parent contexts
if ($parentcontextids = get_parent_contexts($context)) {
foreach ($parentcontextids as $parentcontextid) {
if (!empty($USER->switchrole[$parentcontextid])) { // Yep, switchroles active here
$switchroleactive = true;
break;
}
}
}
}
}
/// Check the site context for doanything (most common) first
if (empty($switchroleactive)) { // Ignore site setting if switchrole is active
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
if (isset($capabilities[$sitecontext->id]['moodle/site:doanything'])) {
return (0 < $capabilities[$sitecontext->id]['moodle/site:doanything']);