mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-61868 tool_policy: Implement privacy API
Part of MDL-61864
- Loading branch information
1 parent
4e9e2b0
commit 24966a2
Showing
3 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |