diff --git a/admin/settings/server.php b/admin/settings/server.php index 75e72ed3a08..aee096179a3 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -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'), diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index 7c81fc76326..34fc568708e 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -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; } diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index 827001605d0..e04480979fe 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -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', 'test@test.com'); // 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', 'test@test.com'); $result = external::get_config(); $result = external_api::clean_returnvalue(external::get_config_returns(), $result); diff --git a/admin/tool/policy/classes/output/page_nopermission.php b/admin/tool/policy/classes/output/page_nopermission.php index 454bafd13cd..2191f81b7bc 100644 --- a/admin/tool/policy/classes/output/page_nopermission.php +++ b/admin/tool/policy/classes/output/page_nopermission.php @@ -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. diff --git a/auth/classes/output/digital_minor_page.php b/auth/classes/output/digital_minor_page.php index 411893eae64..0f746489a5a 100644 --- a/auth/classes/output/digital_minor_page.php +++ b/auth/classes/output/digital_minor_page.php @@ -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, diff --git a/lang/en/admin.php b/lang/en/admin.php index cca2cfc8786..5fa2ff0be2c 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -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'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 09bed520984..37708863a60 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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. * diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index ae615de6b6b..6397f2c3d00 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -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', 'noreply@example.com'); + // Set the support email address. + set_config('supportemail', 'email@example.com'); + // Remove any default blocked hosts and port restrictions, to avoid blocking tests (eg those using local files). set_config('curlsecurityblockedhosts', ''); set_config('curlsecurityallowedport', ''); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 3e4b2f43ed9..cb70bea7dec 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/version.php b/version.php index 4f5d2245fde..92d9753048c 100644 --- a/version.php +++ b/version.php @@ -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