From 336d8c5fabe6bbc055b46906c44f3ab11b1b25d0 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Mon, 17 Oct 2022 15:49:33 +0800 Subject: [PATCH] MDL-74643 tool_mobile: Update API to support supportavailability config Co-authored-by: Juan Leyva --- admin/tool/mobile/classes/api.php | 24 +++++++++++++++----- admin/tool/mobile/classes/external.php | 2 ++ admin/tool/mobile/tests/externallib_test.php | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index ea9a13708eb..78803c5df71 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -167,6 +167,9 @@ class api { // We need this to make work the format text functions. $PAGE->set_context($context); + // Check if contacting site support is available to all visitors. + $sitesupportavailable = (isset($CFG->supportavailability) && $CFG->supportavailability == CONTACT_SUPPORT_ANYONE); + list($authinstructions, $notusedformat) = external_format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id); list($maintenancemessage, $notusedformat) = external_format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id); $settings = array( @@ -198,7 +201,8 @@ class api { 'tool_mobile_androidappid' => get_config('tool_mobile', 'androidappid'), 'tool_mobile_setuplink' => clean_param(get_config('tool_mobile', 'setuplink'), PARAM_URL), 'tool_mobile_qrcodetype' => clean_param(get_config('tool_mobile', 'qrcodetype'), PARAM_INT), - 'supportpage' => clean_param($CFG->supportpage, PARAM_URL), + 'supportpage' => $sitesupportavailable ? clean_param($CFG->supportpage, PARAM_URL) : '', + 'supportavailability' => clean_param($CFG->supportavailability, PARAM_INT), ); $typeoflogin = get_config('tool_mobile', 'typeoflogin'); @@ -236,8 +240,8 @@ class api { } } - // If age is verified, return also the admin contact details. - if ($settings['agedigitalconsentverification']) { + // If age is verified or support is available to all visitors, also return the admin contact details. + if ($settings['agedigitalconsentverification'] || $sitesupportavailable) { $settings['supportname'] = clean_param($CFG->supportname, PARAM_NOTAGS); $settings['supportemail'] = clean_param($CFG->supportemail, PARAM_EMAIL); } @@ -330,9 +334,17 @@ class api { } if (empty($section) or $section == 'supportcontact') { - $settings->supportname = $CFG->supportname; - $settings->supportemail = $CFG->supportemail ?? null; - $settings->supportpage = $CFG->supportpage; + $settings->supportavailability = $CFG->supportavailability; + + if ($CFG->supportavailability == CONTACT_SUPPORT_DISABLED) { + $settings->supportname = null; + $settings->supportemail = null; + $settings->supportpage = null; + } else { + $settings->supportname = $CFG->supportname; + $settings->supportemail = $CFG->supportemail ?? null; + $settings->supportpage = $CFG->supportpage; + } } if (empty($section) || $section === 'graceperiodsettings') { diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index 7d5120c4969..f9e56a57b1c 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -175,6 +175,8 @@ class external extends external_api { 'supportemail' => new external_value(PARAM_EMAIL, 'Site support contact email (only if age verification is enabled).', VALUE_OPTIONAL), 'supportpage' => new external_value(PARAM_URL, 'Site support page link.', VALUE_OPTIONAL), + 'supportavailability' => new external_value(PARAM_INT, 'Determines who has access to contact site support.', + VALUE_OPTIONAL), 'autolang' => new external_value(PARAM_INT, 'Whether to detect default language from browser setting.', VALUE_OPTIONAL), 'lang' => new external_value(PARAM_LANG, 'Default language for the site.', VALUE_OPTIONAL), diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index 8394821446a..9e7a02e44e2 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -92,6 +92,7 @@ class externallib_test extends externallib_advanced_testcase { 'tool_mobile_setuplink' => get_config('tool_mobile', 'setuplink'), 'tool_mobile_qrcodetype' => get_config('tool_mobile', 'qrcodetype'), 'supportpage' => $CFG->supportpage, + 'supportavailability' => $CFG->supportavailability, 'warnings' => array() ); $this->assertEquals($expected, $result); @@ -111,6 +112,7 @@ class externallib_test extends externallib_advanced_testcase { set_config('disabledfeatures', 'myoverview', 'tool_mobile'); set_config('minimumversion', '3.8.0', 'tool_mobile'); set_config('supportemail', 'test@test.com'); + set_config('supportavailability', CONTACT_SUPPORT_ANYONE); // Enable couple of issuers. $issuer = \core\oauth2\api::create_standard_issuer('google'); @@ -132,6 +134,7 @@ class externallib_test extends externallib_advanced_testcase { $expected['agedigitalconsentverification'] = true; $expected['supportname'] = $CFG->supportname; $expected['supportemail'] = $CFG->supportemail; + $expected['supportavailability'] = $CFG->supportavailability; $expected['autolang'] = '1'; $expected['lang'] = ''; // Expect empty because it was set to an invalid lang. $expected['tool_mobile_disabledfeatures'] = 'myoverview'; @@ -226,6 +229,7 @@ class externallib_test extends externallib_advanced_testcase { 'value' => get_config('core_admin', 'coursecolor' . $number) ]; } + $expected[] = ['name' => 'supportavailability', 'value' => $CFG->supportavailability]; $expected[] = ['name' => 'supportname', 'value' => $CFG->supportname]; $expected[] = ['name' => 'supportemail', 'value' => $CFG->supportemail]; $expected[] = ['name' => 'supportpage', 'value' => $CFG->supportpage];