Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mudrd8mz committed May 9, 2018
1 parent 07dc878 commit fdcb33c
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 0 deletions.
68 changes: 68 additions & 0 deletions mod/workshop/allocation/manual/classes/privacy/provider.php
@@ -0,0 +1,68 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides the class {@link workshopallocation_manual\privacy\provider}
*
* @package workshopallocation_manual
* @category privacy
* @copyright 2018 David Mudrák <david@moodle.com>
* @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 <david@moodle.com>
* @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'));
}
}
}
Expand Up @@ -31,4 +31,5 @@
$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';
69 changes: 69 additions & 0 deletions mod/workshop/allocation/manual/tests/privacy_provider_test.php
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides the {@link workshopallocation_manual_privacy_provider_testcase} class.
*
* @package workshopallocation_manual
* @category test
* @copyright 2018 David Mudrák <david@moodle.com>
* @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 <david@moodle.com>
* @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);
}
}
46 changes: 46 additions & 0 deletions mod/workshop/allocation/random/classes/privacy/provider.php
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides the class {@link workshopallocation_random\privacy\provider}
*
* @package workshopallocation_random
* @category privacy
* @copyright 2018 David Mudrák <david@moodle.com>
* @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 <david@moodle.com>
* @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';
}
}
Expand Up @@ -43,6 +43,7 @@
$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';
Expand Down
46 changes: 46 additions & 0 deletions mod/workshop/allocation/scheduled/classes/privacy/provider.php
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides the class {@link workshopallocation_scheduled\privacy\provider}
*
* @package workshopallocation_scheduled
* @category privacy
* @copyright 2018 David Mudrák <david@moodle.com>
* @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 <david@moodle.com>
* @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';
}
}
Expand Up @@ -47,6 +47,7 @@
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';
Expand Down

0 comments on commit fdcb33c

Please sign in to comment.