MDL-72984 admin: make support email setting mandatory

This commit is contained in:
Simey Lameze
2021-12-20 13:22:35 +08:00
parent 58a729f088
commit eadf157068
10 changed files with 50 additions and 9 deletions
+2 -4
View File
@@ -48,17 +48,15 @@ if ($hassiteconfig) {
$temp = new admin_settingpage('supportcontact', new lang_string('supportcontact', 'admin'));
$primaryadmin = get_admin();
if ($primaryadmin) {
$primaryadminemail = $primaryadmin->email;
$primaryadminname = fullname($primaryadmin, true);
} else {
// No defaults during installation - admin user must be created first.
$primaryadminemail = null;
$primaryadminname = null;
}
$temp->add(new admin_setting_configtext('supportname', new lang_string('supportname', 'admin'),
new lang_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
$setting = new admin_setting_configtext('supportemail', new lang_string('supportemail', 'admin'),
new lang_string('configsupportemail', 'admin'), $primaryadminemail, PARAM_EMAIL);
$setting = new admin_setting_requiredtext('supportemail', new lang_string('supportemail', 'admin'),
new lang_string('configsupportemail', 'admin'), null, PARAM_EMAIL);
$setting->set_force_ltr(true);
$temp->add($setting);
$temp->add(new admin_setting_configtext('supportpage', new lang_string('supportpage', 'admin'),
+1 -1
View File
@@ -326,7 +326,7 @@ class api {
if (empty($section) or $section == 'supportcontact') {
$settings->supportname = $CFG->supportname;
$settings->supportemail = $CFG->supportemail;
$settings->supportemail = $CFG->supportemail ?? null;
$settings->supportpage = $CFG->supportpage;
}
@@ -118,6 +118,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
set_config('lang', 'a_b'); // Set invalid lang.
set_config('disabledfeatures', 'myoverview', 'tool_mobile');
set_config('minimumversion', '3.8.0', 'tool_mobile');
set_config('supportemail', '[email protected]');
// Enable couple of issuers.
$issuer = \core\oauth2\api::create_standard_issuer('google');
@@ -186,6 +187,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
$mysitepolicy = 'http://mysite.is/policy/';
set_config('sitepolicy', $mysitepolicy);
set_config('supportemail', '[email protected]');
$result = external::get_config();
$result = external_api::clean_returnvalue(external::get_config_returns(), $result);
@@ -132,7 +132,7 @@ class page_nopermission implements renderable, templatable {
'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false),
'haspermissionagreedocs' => $this->haspermissionagreedocs,
'supportname' => $CFG->supportname,
'supportemail' => $CFG->supportemail,
'supportemail' => $CFG->supportemail ?? null,
];
// Get the messages to display.
+1 -1
View File
@@ -49,7 +49,7 @@ class digital_minor_page implements renderable, templatable {
$sitename = format_string($SITE->fullname);
$supportname = $CFG->supportname;
$supportemail = $CFG->supportemail;
$supportemail = $CFG->supportemail ?? null;
$context = [
'sitename' => $sitename,
+2 -1
View File
@@ -374,7 +374,7 @@ $string['configstatsruntimestart'] = 'What time should the cronjob that does the
$string['configstatsuserthreshold'] = 'This setting specifies the minimum number of enrolled users for a course to be included in statistics calculations.';
$string['configstrictformsrequired'] = 'If enabled, users are prevented from entering a space or line break only in required fields in forms.';
$string['configstripalltitletags'] = 'Uncheck this setting to allow HTML tags in activity and resource names.';
$string['configsupportemail'] = 'This email address will be published to users of this site as the one to email when they need general help (for example, when new users create their own accounts). If this email is left blank then no such helpful email address is supplied.';
$string['configsupportemail'] = 'This email address will be published to users of this site as the one to email when they need general help (for example, when new users create their own accounts).';
$string['configsupportname'] = 'This is the name of a person or other entity offering general help via the support email or web address.';
$string['configsupportpage'] = 'This web address will be published to users of this site as the one to go to when they need general help (for example, when new users create their own accounts). If this address is left blank then no link will be supplied.';
$string['configtempdatafoldercleanup'] = 'Remove temporary data files from the data folder that are older than the selected time.';
@@ -396,6 +396,7 @@ $string['confirmcontextlock'] = '{$a->contextname} is currently unfrozen. Freezi
$string['confirmcontextunlock'] = '{$a->contextname} is currently frozen. Unfreezing it will allow users to make changes. Are you sure you wish to continue?';
$string['confirmdeletecomments'] = 'You are about to delete comments, are you sure?';
$string['confirmed'] = 'Confirmed';
$string['contactsitesupport'] = 'Contact site support';
$string['contextlocking'] = 'Context freezing';
$string['contextlocking_desc'] = 'This setting enables read-only access to be set for selected categories, courses, activities or blocks.';
$string['contextlockappliestoadmin'] = 'Context freezing applies to administrators';
+23
View File
@@ -4838,6 +4838,29 @@ class admin_setting_sitesettext extends admin_setting_configtext {
}
/**
* This type of field should be used for mandatory config settings.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_requiredtext extends admin_setting_configtext {
/**
* Validate data before storage.
*
* @param string $data The string to be validated.
* @return bool|string true for success or error string if invalid.
*/
public function validate($data) {
$cleaned = clean_param($data, PARAM_TEXT);
if ($cleaned === '') {
return get_string('required');
}
return parent::validate($data);
}
}
/**
* Special text editor for site description.
*
+3
View File
@@ -125,6 +125,9 @@ class behat_util extends testing_util {
// Set noreplyaddress to an example domain, as it should be valid email address and test site can be a localhost.
set_config('noreplyaddress', '[email protected]');
// Set the support email address.
set_config('supportemail', '[email protected]');
// Remove any default blocked hosts and port restrictions, to avoid blocking tests (eg those using local files).
set_config('curlsecurityblockedhosts', '');
set_config('curlsecurityallowedport', '');
+14
View File
@@ -3199,5 +3199,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021121400.01);
}
if ($oldversion < 2021121700.01) {
// Get current support email setting value.
$config = get_config('moodle', 'supportemail');
// Check if support email setting is empty and then set it to null.
// We must do that so the setting is displayed during the upgrade.
if (empty($config)) {
set_config('supportemail', null);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2021121700.01);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021121700.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021121700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev+ (Build: 20211217)'; // Human-friendly version name