From 2b3c4538f1661673e221ac706b0f901a13c04567 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 16 Apr 2018 13:43:23 +0800 Subject: [PATCH] MDL-61920 ltiservice_gradebookservices: implement privacy provider --- .../classes/privacy/provider.php | 94 +++++++++++++++++++ .../lang/en/ltiservice_gradebookservices.php | 6 ++ .../tests/privacy_provider_test.php | 51 ++++++++++ 3 files changed, 151 insertions(+) create mode 100644 mod/lti/service/gradebookservices/classes/privacy/provider.php create mode 100644 mod/lti/service/gradebookservices/tests/privacy_provider_test.php diff --git a/mod/lti/service/gradebookservices/classes/privacy/provider.php b/mod/lti/service/gradebookservices/classes/privacy/provider.php new file mode 100644 index 00000000000..878fe6bd991 --- /dev/null +++ b/mod/lti/service/gradebookservices/classes/privacy/provider.php @@ -0,0 +1,94 @@ +. + +/** + * Privacy Subsystem implementation for ltiservice_gradebookservices. + * + * @package ltiservice_gradebookservices + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace ltiservice_gradebookservices\privacy; + +use \core_privacy\local\metadata\collection; +use \core_privacy\local\request\contextlist; +use \core_privacy\local\request\approved_contextlist; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for ltiservice_gradebookservices. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements + \core_privacy\local\metadata\provider, + \core_privacy\local\request\plugin\provider { + + /** + * Returns meta data about this system. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ + public static function get_metadata(collection $collection) : collection { + $collection->link_external_location('External LTI provider.', [ + 'userid' => 'privacy:metadata:userid', + 'grade' => 'privacy:metadata:grade', + 'maxgrade' => 'privacy:metadata:maxgrade', + 'feedback' => 'privacy:metadata:feedback', + 'timemodified' => 'privacy:metadata:timemodified' + ], 'privacy:metadata:externalpurpose'); + + return $collection; + } + + /** + * Get the list of contexts that contain user information for the specified user. + * + * @param int $userid The user to search. + * @return contextlist The contextlist containing the list of contexts used in this plugin. + */ + public static function get_contexts_for_userid(int $userid) : contextlist { + return new contextlist(); + } + + /** + * Export all user data for the specified user, in the specified contexts. + * + * @param approved_contextlist $contextlist The approved contexts to export information for. + */ + public static function export_user_data(approved_contextlist $contextlist) { + } + + /** + * Delete all user data which matches the specified context. + * + * @param \context $context A user context. + */ + public static function delete_data_for_all_users_in_context(\context $context) { + } + + /** + * Delete all user data for the specified user, in the specified contexts. + * + * @param approved_contextlist $contextlist The approved contexts and user information to delete information for. + */ + public static function delete_data_for_user(approved_contextlist $contextlist) { + } +} diff --git a/mod/lti/service/gradebookservices/lang/en/ltiservice_gradebookservices.php b/mod/lti/service/gradebookservices/lang/en/ltiservice_gradebookservices.php index e68fdc5366f..7d9a5d149d0 100644 --- a/mod/lti/service/gradebookservices/lang/en/ltiservice_gradebookservices.php +++ b/mod/lti/service/gradebookservices/lang/en/ltiservice_gradebookservices.php @@ -34,5 +34,11 @@ $string['modulename'] = 'LTI Grades'; $string['nevergs'] = 'Do not use this service'; $string['partialgs'] = 'Use this service for grade sync only'; $string['pluginname'] = 'LTI Assignment and Grade Services'; +$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external LTI provider.'; +$string['privacy:metadata:feedback'] = 'The feedback the user received for this LTI activity.'; +$string['privacy:metadata:grade'] = 'The grade the user received in Moodle for this LTI activity.'; +$string['privacy:metadata:maxgrade'] = 'The max grade that can be achieved for this LTI activity.'; +$string['privacy:metadata:timemodified'] = 'The last time the grade was updated'; +$string['privacy:metadata:userid'] = 'The ID of the user using the LTI consumer.'; $string['servicename'] = 'LTI Assignment and Grade Services'; $string['taskcleanup'] = 'LTI Assignment and Grade Services table cleanup'; diff --git a/mod/lti/service/gradebookservices/tests/privacy_provider_test.php b/mod/lti/service/gradebookservices/tests/privacy_provider_test.php new file mode 100644 index 00000000000..d24c59c8f12 --- /dev/null +++ b/mod/lti/service/gradebookservices/tests/privacy_provider_test.php @@ -0,0 +1,51 @@ +. +/** + * Unit tests for ltiservice_gradebookservices privacy provider. + * + * @package ltiservice_gradebookservices + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +use \core_privacy\tests\provider_testcase; + +/** + * Unit tests for ltiservice_gradebookservices privacy provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class ltiservice_gradebookservices_privacy_provider_testcase extends provider_testcase { + + /** + * Basic setup for these tests. + */ + public function setUp() { + $this->resetAfterTest(true); + } + + /** + * Test getting the context for the user ID related to this plugin. + */ + public function test_get_contexts_for_userid() { + $user = $this->getDataGenerator()->create_user(); + $contextlist = \ltiservice_gradebookservices\privacy\provider::get_contexts_for_userid($user->id); + $this->assertEmpty($contextlist); + } +}