Issue #288: Split allowed IPs settings into two.

Merge two settings when accessing config.
Bump version.
This commit is contained in:
Jason den Dulk
2022-04-28 09:47:58 +10:00
parent afc96d347d
commit c64a33c345
5 changed files with 35 additions and 5 deletions

View File

@@ -168,7 +168,12 @@ class outagelib {
}
}
return (object)array_merge(self::get_config_defaults(), $config);
$config = array_merge(self::get_config_defaults(), $config);
// Combine allowed IPs config values together.
if (isset($config['allowedips_forced'])) {
$config['allowedips'] = trim($config['allowedips'] . "\n" . $config['allowedips_forced']);
}
return (object)$config;
}
/**

View File

@@ -158,6 +158,10 @@ $string['warningduration'] = 'Warning duration';
$string['warningduration_help'] = 'How long before the start of the outage should the warning be displayed.';
$string['warningreenablemaintenancemode'] = 'Please note that saving this outage will re-enable maintenance mode.<br />Untick "Auto start maintenance mode" if you want to prevent this.';
$string['builtinallowediplist'] = 'Builtin Allowed IP List';
$string['builtinallowediplist_desc'] = 'Allowed IP list defined via configuration';
$string['ips_combine'] = 'The IPs listed above will be combined with the IPs listed below.';
/*
* Privacy provider (GDPR)
*/

View File

@@ -110,6 +110,8 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
$description .= '<p>'.get_string('ipblockersyntax', 'admin').'</p>';
$description .= '<p>'.get_string('ips_combine', 'auth_outage').'</p>';
$iplist = new admin_setting_configiplist(
'auth_outage/allowedips',
get_string('allowediplist', 'admin'),
@@ -119,6 +121,14 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$iplist->set_updatedcallback('auth_outage_outagelib_prepare_next_outage');
$settings->add($iplist);
$iplist = new admin_setting_configiplist(
'auth_outage/allowedips_forced',
get_string('builtinallowediplist', 'auth_outage'),
get_string('builtinallowediplist_desc', 'auth_outage'),
''
);
$settings->add($iplist);
// Create 'Static Page - Elements to Remove' settings.
$toremove = new admin_setting_configtextarea(
'auth_outage/remove_selectors',

View File

@@ -216,6 +216,10 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
foreach ($keys as $k) {
self::assertSame($config->$k, $k.'_value', 'auth_outage');
}
set_config('allowedips_forced', 'allowedips_forced_value', 'auth_outage');
$config = outagelib::get_config();
self::assertSame($config->allowedips, "allowedips_value\nallowedips_forced_value", 'auth_outage');
}
/**
@@ -336,8 +340,10 @@ EOT;
/**
* Test create maintenance php code without age
*
* @dataProvider test_createmaintenancephpcode_withoutage_provider
*/
public function test_createmaintenancephpcode_withoutage() {
public function test_createmaintenancephpcode_withoutage($configkey) {
global $CFG;
$this->resetAfterTest(true);
@@ -380,7 +386,7 @@ EOT;
'stoptime' => 456,
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config('allowedips', '127.0.0.1', 'auth_outage');
set_config($configkey, '127.0.0.1', 'auth_outage');
outagelib::update_climaintenance_code($outage);
self::assertFileExists($file);
@@ -388,6 +394,10 @@ EOT;
self::assertSame($found, $expected);
}
public function test_createmaintenancephpcode_withoutage_provider(): array {
return [['allowedips'], ['allowedips_forced']];
}
/**
* Test create maintenance php code without IPs
*/
@@ -401,6 +411,7 @@ EOT;
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config('allowedips', '', 'auth_outage');
set_config('allowedips_forced', '', 'auth_outage');
touch($file);
outagelib::update_climaintenance_code($outage);

View File

@@ -28,8 +28,8 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2022011400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022011400; // Human-readable release information.
$plugin->version = 2022042800; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022042800; // Human-readable release information.
$plugin->requires = 2017111309; // 2017111309 = T13, but this really requires 3.9 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
$plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.