From b4d2fc163d4eb4c39bd1ce912f8df30341122453 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 16 Sep 2020 18:42:42 +0200 Subject: [PATCH] MDL-68845 calendar: New WS get_calendar_export_token --- calendar/classes/external/export/token.php | 99 ++++++++++++++++++++++ lib/db/services.php | 7 ++ version.php | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 calendar/classes/external/export/token.php diff --git a/calendar/classes/external/export/token.php b/calendar/classes/external/export/token.php new file mode 100644 index 00000000000..9c530a01989 --- /dev/null +++ b/calendar/classes/external/export/token.php @@ -0,0 +1,99 @@ +. + +/** + * This is the external method for exporting a calendar token. + * + * @package core_calendar + * @since Moodle 3.10 + * @copyright 2020 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_calendar\external\export; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->libdir . '/externallib.php'); +require_once($CFG->dirroot . '/calendar/lib.php'); + +use context_system; +use external_api; +use external_function_parameters; +use external_multiple_structure; +use external_single_structure; +use external_value; +use external_warnings; +use moodle_exception; + +/** + * This is the external method for exporting a calendar token. + * + * @copyright 2020 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class token extends external_api { + + /** + * Returns description of method parameters. + * + * @return external_function_parameters. + * @since Moodle 3.10 + */ + public static function execute_parameters() { + return new external_function_parameters([]); + } + + /** + * Return the auth token required for exporting a calendar. + * + * @return array The access information + * @throws moodle_exception + * @since Moodle 3.10 + */ + public static function execute() { + global $CFG, $USER; + + $context = context_system::instance(); + self::validate_context($context); + + if (empty($CFG->enablecalendarexport)) { + throw new moodle_exception('Calendar export is disabled in this site.'); + } + + return [ + 'token' => calendar_get_export_token($USER), + 'warnings' => [], + ]; + } + + /** + * Returns description of method result value. + * + * @return external_description. + * @since Moodle 3.10 + */ + public static function execute_returns() { + + return new external_single_structure( + [ + 'token' => new external_value(PARAM_RAW, 'The calendar permanent access token for calendar export.'), + 'warnings' => new external_warnings(), + ] + ); + } +} diff --git a/lib/db/services.php b/lib/db/services.php index 94f0c0d1701..c5892215f18 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -287,6 +287,13 @@ $functions = array( 'type' => 'read', 'ajax' => true, ], + 'core_calendar_get_calendar_export_token' => [ + 'classname' => 'core_calendar\external\export\token', + 'methodname' => 'execute', + 'description' => 'Return the auth token required for exporting a calendar.', + 'type' => 'read', + 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), + ], 'core_cohort_add_cohort_members' => array( 'classname' => 'core_cohort_external', 'methodname' => 'add_cohort_members', diff --git a/version.php b/version.php index 3c05ae92567..6df7210821b 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021052500.16; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2021052500.17; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20200924)'; // Human-friendly version name