Skip to content

Commit

Permalink
MDL-61868 tool_policy: Implement privacy API
Browse files Browse the repository at this point in the history
Part of MDL-61864
  • Loading branch information
sarjona authored and marinaglancy committed Apr 16, 2018
1 parent 4e9e2b0 commit 24966a2
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
104 changes: 104 additions & 0 deletions admin/tool/policy/classes/privacy/provider.php
@@ -0,0 +1,104 @@
<?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/>.

/**
* Privacy Subsystem implementation for tool_policy.
*
* @package tool_policy
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_policy\privacy;

use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\contextlist;

defined('MOODLE_INTERNAL') || die();

/**
* Implementation of the privacy subsystem plugin provider for the policy tool.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This tool stores user data.
\core_privacy\local\metadata\provider,

// This tool may provide access to and deletion of user data.
\core_privacy\local\request\plugin\provider {

/**
* Return the fields which contain personal data.
*
* @param collection $items A reference to the collection to use to store the metadata.
* @return collection The updated collection of metadata items.
*/
public static function get_metadata(collection $items) : collection {
$items->add_database_table(
'tool_policy_acceptances',
[
'policyversionid' => 'privacy:metadata:acceptances:policyversionid',
'userid' => 'privacy:metadata:acceptances:userid',
'status' => 'privacy:metadata:acceptances:status',
'lang' => 'privacy:metadata:acceptances:lang',
'usermodified' => 'privacy:metadata:acceptances:usermodified',
'timecreated' => 'privacy:metadata:acceptances:timecreated',
'timemodified' => 'privacy:metadata:acceptances:timemodified',
'note' => 'privacy:metadata:acceptances:note',
],
'privacy:metadata:acceptances'
);

return $items;
}

/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The userid.
* @return contextlist The list of contexts containing user info for the user.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
return new contextlist();
}

/**
* Export personal data for the given approved_contextlist. User and context information is contained within the contextlist.
*
* @param approved_contextlist $contextlist A list of contexts approved for export.
*/
public static function export_user_data(approved_contextlist $contextlist) {
}

/**
* Delete all data for all users in the specified context.
*
* @param \context $context The context to delete in.
*/
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 A list of contexts approved for deletion.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
}
}
9 changes: 9 additions & 0 deletions admin/tool/policy/lang/en/tool_policy.php
Expand Up @@ -116,6 +116,15 @@
$string['policyversionacceptedinbehalf'] = 'This policy version has been agreed to by another user on behalf of you.';
$string['policyversionacceptedinotherlang'] = 'This policy version has been agreed to in a different language.';
$string['previousversions'] = '{$a} previous versions';
$string['privacy:metadata:acceptances'] = 'Information from policies acceptances made by the users of this site.';
$string['privacy:metadata:acceptances:policyversionid'] = 'The ID of the accepted version policy.';
$string['privacy:metadata:acceptances:userid'] = 'The ID of the user who has accepted the policy.';
$string['privacy:metadata:acceptances:status'] = 'The status of the acceptance: 0 if not accepted; 1 otherwise.';
$string['privacy:metadata:acceptances:lang'] = 'The current lang displayed when the policy is accepted.';
$string['privacy:metadata:acceptances:usermodified'] = 'The ID of the user accepting the policy, if made on behalf of another user.';
$string['privacy:metadata:acceptances:timecreated'] = 'The timestamp indicating when the acceptance was made by the user.';
$string['privacy:metadata:acceptances:timemodified'] = 'The timestamp indicating when the acceptance was modified by the user.';
$string['privacy:metadata:acceptances:note'] = 'Any comments added by the user who accepts policies on behalf of another.';
$string['privacysettings'] = 'Privacy settings';
$string['readpolicy'] = 'Please read our {$a}';
$string['refertofullpolicytext'] = 'Please refer to the full {$a} text if you would like to review.';
Expand Down
83 changes: 83 additions & 0 deletions admin/tool/policy/tests/privacy_provider_test.php
@@ -0,0 +1,83 @@
<?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/>.

/**
* Privacy provider tests.
*
* @package tool_policy
* @category test
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core_privacy\local\metadata\collection;
use tool_policy\privacy\provider;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy provider tests class.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_policy_privacy_provider_testcase extends \core_privacy\tests\provider_testcase {
/** @var stdClass The user object. */
protected $user;

/**
* Setup function. Will create a user.
*/
protected function setUp() {
$this->resetAfterTest();

$generator = $this->getDataGenerator();
$this->user = $generator->create_user();
}

/**
* Test for provider::get_metadata().
*/
public function test_get_metadata() {
$collection = new collection('tool_policy');
$newcollection = provider::get_metadata($collection);
$itemcollection = $newcollection->get_collection();
$this->assertCount(1, $itemcollection);

$table = reset($itemcollection);
$this->assertEquals('tool_policy_acceptances', $table->get_name());

$privacyfields = $table->get_privacy_fields();
$this->assertArrayHasKey('policyversionid', $privacyfields);
$this->assertArrayHasKey('userid', $privacyfields);
$this->assertArrayHasKey('status', $privacyfields);
$this->assertArrayHasKey('lang', $privacyfields);
$this->assertArrayHasKey('usermodified', $privacyfields);
$this->assertArrayHasKey('timecreated', $privacyfields);
$this->assertArrayHasKey('timemodified', $privacyfields);
$this->assertArrayHasKey('note', $privacyfields);

$this->assertEquals('privacy:metadata:acceptances', $table->get_summary());
}

/**
* Test getting the context for the user ID related to this plugin.
*/
public function test_get_contexts_for_userid() {
$contextlist = \tool_policy\privacy\provider::get_contexts_for_userid($this->user->id);
$this->assertEmpty($contextlist);
}
}

0 comments on commit 24966a2

Please sign in to comment.