diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index e70910bfbdc..8c8fe7f3258 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -149,6 +149,8 @@ class api { 'maintenancemessage' => $maintenancemessage, 'mobilecssurl' => !empty($CFG->mobilecssurl) ? $CFG->mobilecssurl : '', 'tool_mobile_disabledfeatures' => get_config('tool_mobile', 'disabledfeatures'), + 'country' => clean_param($CFG->country, PARAM_NOTAGS), + 'agedigitalconsentverification' => \core_auth\digital_consent::is_age_digital_consent_verification_enabled(), ); $typeoflogin = get_config('tool_mobile', 'typeoflogin'); @@ -180,6 +182,12 @@ class api { $settings['identityproviders'] = $identityprovidersdata; } + // If age is verified, return also the admin contact details. + if ($settings['agedigitalconsentverification']) { + $settings['supportname'] = clean_param($CFG->supportname, PARAM_NOTAGS); + $settings['supportemail'] = clean_param($CFG->supportemail, PARAM_EMAIL); + } + return $settings; } diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index d54d7480b66..65a5ccf1ad8 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -161,6 +161,13 @@ class external extends external_api { ), 'Identity providers', VALUE_OPTIONAL ), + 'country' => new external_value(PARAM_NOTAGS, 'Default site country', VALUE_OPTIONAL), + 'agedigitalconsentverification' => new external_value(PARAM_BOOL, 'Whether age digital consent verification + is enabled.', VALUE_OPTIONAL), + 'supportname' => new external_value(PARAM_NOTAGS, 'Site support contact name + (only if age verification is enabled).', VALUE_OPTIONAL), + 'supportemail' => new external_value(PARAM_EMAIL, 'Site support contact email + (only if age verification is enabled).', VALUE_OPTIONAL), 'warnings' => new external_warnings(), ) ); diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index ff1f3c1a829..de2fbe4e223 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -86,6 +86,8 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { 'mobilecssurl' => '', 'tool_mobile_disabledfeatures' => '', 'launchurl' => "$CFG->wwwroot/$CFG->admin/tool/mobile/launch.php", + 'country' => $CFG->country, + 'agedigitalconsentverification' => \core_auth\digital_consent::is_age_digital_consent_verification_enabled(), 'warnings' => array() ); $this->assertEquals($expected, $result); @@ -98,12 +100,16 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { set_config('logo', 'mock.png', 'core_admin'); set_config('logocompact', 'mock.png', 'core_admin'); set_config('forgottenpasswordurl', 'mailto:fake@email.zy'); // Test old hack. + set_config('agedigitalconsentverification', 1); list($authinstructions, $notusedformat) = external_format_text($authinstructions, FORMAT_MOODLE, $context->id); $expected['registerauth'] = 'email'; $expected['authinstructions'] = $authinstructions; $expected['typeoflogin'] = api::LOGIN_VIA_BROWSER; $expected['forgottenpasswordurl'] = ''; // Expect empty when it's not an URL. + $expected['agedigitalconsentverification'] = true; + $expected['supportname'] = $CFG->supportname; + $expected['supportemail'] = $CFG->supportemail; if ($logourl = $OUTPUT->get_logo_url()) { $expected['logourl'] = $logourl->out(false); diff --git a/auth/classes/external.php b/auth/classes/external.php index bc21cbc2afd..7c083494a9d 100644 --- a/auth/classes/external.php +++ b/auth/classes/external.php @@ -287,4 +287,53 @@ class core_auth_external extends external_api { ) ); } + + /** + * Describes the parameters for is_age_digital_consent_verification_enabled. + * + * @return external_function_parameters + * @since Moodle 3.3 + */ + public static function is_age_digital_consent_verification_enabled_parameters() { + return new external_function_parameters(array()); + } + + /** + * Checks if age digital consent verification is enabled. + * + * @return array status (true if digital consent verification is enabled, false otherwise.) + * @since Moodle 3.3 + * @throws moodle_exception + */ + public static function is_age_digital_consent_verification_enabled() { + global $PAGE; + + $context = context_system::instance(); + $PAGE->set_context($context); + + $status = false; + // Check if verification is enabled. + if (\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) { + $status = true; + } + + return array( + 'status' => $status + ); + } + + /** + * Describes the is_age_digital_consent_verification_enabled return value. + * + * @return external_single_structure + * @since Moodle 3.3 + */ + public static function is_age_digital_consent_verification_enabled_returns() { + return new external_single_structure( + array( + 'status' => new external_value(PARAM_BOOL, 'True if digital consent verification is enabled, + false otherwise.') + ) + ); + } } diff --git a/auth/tests/external_test.php b/auth/tests/external_test.php index f85f9a6a8f2..84ffa1f8daa 100644 --- a/auth/tests/external_test.php +++ b/auth/tests/external_test.php @@ -89,4 +89,30 @@ class core_auth_external_testcase extends externallib_advanced_testcase { $this->expectExceptionMessage(get_string('invalidconfirmdata', 'error')); $result = core_auth_external::confirm_user($username, 'zzZZzz'); } + + /** + * Test age digital consent not enabled. + */ + public function test_age_digital_consent_verification_is_not_enabled() { + global $CFG; + + $CFG->agedigitalconsentverification = 0; + $result = core_auth_external::is_age_digital_consent_verification_enabled(); + $result = external_api::clean_returnvalue( + core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result); + $this->assertFalse($result['status']); + } + + /** + * Test age digital consent is enabled. + */ + public function test_age_digital_consent_verification_is_enabled() { + global $CFG; + + $CFG->agedigitalconsentverification = 1; + $result = core_auth_external::is_age_digital_consent_verification_enabled(); + $result = external_api::clean_returnvalue( + core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result); + $this->assertTrue($result['status']); + } } diff --git a/lib/db/services.php b/lib/db/services.php index 8cdb154783b..35ba7f998cf 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -55,6 +55,15 @@ $functions = array( 'methodname' => 'is_minor', 'description' => 'Requests a check if a user is a digital minor.', 'type' => 'read', + 'ajax' => true, + 'loginrequired' => false, + ), + 'core_auth_is_age_digital_consent_verification_enabled' => array( + 'classname' => 'core_auth_external', + 'methodname' => 'is_age_digital_consent_verification_enabled', + 'description' => 'Checks if age digital consent verification is enabled.', + 'type' => 'read', + 'ajax' => true, 'loginrequired' => false, ), 'core_badges_get_user_badges' => array( diff --git a/version.php b/version.php index 4bc5313c426..ae94108c280 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2018030800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2018030800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.