MDL-55791 admin: maintenance mode access capability

Add capability to allow certain non-admin users through maintenance
mode.
This commit is contained in:
Matt Davidson 2016-09-12 10:37:25 -04:00
parent 0344082208
commit 59c66f926f
7 changed files with 22 additions and 13 deletions

View file

@ -52,13 +52,15 @@ if ($CFG->forcelogin) {
user_accesstime_log();
}
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
// If the site is currently under maintenance, then print a message.
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
print_maintenance_message();
}
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
if ($hassiteconfig && moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}

View file

@ -392,6 +392,7 @@ $string['site:doanything'] = 'Allowed to do everything';
$string['site:doclinks'] = 'Show links to offsite docs';
$string['site:forcelanguage'] = 'Override course language';
$string['site:import'] = 'Import other courses into a course';
$string['site:maintenanceaccess'] = 'Allowed access when maintenance mode is enabled.';
$string['site:manageblocks'] = 'Manage blocks on a page';
$string['site:mnetloginfromremote'] = 'Login from a remote application via MNet';
$string['site:mnetlogintoremote'] = 'Roam to a remote application via MNet';

View file

@ -2292,5 +2292,11 @@ $capabilities = array(
'manager' => CAP_ALLOW
),
),
'moodle/site:maintenanceaccess' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
)
),
);

View file

@ -2683,7 +2683,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
}
// If the site is currently under maintenance, then print a message.
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', $sysctx)) {
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:maintenanceaccess', $sysctx)) {
if ($preventredirect) {
throw new require_login_exception('Maintenance in progress');
}

View file

@ -46,9 +46,9 @@ if (is_restored_user($username)) {
$user = authenticate_user_login($username, $password);
if (!empty($user)) {
//Non admin can not authenticate if maintenance mode
$hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
// Cannot authenticate unless maintenance access is granted.
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
throw new moodle_exception('sitemaintenance', 'admin');
}

View file

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016090800.01; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016090800.02; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

View file

@ -120,9 +120,9 @@ class webservice {
}
}
//Non admin can not authenticate if maintenance mode
$hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
// Cannot authenticate unless maintenance access is granted.
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
//this is usually temporary, client want to implement code logic => moodle_exception
throw new moodle_exception('sitemaintenance', 'admin');
}
@ -924,9 +924,9 @@ abstract class webservice_server implements webservice_server_interface {
$user = $this->authenticate_by_token(EXTERNAL_TOKEN_EMBEDDED);
}
//Non admin can not authenticate if maintenance mode
$hassiteconfig = has_capability('moodle/site:config', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
// Cannot authenticate unless maintenance access is granted.
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance(), $user);
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
throw new moodle_exception('sitemaintenance', 'admin');
}