From dcdd4f10532220ffd26853f08066e3ffd83f1cf9 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Wed, 19 Sep 2018 15:59:08 +0800 Subject: [PATCH] MDL-63497 tool_dataprivacy: Add support for removal of context users This issue is a part of the MDL-62560 Epic. --- .../dataprivacy/classes/privacy/provider.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/admin/tool/dataprivacy/classes/privacy/provider.php b/admin/tool/dataprivacy/classes/privacy/provider.php index 4ddd41156cc..193bd70538d 100644 --- a/admin/tool/dataprivacy/classes/privacy/provider.php +++ b/admin/tool/dataprivacy/classes/privacy/provider.php @@ -30,9 +30,11 @@ use context; 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; @@ -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, @@ -100,6 +105,32 @@ class provider implements 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. * @@ -172,6 +203,15 @@ class provider implements 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. *