Skip to content

Commit

Permalink
correction and adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Dec 6, 2024
1 parent e337d74 commit e1b1ef2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
25 changes: 20 additions & 5 deletions classes/local/maintenance_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,15 @@ public function can_access(string $method) {
public function decide_access_bounce() {
global $CFG, $COURSE, $SITE;
$wwwroot = $CFG->wwwroot;
if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) {
$wwwroot = $CFG->behat_wwwroot;
}
$wwwrootparsed = parse_url($wwwroot);
$iswebrequest = isset($_SERVER['REMOTE_ADDR']); // It is a web call when the REMOTE_ADDR is set in $_SERVER!

$isbahat = defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING;
$iscli = defined('CLI_SCRIPT') && CLI_SCRIPT;
$isphpunit = defined('PHPUNIT_TEST') && PHPUNIT_TEST;

// If it is a web request.
if ($iswebrequest) {
if ($iswebrequest && !$iscli && !$isphpunit) {
// We have to carefully decide whether to redirect back to the referer or the course page.
// The reason for this check is to avoid redirecting loops!
$referer = get_local_referer(false);
Expand All @@ -339,10 +340,24 @@ public function decide_access_bounce() {
$requesttarget = parse_url($initiator);
$tagetpath = $requesttarget['path'] ?? '';

// We handle behat test process right here before going further.
if ($isbahat) {
$behatredirectbackurl = $referer;
if (empty($behatredirectbackurl) && $COURSE && !empty($COURSE->id)) {
$behatredirectbackurl = new \moodle_url('/course/view.php', ['id' => $COURSE->id]);
}
if (!empty($behatredirectbackurl)) {
redirect($behatredirectbackurl);
} else {
throw new \moodle_exception('maintenance_exception_message', self::PLUGINNAME);
}
}

$whitelist = [];
$whitelist[] = $wwwrootparsed['path'];
$whitelist[] = $wwwrootparsed['path'] . '/course/view.php';
$whitelist[] = $wwwrootparsed['path'] . '/my';
$whitelist[] = $wwwrootparsed['path'] . '/course';

$blacklist = [];
$blacklist['block_opencast'] = $wwwrootparsed['path'] . '/blocks/opencast'; // Match for block_opencast plugin.
Expand Down Expand Up @@ -385,7 +400,7 @@ public function decide_access_bounce() {
close_window(0, true);
}

// If it is not yet returned, it has to throw an error.
// If it is not yet returned, it has to throw an error, this should also cover requests coming from unit tests.
throw new \moodle_exception('maintenance_exception_message', self::PLUGINNAME);
}

Expand Down
1 change: 1 addition & 0 deletions tests/behat/tool_opencast_maintenace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Feature: Configure and check maintenance
| maintenancemode_startdate_1 | {"enabled":false} | tool_opencast |
| maintenancemode_enddate_1 | {"enabled":false} | tool_opencast |
When I reload the page
And I wait "2" seconds
And I click on "Add video" "button"
Then I should see "Opencast Maintenance Notification" in the "#user-notifications" "css_element"
And I should not see "Videos available in this course" in the "#region-main" "css_element"
Expand Down

0 comments on commit e1b1ef2

Please sign in to comment.