Skip to content

Commit

Permalink
MDL-63497 tool_dataprivacy: Add support for removal of context users
Browse files Browse the repository at this point in the history
This issue is a part of the MDL-62560 Epic.
  • Loading branch information
mickhawkins authored and David Monllao committed Oct 22, 2018
1 parent 7b5fcbd commit dcdd4f1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions admin/tool/dataprivacy/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
use context_user;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use \core_privacy\local\request\approved_userlist;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\helper;
use core_privacy\local\request\transform;
use \core_privacy\local\request\userlist;
use core_privacy\local\request\writer;
use dml_exception;
use stdClass;
Expand All @@ -50,6 +52,9 @@ class provider implements
// This tool stores user data.
\core_privacy\local\metadata\provider,

// This plugin is capable of determining which users have data within it.
\core_privacy\local\request\core_userlist_provider,

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

Expand Down Expand Up @@ -100,6 +105,32 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
return $contextlist;
}

/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if (!is_a($context, \context_user::class)) {
return;
}

$params = [
'contextlevel' => CONTEXT_USER,
'contextid' => $context->id,
];

$sql = "SELECT instanceid AS userid
FROM {context}
WHERE id = :contextid
AND contextlevel = :contextlevel";

$userlist->add_from_sql('userid', $sql, $params);
}

/**
* Export all user data for the specified user, in the specified contexts.
*
Expand Down Expand Up @@ -172,6 +203,15 @@ public static function delete_data_for_all_users_in_context(context $context) {
public static function delete_data_for_user(approved_contextlist $contextlist) {
}

/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*
*/
public static function delete_data_for_users(approved_userlist $userlist) {
}

/**
* Export all user preferences for the plugin.
*
Expand Down

0 comments on commit dcdd4f1

Please sign in to comment.