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 d50900c4370..97b672c19fe 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 64d2914ce0b..be033489499 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017111301.09; // 20171113 = branching date YYYYMMDD - do not modify! +$version = 2017111301.10; // 20171113 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes.