MDL-61920 ltiservice_gradebookservices: implement privacy provider

This commit is contained in:
Mark Nelson 2018-04-16 13:43:23 +08:00
parent af099b484c
commit 2b3c4538f1
3 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,94 @@
<?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 ltiservice_gradebookservices.
*
* @package ltiservice_gradebookservices
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @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 <markn@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\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) {
}
}

View File

@ -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';

View File

@ -0,0 +1,51 @@
<?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/>.
/**
* Unit tests for ltiservice_gradebookservices privacy provider.
*
* @package ltiservice_gradebookservices
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @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 <markn@moodle.com>
* @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);
}
}