MDL-53566 core: Allow admins more control over locking

This change allows sites to configure locking such that it does not
apply to administrators at all.
This commit is contained in:
Andrew Nicols
2018-11-13 21:17:40 +08:00
parent 6a89b6c8f0
commit bb41db9ce0
5 changed files with 182 additions and 3 deletions
+10 -2
View File
@@ -480,8 +480,16 @@ function has_capability($capability, context $context, $user = null, $doanything
// Check whether context locking is enabled.
if (!empty($CFG->contextlocking)) {
if ($capinfo->captype === 'write' && $context->locked && $capinfo->name !== 'moodle/site:managecontextlocks') {
return false;
if ($capinfo->captype === 'write' && $context->locked) {
// Context locking applies to any write capability in a locked context.
// It does not apply to moodle/site:managecontextlocks - this is to allow context locking to be unlocked.
if ($capinfo->name !== 'moodle/site:managecontextlocks') {
// It applies to all users who are not site admins.
// It also applies to site admins when contextlockappliestoadmin is set.
if (!is_siteadmin($userid) || !empty($CFG->contextlockappliestoadmin)) {
return false;
}
}
}
}