33 Commits

Author SHA1 Message Date
Nathan Nguyen
3f1cfcb908 WR#310007 - Fix failed unit test 2019-04-23 13:21:44 +10:00
Brendan Heywood
dec4c7bf53 Fixed ipwhitelist escaping issue #150 2019-03-28 14:32:20 +11:00
Dmitrii Metelkin
e94d9c94ea Merge pull request #147 from catalyst/issues#146
Add an icon map for calendar events to fix #146
2019-02-22 10:35:57 +11:00
Dmitrii Metelkin
030fec75e1 Add an icon map for calendar events to fix #146 2019-02-22 10:32:19 +11:00
tuanngocnguyen
cf85a04ddc Merge pull request #145 from catalyst/issue#144
user date
2018-12-06 16:53:17 +11:00
Nathan Nguyen
c820bb1c0b Fix day display 2018-12-06 15:42:56 +11:00
Nathan Nguyen
e1b6279437 user date 2018-12-06 15:07:58 +11:00
tuanngocnguyen
846879d2d6 Merge pull request #143 from catalyst/issue#140
#140 Turn off check_wwwroot_accessible
2018-12-03 16:24:54 +11:00
Nathan Nguyen
38f838d84e Turn off check_wwwroot_accessible on admin pages other than outage setting page 2018-12-03 14:36:54 +11:00
Nathan Nguyen
df649c8133 change relative link to absolute link 2018-11-30 10:40:43 +11:00
Dmitrii Metelkin
8f5e5dbb50 Merge pull request #139 from catalyst/StyleSheetLoadingError
Fix problem with loading stylesheet in preview mode
2018-11-16 13:36:02 +11:00
Nathan Nguyen
f4962f22a8 Fix problem with loading stylesheet in preview mode 2018-11-16 10:40:08 +11:00
Dan Marsden
1ec50dadb2 add details about version support 2018-10-11 14:01:28 +13:00
Ilya Tregubov
54045d5ce1 Incease timeout to prevent settings page throwing error (from time to time) 2018-10-11 11:15:04 +11:00
Dan Marsden
e84534f7b6 Fix #127 fix boost header when outage plugin in use. 2018-10-05 15:19:12 +13:00
Dan Marsden
ceb9e065b9 Use correct check for behat running. 2018-10-05 14:21:03 +13:00
Dan Marsden
3639883d30 Don't use curl when running behat tests to get page outage.
Behat step improvements.
2018-10-05 13:45:08 +13:00
Dan Marsden
6c69d46ebe Fix some behat steps. 2018-10-05 11:49:59 +13:00
Dan Marsden
6cea3f52c2 Fix travis config for old php versions. 2018-10-05 11:08:56 +13:00
Dan Marsden
49bdb687c3 Fix #120 increase timeout values to prevent ci failures. 2018-10-05 10:20:59 +13:00
Dan Marsden
c175333f88 Remove incorrect usage of example.com in tests.
remove http part of test - site might be https.
2018-10-03 22:55:09 +13:00
Dan Marsden
3e5446d8d1 tidy up coding guideline travis failures. 2018-10-03 22:10:39 +13:00
Dan Marsden
6c489ad20e codiing guideline improvements to css file. 2018-10-03 15:50:27 +13:00
Dan Marsden
a33e80b4aa Coding guidelines - tidy up some spacing in behat tests. 2018-10-03 15:46:11 +13:00
Dan Marsden
fa0641ec47 update travis config. 2018-10-03 15:34:13 +13:00
Dan Marsden
20df09d3e9 Revert "Temporarly disabling one scenario test, see Issue #68."
This reverts commit 42fec9e752.
2018-10-03 15:28:03 +13:00
Dan Marsden
ff59dac023 Revert "Travis is freezing with a few behat tests which creates outages. It works fine locally both manually and with selenium. Ignoring tests and opening issue #77 to deal with it later as the code works fine."
This reverts commit fc2349f312.
2018-10-03 15:27:21 +13:00
adamlynam-catalyst
5aaf0ddeda Adding check for use of ip restrictions before warning (#134)
* Adding check for use of ip restrictions before warning about bootstrap.php not being included in config.php

* Replacing reference to same class with self
2018-10-03 15:22:31 +13:00
Dan Marsden
b3917b7b63 fix postgres version used in travis. 2018-10-03 15:20:26 +13:00
Dan Marsden
882f6a1afc Fix #124 use correct urls in redirects. 2018-10-03 15:16:36 +13:00
Dan Marsden
07e26e312c Convert deprecated pix_url calls. 2018-10-03 15:10:59 +13:00
Dan Marsden
92f7ec0541 add behat tests back to master branch. 2018-10-03 15:10:33 +13:00
Dan Marsden
84b35f01fa Master branch now requires 3.3 and higher so we can merge
version specific changes.
2018-10-03 15:00:20 +13:00
22 changed files with 205 additions and 244 deletions

View File

@@ -1,47 +1,60 @@
language: php
sudo: true
addons:
firefox: "47.0.1"
postgresql: "9.4"
apt:
packages:
- oracle-java8-installer
- oracle-java8-set-default
cache:
directories:
- $HOME/.composer/cache
addons:
postgresql: "9.5"
- $HOME/.composer/cache
- $HOME/.npm
php:
- 7.0
services:
- mysql
env:
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_32_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
- DB=pgsql MOODLE_BRANCH=master
- DB=mysqli MOODLE_BRANCH=master
matrix:
include:
- php: 5.6
env: DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
env: DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
- php: 5.6
env: DB=mysqli MOODLE_BRANCH=MOODLE_30_STABLE
env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
- php: 7.1
env: DB=pgsql MOODLE_BRANCH=master
before_install:
- phpenv config-rm xdebug.ini
- nvm install 8.9
- nvm use 8.9
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
install:
- moodle-plugin-ci install -vvv
- moodle-plugin-ci install
script:
- moodle-plugin-ci validate
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci csslint
- moodle-plugin-ci shifter
- moodle-plugin-ci jshint
- moodle-plugin-ci phpunit
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci validate
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat

View File

@@ -3,7 +3,7 @@
</a>
# Moodle Outage manager plugin
* [Version Support](#version-support)
* [What is this?](#what-is-this)
* [Moodle Requirements](#moodle-requirements)
* [Screenshots](#screenshots)
@@ -13,6 +13,11 @@
* [Why is it an auth plugin?](#why-it-is-an-auth-plugin)
* [Feedback and issues](#feedback-and-issues)
Version Support
-------------
The master branch supports Moodle 3.3 and higher.
The MOODLE_32_STABLE branch supports Moodle 2.7 -> Moodle 3.2
What is this?
-------------
@@ -39,16 +44,6 @@ If you have an older version of Moodle you can still make it work but you will
need to manually add one extra plugin, please check:
* https://github.com/catalyst/moodle-local_outage
Branches
--------
| Moodle version | Branch | PHP |
| ----------------- | ----------- | ---- |
| Moodle 2.7 to 3.2 | MOODLE_32_STABLE | 5.5+ |
| Totara up to 10 | TOTARA_10 | 5.5+ |
| Moodle 3.3 to 3.9 | MOODLE_39_STABLE | 7.0+ |
| Totara 11 to 12 | MOODLE_39_STABLE | 7.0+ |
| Moodle 3.10 | master | 7.2+ |
| Totara 13+ | master | 7.2+ |
Screenshots
-----------
@@ -109,7 +104,7 @@ Creates a new outage.
-c, --clone clone another outage except for the start time.
-a, --autostart must be Y or N, sets if the outage automatically triggers maintenance mode.
-w, --warn how many seconds before it starts to display a warning.
-s, --start in how many seconds should this outage start or unix time to start outage. Required.
-s, --start in how many seconds should this outage start. Required.
-d, --duration how many seconds should the outage last.
-t, --title the title of the outage.
-e, --description the description of the outage.

View File

@@ -170,9 +170,7 @@ class create extends clibase {
$this->become_admin_user();
// Create the outage.
// If time is above 1500000000 then it must be a unix time timestamp, otherwise they are trying to create
// an outage 47 years in advance.
$start = $options['start'] > 1500000000 ? $options['start'] : $this->time + $options['start'];
$start = $this->time + $options['start'];
$outage = new outage([
'autostart' => $options['autostart'],
'warntime' => $start - $options['warn'],

View File

@@ -57,7 +57,7 @@ class maintenance_static_page {
if (is_null($outage)) {
$html = null;
} else if (PHPUNIT_TEST) {
} else if (PHPUNIT_TEST || defined('BEHAT_SITE_RUNNING')) {
$html = '<html></html>';
} else {
$data = maintenance_static_page_io::file_get_data(

View File

@@ -30,6 +30,7 @@ use coding_exception;
use DOMDocument;
use DOMElement;
use invalid_state_exception;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
@@ -179,10 +180,12 @@ class maintenance_static_page_generator {
foreach ($links as $link) {
$rel = $link->getAttribute("rel");
$href = $link->getAttribute("href");
if (($rel != 'shortcut icon') || ($href == '')) {
continue;
if (($rel == 'shortcut icon') && ($href != '')) {
if (!maintenance_static_page_io::is_url($href)) {
$href = (string) new moodle_url($href);
}
$link->setAttribute('href', $this->io->generate_file_url($href)); // Works for most image formats.
}
$link->setAttribute('href', $this->io->generate_file_url($href)); // Works for most image formats.
}
}
@@ -194,10 +197,12 @@ class maintenance_static_page_generator {
foreach ($links as $link) {
$src = $link->getAttribute("src");
if ($src == '') {
continue;
if ($src != '') {
if (!maintenance_static_page_io::is_url($src)) {
$src = (string) new moodle_url($src);
}
$link->setAttribute('src', $this->io->generate_file_url($src)); // Works for most image formats.
}
$link->setAttribute('src', $this->io->generate_file_url($src)); // Works for most image formats.
}
}

View File

@@ -246,14 +246,13 @@ class outagelib {
}
// I know Moodle validation would clean up this field, but just in case, let's ensure no
// single-quotes (and double for the sake of it) are present otherwise it would break the code.
$allowedips = str_replace('\'"', '', $allowedips);
$allowedips = addslashes($allowedips);
$code = <<<'EOT'
<?php
if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('{{ALLOWEDIPS}}')) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
header('Status: 503 Moodle under maintenance');
@@ -327,11 +326,11 @@ EOT;
* @internal bootstrap_renderer $OUTPUT
*/
public static function generate_plugin_configuration_warning() {
global $CFG, $OUTPUT;
global $CFG, $OUTPUT, $PAGE;
$message = [];
if (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded) {
if (trim(self::get_config()->allowedips) != '' && (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)) {
$message[] = get_string('configurationwarning', 'auth_outage');
}
@@ -339,8 +338,10 @@ EOT;
$message[] = get_string('configurationdisabled', 'auth_outage');
}
if (!self::check_wwwroot_accessible()) {
$message[] = get_string('configurationinaccessiblewwwroot', 'auth_outage', ['wwwroot' => $CFG->wwwroot]);
if ($PAGE->pagetype == "admin-setting-auth_outage" || $PAGE->pagetype == "admin-setting-authsettingoutage") {
if (!self::check_wwwroot_accessible()) {
$message[] = get_string('configurationinaccessiblewwwroot', 'auth_outage', ['wwwroot' => $CFG->wwwroot]);
}
}
if (count($message) == 0) {

View File

@@ -84,7 +84,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/info.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/preview'),
'src' => $OUTPUT->image_url('t/preview'),
'alt' => get_string('view'),
'class' => 'iconsmall',
@@ -100,7 +100,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/edit'),
'src' => $OUTPUT->image_url('t/edit'),
'alt' => get_string('edit'),
'class' => 'iconsmall',
]),
@@ -112,7 +112,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['clone' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/copy'),
'src' => $OUTPUT->image_url('t/copy'),
'alt' => get_string('clone', 'auth_outage'),
'class' => 'iconsmall',
@@ -125,7 +125,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/finish.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'src' => $OUTPUT->image_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]),
@@ -138,7 +138,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/delete'),
'src' => $OUTPUT->image_url('t/delete'),
'alt' => get_string('delete'),
'class' => 'iconsmall',
]),

View File

@@ -178,14 +178,14 @@ class renderer extends plugin_renderer_base {
$url = new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
['src' => $OUTPUT->image_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
);
$linkedit = html_writer::link($url, $img, ['title' => get_string('edit')]);
$url = new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
['src' => $OUTPUT->image_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
);
$linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]);

View File

@@ -34,7 +34,7 @@ $string['clicreateparamdescription'] = 'the description of the outage.';
$string['clicreateparamduration'] = 'how many seconds should the outage last.';
$string['clicreateparamhelp'] = 'shows parameters help.';
$string['clicreateparamonlyid'] = 'only outputs the new outage id, useful for scripts.';
$string['clicreateparamstart'] = 'in how many seconds should this outage start or unix time to start outage. Required.';
$string['clicreateparamstart'] = 'in how many seconds should this outage start. Required.';
$string['clicreateparamtitle'] = 'the title of the outage.';
$string['clicreateparamwarn'] = 'how many seconds before it starts to display a warning.';
$string['clifinishhelp'] = 'Finishes an ongoing outage.';
@@ -94,7 +94,7 @@ $string['allowedipshasmyip'] = 'Your IP (<i>{$a->ip}</i>) is in the list and you
$string['allowedipshasntmyip'] = 'Your IP (<i>{$a->ip}</i>) is not in the list and you will be blocked out during an outage.';
$string['allowedipsnoconfig'] = 'Your config.php does not have the extra setup to allow blocking via IP.<br />Please refer to our <a href="https://github.com/catalyst/moodle-auth_outage#installation" target="_blank">README.md</a> file for more information.';
$string['menusettings'] = 'Settings';
$string['menumanage'] = 'Manage';
$string['menumanage'] = 'Manage outages';
$string['messageoutagebackonline'] = 'We are back online!';
$string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.';
$string['messageoutageongoing'] = 'Back online at {$a->stop}.';

11
lib.php
View File

@@ -87,3 +87,14 @@ function auth_outage_get_climaintenance_resource_file($file) {
$realpath = realpath($resourcedir.'/'.$file);
return ($realpath == false) ? null : $realpath;
}
/**
* Display required icon for the calendar events.
*
* @return array
*/
function auth_outage_get_fontawesome_icon_map() {
return [
'core:i/auth_outageevent' => 'fa-power-off',
];
}

View File

@@ -11,9 +11,8 @@ Feature: Change the default settings
Given the authentication plugin "outage" is enabled
And I am an administrator
Scenario Outline: Check if I can save the default settings.
When I navigate to "Settings" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
And I set the following fields to these values:
| s_auth_outage_default_autostart | <autostart> |
| s_auth_outage_default_warning_duration[v] | <warning> |

View File

@@ -8,14 +8,11 @@ Feature: IP Blocker
- An ongoing outage does not block Moodle execution, although it can trigger maintenance mode.
- Maintenance mode completely blocks Moodle and can only be deactivated using the CLI.
Background:
Given the authentication plugin "outage" is enabled
Scenario: Default IP Whitelist Settings
Given I am an administrator
And I am on homepage
When I navigate to "Settings" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
Then I should see "Allowed IP list"
And I should see an empty settings text area "allowedips"

View File

@@ -11,22 +11,19 @@ Feature: Manage outages
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background: Always login as admin, enable the auth_outage plugin and go to the outage management page.
Given the authentication plugin "outage" is enabled
And I log in as "admin"
And I wait "1" seconds
Scenario: Check if I can navigate to management page.
Given I am on homepage
When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Manage outages" in site administration
Then I should see "Planned outages"
And I should see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "Outage history"
And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario Outline: Planned outages should include all outages not finished or stopped.
Given there is a "<type>" outage
When I am on Outage Management Page
@@ -40,7 +37,6 @@ Feature: Manage outages
| finished | outage_history |
| stopped | outage_history |
Scenario Outline: Planned and history outages have different actions.
Given there is a "<type>" outage
When I am on Outage Management Page
@@ -59,14 +55,12 @@ Feature: Manage outages
| finished | see | see | not see | not see | not see |
| stopped | see | see | not see | not see | not see |
# Scenario: Create an outage using defaults.
# Given I am on Outage Management Page
# When I press "Create outage"
# And I press "Save changes"
# And I should not see "No outages found." in the "#section_planned_outages" "css_element"
# And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario: Create an outage using defaults.
Given I am on Outage Management Page
When I press "Create outage"
And I press "Save changes"
And I should not see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario: View an outage which should open in a new window or tab.
Given there is a "waiting" outage
@@ -75,29 +69,26 @@ Feature: Manage outages
Then I should be in a new window
And I should see "Example of waiting outage"
Scenario: Clone an outage.
Given there is a "waiting" outage
And I am on Outage Management Page
When I click on the "Clone" action button
Then I should see "Clone outage"
And I set the field "title" to "My cloned outage"
And I press "Save changes"
Then I should see "Example of waiting outage"
And I should see "My cloned outage"
# Scenario: Clone an outage.
# Given there is a "waiting" outage
# And I am on Outage Management Page
# When I click on the "Clone" action button
# Then I should see "Clone outage"
# And I set the field "title" to "My cloned outage"
# And I press "Save changes"
# Then I should see "Example of waiting outage"
# And I should see "My cloned outage"
# Scenario: Edit an outage.
# Given there is a "warning" outage
# And I am on Outage Management Page
# And I should see "Example of warning outage"
# When I click on the "Edit" action button
# Then I should see "Edit outage"
# And I set the field "title" to "My previous warning outage"
# And I press "Save changes"
# Then I should not see "Example of warning outage"
# And I should see "My previous warning outage"
Scenario: Edit an outage.
Given there is a "warning" outage
And I am on Outage Management Page
And I should see "Example of warning outage"
When I click on the "Edit" action button
Then I should see "Edit outage"
And I set the field "title" to "My previous warning outage"
And I press "Save changes"
Then I should not see "Example of warning outage"
And I should see "My previous warning outage"
Scenario: Delete an outage
Given there is a "warning" outage
@@ -109,7 +100,6 @@ Feature: Manage outages
Then I press "Delete"
And I should not see "Example of warning outage"
Scenario: Finish an outage
Given there is a "ongoing" outage
And I am on Outage Management Page

View File

@@ -11,46 +11,45 @@ Feature: Warning bar
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background:
Given the authentication plugin "outage" is enabled
# Scenario: This is how an outage should happend without maintenance mode and manual finish.
# Given there is the following outage:
# | warnbefore | startsin | stopsafter |
# | 10 | 20 | 10 |
# When I am on homepage
# Then I should not see the warning bar
# When I wait until the outage warns
# And I reload the page
# Then I should see "Shutting down in" in the warning bar
# When I wait until the outage starts
# Then I should see "Back online at" in the warning bar
# When I wait until the outage stops
# Then I should see "We are back online!" in the warning bar
# When I reload the page
# Then I should not see the warning bar
Scenario Outline: Some stages should show its own warning message.
Given there is a "<type>" outage
When I am on homepage
Then I should see "<see>" in the warning bar
Examples:
| type | see |
| warning | Shutting down in |
| ongoing | Back online at |
Scenario Outline: Some stages should not have a warning bar.
Given there is a "<type>" outage
Scenario: This is how an outage should happen without maintenance mode and manual finish.
Given there is the following outage:
| warnbefore | startsin | stopsafter |
| 10 | 20 | 10 |
When I am on homepage
Then I should not see the warning bar
Examples:
| type |
| waiting |
| finished |
| stopped |
When I wait until the outage warns
And I reload the page
Then I should see "Shutting down in" in the warning bar
When I wait until the outage starts
And I reload the page
Then I should see "Back online at" in the warning bar
When I wait until the outage stops
Then I should see "We are back online!" in the warning bar
When I reload the page
Then I should not see the warning bar
#
#
# Scenario Outline: Some stages should show its own warning message.
# Given there is a "<type>" outage
# When I am on homepage
# Then I should see "<see>" in the warning bar
#
# Examples:
# | type | see |
# | warning | Shutting down in |
# | ongoing | Back online at |
#
#
# Scenario Outline: Some stages should not have a warning bar.
# Given there is a "<type>" outage
# When I am on homepage
# Then I should not see the warning bar
#
# Examples:
# | type |
# | waiting |
# | finished |
# | stopped |

View File

@@ -70,9 +70,4 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
parent::setUp();
$this->resetAfterTest(true);
}
public function tearDown() {
global $DB;
$DB->delete_records('auth_outage');
}
}

View File

@@ -49,8 +49,8 @@ class calendar_test extends advanced_testcase {
* Creates an outage and checks if its in the calendar.
*/
public function test_create() {
$this->resetAfterTest(true);
self::setAdminUser();
$this->resetAfterTest(false);
$time = time();
self::$outage = new outage([
@@ -70,20 +70,8 @@ class calendar_test extends advanced_testcase {
* Updates an outage and checks the calendar.
*/
public function test_update() {
$this->resetAfterTest(true);
self::setAdminUser();
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
'title' => 'Title',
'description' => 'Description',
]);
calendar::create(self::$outage);
$this->resetAfterTest(false);
self::$outage->title = 'New Title';
calendar::update(self::$outage);
@@ -94,22 +82,8 @@ class calendar_test extends advanced_testcase {
* Deletes an outage and checks the calendar.
*/
public function test_delete() {
$this->resetAfterTest(true);
self::setAdminUser();
$time = time();
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
'starttime' => $time,
'stoptime' => $time + (2 * 60 * 60),
'title' => 'Title',
'description' => 'Description',
]);
calendar::create(self::$outage);
$this->check_calendar();
$this->resetAfterTest(true);
calendar::delete(self::$outage->id);
self::assertNull(calendar::load(self::$outage->id));
@@ -119,8 +93,8 @@ class calendar_test extends advanced_testcase {
* Try to update a non existing outage.
*/
public function test_update_notfound() {
$this->resetAfterTest(true);
self::setAdminUser();
$this->resetAfterTest(true);
$time = time();
$outage = new outage([
@@ -142,9 +116,8 @@ class calendar_test extends advanced_testcase {
* Try to delete a non existing outage.
*/
public function test_delete_notfound() {
$this->resetAfterTest(true);
self::setAdminUser();
$this->resetAfterTest(true);
calendar::delete(1);
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();

View File

@@ -57,7 +57,7 @@ class events_test extends advanced_testcase {
public function test_save() {
global $DB;
self::setAdminUser();
$this->resetAfterTest(true);
$this->resetAfterTest(false);
// Save new outage.
$now = time();
@@ -90,20 +90,7 @@ class events_test extends advanced_testcase {
global $DB;
self::setAdminUser();
$this->resetAfterTest(true);
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
'title' => 'Title',
'description' => 'Description',
]);
$outage->id = outagedb::save($outage);
self::$outage = $outage;
$this->resetAfterTest(false);
self::$outage->starttime += 10;
outagedb::save(self::$outage);
@@ -130,19 +117,6 @@ class events_test extends advanced_testcase {
self::setAdminUser();
$this->resetAfterTest(true);
// Save new outage.
$now = time();
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
'title' => 'Title',
'description' => 'Description',
]);
$outage->id = outagedb::save($outage);
self::$outage = $outage;
outagedb::delete(self::$outage->id);
// Should not exist.

View File

@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
require_once(__DIR__.'/../base_testcase.php');
/**
* outagelib_test test class.
*
@@ -41,7 +41,7 @@ require_once(__DIR__.'/../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class outagelib_test extends auth_outage_base_testcase {
class outagelib_test extends advanced_testcase {
/**
* Check if maintenance message is disabled as needed.
*/
@@ -105,8 +105,6 @@ class outagelib_test extends auth_outage_base_testcase {
$size = strlen($CFG->additionalhtmltopofbody);
outagelib::inject();
self::assertSame($size, strlen($CFG->additionalhtmltopofbody));
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
}
/**
@@ -142,8 +140,6 @@ class outagelib_test extends auth_outage_base_testcase {
outagelib::reinject();
self::assertContains('<style>', $CFG->additionalhtmltopofbody);
self::assertContains('<script>', $CFG->additionalhtmltopofbody);
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
}
/**
@@ -293,8 +289,7 @@ class outagelib_test extends auth_outage_base_testcase {
if ((time() >= 123) && (time() < 456)) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('heyyou
if (!remoteip_in_list('hey\'\"you
a.b.c.d
e.e.e.e/20')) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
@@ -334,7 +329,6 @@ EOT;
if ((time() >= 123) && (time() < 456)) {
define('MOODLE_INTERNAL', true);
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
if (!remoteip_in_list('127.0.0.1')) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
header('Status: 503 Moodle under maintenance');
@@ -505,8 +499,6 @@ EOT;
outagelib::reinject();
self::assertNotEmpty($CFG->additionalhtmltopofbody);
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
}
private function create_outage() {

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2018062500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.9'; // Human-readable release information.
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 3.0 or later recommended.
$plugin->version = 2019022200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.10'; // Human-readable release information.
$plugin->requires = 2017051500; // Requires 3.3 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!

View File

@@ -7,7 +7,7 @@ If you need to make changes here, remember to update your settings inside Moodle
background-color: red;
box-sizing: content-box;
color: white;
height: 90px;
height: 100px;
left: 0;
padding: 0;
position: fixed;
@@ -19,47 +19,51 @@ If you need to make changes here, remember to update your settings inside Moodle
}
#auth_outage_warningbar_box.auth_outage_warning_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#ff7c00,
#ff7c00 10px,
#ff6c00 10px,
#ff6c00 20px
);
);
background-color: #ff7c00;
}
#auth_outage_warningbar_box.auth_outage_imminent_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#a000a0,
#a000a0 10px,
#800080 10px,
#800080 20px
);
);
background-color: #800080;
}
#auth_outage_warningbar_box.auth_outage_ongoing_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#ee0000,
#ee0000 10px,
#cc0000 10px,
#cc0000 20px
);
background-color: #ee0000;
#e00,
#e00 10px,
#c00 10px,
#c00 20px
);
background-color: #e00;
}
#auth_outage_warningbar_box.auth_outage_finished_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#00aa00,
#00aa00 10px,
#009900 10px,
#009900 20px
);
background-color: #009900;
#0a0,
#0a0 10px,
#090 10px,
#090 20px
);
background-color: #090;
}
.auth_outage_warningbar_center {
@@ -95,10 +99,14 @@ a.auth_outage_warningbar_box_finish:hover {
background-color: black;
}
.navbar.navbar-fixed-top {
top: 90px;
}
.auth_outage_warningbar_spacer {
height: 80px;
}
body.auth_outage #nav-drawer {
top: 150px;
}
body.auth_outage nav.fixed-top.navbar {
top: 100px;
}

View File

@@ -114,8 +114,10 @@ var authOutageWarningBar = {
seconds2hms: function(seconds) {
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
seconds %= 60;
minutes %= 60;
hours %= 24;
// Cross-browser simple solution for padding zeroes.
if (minutes < 10) {
minutes = "0" + minutes;
@@ -123,6 +125,15 @@ var authOutageWarningBar = {
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds;
if (days > 0) {
if (days > 1) {
days = days + ' days ';
} else {
days = days + ' day ';
}
} else {
days = '';
}
return days + hours + ':' + minutes + ':' + seconds;
}
};

View File

@@ -48,7 +48,7 @@ if (!$viewbag['static']) {
if (is_siteadmin()) {
$url = new moodle_url('/auth/outage/finish.php', ['id' => $viewbag['outage']->id]);
$text = html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'src' => $OUTPUT->image_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]).' '.get_string('finish', 'auth_outage');