From 4b8d462ee6771985cded62bf8c996eaf901bef75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 27 Apr 2018 11:14:11 +0200 Subject: [PATCH] MDL-61905 workshop: Implement privacy API in assessment allocators Assessment allocation methods normally do not store any personal data. Their duty is to create assessment records that are then exported by the workshop core itself. Still, some allocators (such as the Manual allocation) can store certain personal data such as user preferences. --- .../manual/classes/privacy/provider.php | 68 ++++++++++++++++++ .../lang/en/workshopallocation_manual.php | 1 + .../manual/tests/privacy_provider_test.php | 69 +++++++++++++++++++ .../random/classes/privacy/provider.php | 46 +++++++++++++ .../lang/en/workshopallocation_random.php | 1 + .../scheduled/classes/privacy/provider.php | 46 +++++++++++++ .../lang/en/workshopallocation_scheduled.php | 1 + 7 files changed, 232 insertions(+) create mode 100644 mod/workshop/allocation/manual/classes/privacy/provider.php create mode 100644 mod/workshop/allocation/manual/tests/privacy_provider_test.php create mode 100644 mod/workshop/allocation/random/classes/privacy/provider.php create mode 100644 mod/workshop/allocation/scheduled/classes/privacy/provider.php diff --git a/mod/workshop/allocation/manual/classes/privacy/provider.php b/mod/workshop/allocation/manual/classes/privacy/provider.php new file mode 100644 index 00000000000..d732ba5b7ac --- /dev/null +++ b/mod/workshop/allocation/manual/classes/privacy/provider.php @@ -0,0 +1,68 @@ +. + +/** + * Provides the class {@link workshopallocation_manual\privacy\provider} + * + * @package workshopallocation_manual + * @category privacy + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace workshopallocation_manual\privacy; + +use core_privacy\local\metadata\collection; +use core_privacy\local\request\writer; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy API implementation for the Manual allocation method. + * + * @copyright 2018 David Mudrák + * @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\user_preference_provider { + + /** + * Describe all the places where this plugin stores some personal data. + * + * @param collection $collection Collection of items to add metadata to. + * @return collection Collection with our added items. + */ + public static function get_metadata(collection $collection) : collection { + + $collection->add_user_preference('workshopallocation_manual_perpage', 'privacy:metadata:preference:perpage'); + + return $collection; + } + + /** + * Export user preferences controlled by this plugin. + * + * @param int $userid ID of the user we are exporting data form. + */ + public static function export_user_preferences(int $userid) { + + $perpage = get_user_preferences('workshopallocation_manual_perpage', null, $userid); + + if ($perpage !== null) { + writer::export_user_preference('workshopallocation_manual', 'workshopallocation_manual_perpage', $perpage, + get_string('privacy:metadata:preference:perpage', 'workshopallocation_manual')); + } + } +} diff --git a/mod/workshop/allocation/manual/lang/en/workshopallocation_manual.php b/mod/workshop/allocation/manual/lang/en/workshopallocation_manual.php index 829c37262f0..69365e39229 100644 --- a/mod/workshop/allocation/manual/lang/en/workshopallocation_manual.php +++ b/mod/workshop/allocation/manual/lang/en/workshopallocation_manual.php @@ -31,4 +31,5 @@ $string['allocationexists'] = 'The allocation already exists'; $string['areyousuretodeallocate'] = 'Are you sure you want deallocate the selected assessment?'; $string['areyousuretodeallocategraded'] = 'You are going to remove the assessment that has already been graded. Are you really sure you want to do it?'; $string['pluginname'] = 'Manual allocation'; +$string['privacy:metadata:preference:perpage'] = 'Number of allocated assessments the user prefers to see on one page.'; $string['showallparticipants'] = 'Show all participants'; diff --git a/mod/workshop/allocation/manual/tests/privacy_provider_test.php b/mod/workshop/allocation/manual/tests/privacy_provider_test.php new file mode 100644 index 00000000000..39faa4c9706 --- /dev/null +++ b/mod/workshop/allocation/manual/tests/privacy_provider_test.php @@ -0,0 +1,69 @@ +. + +/** + * Provides the {@link workshopallocation_manual_privacy_provider_testcase} class. + * + * @package workshopallocation_manual + * @category test + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use core_privacy\local\request\writer; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Unit tests for the privacy API implementation. + * + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class workshopallocation_manual_privacy_provider_testcase extends \core_privacy\tests\provider_testcase { + + /** + * When no preference exists, there should be no export. + */ + public function test_no_preference() { + global $USER; + $this->resetAfterTest(); + $this->setAdminUser(); + + \workshopallocation_manual\privacy\provider::export_user_preferences($USER->id); + $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data()); + } + + /** + * Test that the recently selected perpage is exported. + */ + public function test_export_preferences() { + global $USER; + $this->resetAfterTest(); + $this->setAdminUser(); + + set_user_preference('workshopallocation_manual_perpage', 81); + + \workshopallocation_manual\privacy\provider::export_user_preferences($USER->id); + $this->assertTrue(writer::with_context(\context_system::instance())->has_any_data()); + + $prefs = writer::with_context(\context_system::instance())->get_user_preferences('workshopallocation_manual'); + $this->assertNotEmpty($prefs->workshopallocation_manual_perpage); + $this->assertEquals(81, $prefs->workshopallocation_manual_perpage->value); + $this->assertContains(get_string('privacy:metadata:preference:perpage', 'workshopallocation_manual'), + $prefs->workshopallocation_manual_perpage->description); + } +} diff --git a/mod/workshop/allocation/random/classes/privacy/provider.php b/mod/workshop/allocation/random/classes/privacy/provider.php new file mode 100644 index 00000000000..b84b420fa66 --- /dev/null +++ b/mod/workshop/allocation/random/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Provides the class {@link workshopallocation_random\privacy\provider} + * + * @package workshopallocation_random + * @category privacy + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace workshopallocation_random\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy API implementation for the Random allocation method. + * + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Explain that this plugin stores no personal data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/mod/workshop/allocation/random/lang/en/workshopallocation_random.php b/mod/workshop/allocation/random/lang/en/workshopallocation_random.php index 86578ccae57..1a594f4a545 100644 --- a/mod/workshop/allocation/random/lang/en/workshopallocation_random.php +++ b/mod/workshop/allocation/random/lang/en/workshopallocation_random.php @@ -43,6 +43,7 @@ $string['numofselfallocatedsubmissions'] = 'Self-allocating {$a} submission(s)'; $string['numperauthor'] = 'per submission'; $string['numperreviewer'] = 'per reviewer'; $string['pluginname'] = 'Random allocation'; +$string['privacy:metadata'] = 'The Random allocation plugin does not store any personal data. Actual personal data about who is going to assess whom are stored by the Workshop module itself and they form basis for exporting the assessments details.'; $string['randomallocationdone'] = 'Random allocation done'; $string['resultnomorepeers'] = 'No more peers available'; $string['resultnomorepeersingroup'] = 'No more peers available in this separate group'; diff --git a/mod/workshop/allocation/scheduled/classes/privacy/provider.php b/mod/workshop/allocation/scheduled/classes/privacy/provider.php new file mode 100644 index 00000000000..b94fcc805ff --- /dev/null +++ b/mod/workshop/allocation/scheduled/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Provides the class {@link workshopallocation_scheduled\privacy\provider} + * + * @package workshopallocation_scheduled + * @category privacy + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace workshopallocation_scheduled\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy API implementation for the Scheduled allocation method. + * + * @copyright 2018 David Mudrák + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Explain that this plugin stores no personal data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php b/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php index 4d95c3720c3..27d7a74caf3 100644 --- a/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php +++ b/mod/workshop/allocation/scheduled/lang/en/workshopallocation_scheduled.php @@ -47,6 +47,7 @@ Internally, the random allocation method is executed with the parameters pre-def Note that the scheduled allocation is *not* executed if you manually switch the workshop into the assessment phase before the submissions deadline. You have to allocate submissions yourself in that case. The scheduled allocation method is particularly useful when used together with the automatic phase switching feature.'; $string['pluginname'] = 'Scheduled allocation'; +$string['privacy:metadata'] = 'The Scheduled allocation plugin does not store any personal data. Actual personal data about who is going to assess whom are stored by the Workshop module itself and they form basis for exporting the assessments details.'; $string['randomallocationsettings'] = 'Allocation settings'; $string['randomallocationsettings_help'] = 'Parameters for the random allocation method are defined here. They will be used by the random allocation plugin for the actual allocation of submissions.'; $string['resultdisabled'] = 'Scheduled allocation disabled';