Added warnings in case plugin is not properly configured.

This commit is contained in:
Daniel Thee Roperto
2016-11-14 15:02:30 +11:00
parent 739c92e94e
commit 3360d357d4
10 changed files with 53 additions and 14 deletions

View File

@@ -81,6 +81,7 @@ enable the `Outage manager` plugin and place it on the top.
after your `$CFG->dataroot` is set:
```
// Insert this after $CFG->dataroot is defined.
if (file_exists(__DIR__.'/auth/outage/bootstrap.php')) {
require(__DIR__.'/auth/outage/bootstrap.php');
}

View File

@@ -54,4 +54,4 @@ if (file_exists($CFG->dataroot.'/climaintenance.php')) {
}
// 3) Set flag this file was loaded.
$CFG->auth_outage_check = 1;
$CFG->auth_outage_bootstrap_loaded = true;

View File

@@ -74,9 +74,9 @@ class cli_exception extends Exception {
const ERROR_OUTAGE_CHANGED = 7;
/**
* The outage plugin is not enabled.
* The outage plugin is not properly configured.
*/
const ERROR_PLUGIN_DISABLED = 8;
const ERROR_PLUGIN_CONFIGURATION = 8;
/**
* Moodle maintenance mode is enabled.

View File

@@ -25,6 +25,7 @@
namespace auth_outage\local\cli;
use auth_outage\local\outagelib;
use coding_exception;
use core\session\manager;
@@ -58,8 +59,9 @@ abstract class clibase {
global $CFG;
require_once($CFG->libdir.'/clilib.php');
if (!is_enabled_auth('outage')) {
throw new cli_exception(get_string('cliplugindisabled', 'auth_outage'), cli_exception::ERROR_PLUGIN_DISABLED);
$warning = outagelib::generate_plugin_configuration_warning();
if ($warning) {
throw new cli_exception($warning, cli_exception::ERROR_PLUGIN_CONFIGURATION);
}
$this->become_admin_user();

View File

@@ -104,7 +104,7 @@ class outagelib {
// There is a previewing or active outage.
$CFG->additionalhtmltopofbody = renderer::get()->render_warningbar($active, $time, false, $preview).
$CFG->additionalhtmltopofbody;
$CFG->additionalhtmltopofbody;
} catch (Exception $e) {
debugging('Exception occured while injecting our code: '.$e->getMessage());
debugging($e->getTraceAsString(), DEBUG_DEVELOPER);
@@ -144,7 +144,7 @@ class outagelib {
'default_warning_duration' => (string)(60 * 60),
'default_title' => get_string('defaulttitlevalue', 'auth_outage'),
'default_description' => get_string('defaultdescriptionvalue', 'auth_outage'),
'remove_selectors' => '.usermenu',
'remove_selectors' => ".usermenu\n.logininfo\n.homelink",
];
}
@@ -290,4 +290,38 @@ EOT;
file_put_contents($file, $code);
}
}
/**
* Generates a warning message in case the plugin is not active and configured.
*
* @return string
*
* @internal stdClass $CFG
* @internal bootstrap_renderer $OUTPUT
*/
public static function generate_plugin_configuration_warning() {
global $CFG, $OUTPUT;
$message = [];
if (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded) {
$message[] = get_string('configurationwarning', 'auth_outage');
}
if (!is_enabled_auth('outage')) {
$message[] = get_string('configurationdisabled', 'auth_outage');
}
if (count($message) == 0) {
return '';
}
if (CLI_SCRIPT) {
$message = html_to_text(implode("; ", $message));
} else {
$message = $OUTPUT->notification(implode("<br />", $message), 'notifyfailure');
}
return $message;
}
}

View File

@@ -43,7 +43,6 @@ $string['clifinishparamhelp'] = 'shows parameters help.';
$string['clifinishparamactive'] = 'finishes the currently active outage.';
$string['clifinishparamoutageid'] = 'the id of the outage to finish.';
$string['cliinmaintenancemode'] = 'Moodle maintenance mode is on. Use "php admin/cli/maintenance.php --disable" to disable it before finishing the outage.';
$string['cliplugindisabled'] = 'The authentication plugin \'Outage\' is disabled. Please enable it in the site administration it and try again.';
$string['cliwaitforiterroridxoractive'] = 'You must use --outageid=# or --active parameter but not both.';
$string['cliwaitforithelp'] = 'Waits until an outage starts.';
$string['cliwaitforitoutagestarted'] = 'Outage started!';
@@ -60,6 +59,8 @@ $string['clierroroutageended'] = 'Outage has already ended.';
$string['clierroroutagenotfound'] = 'Outage not found.';
$string['clioutagecreated'] = 'Outage created, id: {$a->id}';
$string['clone'] = 'Clone';
$string['configurationwarning'] = 'The outage plugin is not properly configured, please refer to <a href="https://github.com/catalyst/moodle-auth_outage/blob/master/README.md#installation" target="_blank">README.md</a> for more information.';
$string['configurationdisabled'] = 'The authentication plugin \'Outage\' is disabled. Please enable it in the site administration it and try again.';
$string['datetimeformat'] = '%a %d %h %Y at %I:%M%P %Z';
$string['defaultlayoutcss'] = 'Layout CSS';
$string['defaultlayoutcssdescription'] = 'This CSS code can be used to override the Outage Warning Bar CSS.';

View File

@@ -25,6 +25,7 @@
use auth_outage\dml\outagedb;
use auth_outage\output\renderer;
use auth_outage\local\outagelib;
require_once(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php');
@@ -39,7 +40,8 @@ $now = time();
renderer::get()->output_view('manage.php', [
'unended' => outagedb::get_all_unended($now),
'ended' => outagedb::get_all_ended($now),
'ended' => outagedb::get_all_ended($now),
'warning' => outagelib::generate_plugin_configuration_warning(),
]);
echo $OUTPUT->footer();

View File

@@ -89,10 +89,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
// Create 'Allowed IPs' settings.
$allowedips = outagelib::get_config()->allowedips;
$description = '';
if (!isset($CFG->auth_outage_check) || !$CFG->auth_outage_check) {
$description .= $OUTPUT->notification(get_string('allowedipsnoconfig', 'auth_outage'), 'notifyfailure');
}
$description = outagelib::generate_plugin_configuration_warning();
if (trim($allowedips) == '') {
$message = 'allowedipsempty';
$type = 'notifymessage';

View File

@@ -103,7 +103,7 @@ class cli_test extends auth_outage_cli_testcase {
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
// Try to create an CLI object.
$this->set_expected_cli_exception(cli_exception::ERROR_PLUGIN_DISABLED);
$this->set_expected_cli_exception(cli_exception::ERROR_PLUGIN_CONFIGURATION);
new create();
}
}

View File

@@ -30,6 +30,8 @@ use auth_outage\output\renderer;
defined('MOODLE_INTERNAL') || die();
$urlnew = new moodle_url('/auth/outage/edit.php');
echo $viewbag['warning'];
?>
<section id="section_planned_outages">