mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-23062 switch role now works for admin too
This commit is contained in:
parent
4e0969f0d3
commit
7abbc5c2ba
@ -561,7 +561,27 @@ function has_capability($capability, $context, $user = NULL, $doanything=true) {
|
||||
// and it is not possible to switch to admin role either.
|
||||
if ($doanything) {
|
||||
if (is_siteadmin($userid)) {
|
||||
return true;
|
||||
if ($userid != $USER->id) {
|
||||
return true;
|
||||
}
|
||||
// make sure switchrole is not used in this context
|
||||
if (empty($USER->access['rsw'])) {
|
||||
return true;
|
||||
}
|
||||
$parts = explode('/', trim($context->path, '/'));
|
||||
$path = '';
|
||||
$switched = false;
|
||||
foreach ($parts as $part) {
|
||||
$path .= '/' . $part;
|
||||
if (!empty($USER->access['rsw'][$path])) {
|
||||
$switched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$switched) {
|
||||
return true;
|
||||
}
|
||||
//ok, admin switched role in this context, let's use normal access control rules
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user