From e063385c59f560867f000285b747b25fae221e3c Mon Sep 17 00:00:00 2001 From: Guillaume Barat Date: Fri, 1 Sep 2023 16:06:29 +1000 Subject: [PATCH 1/2] fix : issue 78 failing privacy provider test. adding method get_users_in_context --- classes/privacy/provider.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index df5ef34a..49f2b264 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -29,12 +29,14 @@ use core_privacy\local\request\contextlist; use core_privacy\local\request\deletion_criteria; use core_privacy\local\request\helper; +use core_privacy\local\request\userlist; use core_privacy\local\request\writer; class provider implements // This plugin stores personal data. \core_privacy\local\metadata\provider, - \core_privacy\local\request\plugin\provider { + \core_privacy\local\request\plugin\provider, + \core_privacy\local\request\core_userlist_provider { // This trait must be included to provide the relevant polyfill for the metadata provider. // All required methods must start with an underscore. @@ -246,4 +248,33 @@ public static function _delete_data_for_user(approved_contextlist $contextlist) $records->close(); } } + public static function get_users_in_context(userlist $userlist) { + // TODO: Implement get_users_in_context() method. + $context = $userlist->get_context(); + if(!$context instanceof \context_user) { + return; + } + + $params = ['contextid' => $context->instanceid]; + $sql = "SELECT q.createdby userid + FROM {question_categories} qc"; + + if ($CFG->version >= 2022041900) { + $sql .= " INNER JOIN {question_bank_entries} qbe ON qbe.questioncategoryid = qc.id + INNER JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id + INNER JOIN {question} q ON q.id = qv.questionid + INNER JOIN {qtype_wq} wq ON q.id = wq.question"; + } else { + $sql .= " INNER JOIN {question} q ON qc.id = q.category + INNER JOIN {qtype_wq} wq ON q.id = wq.question"; + } + + $sql .= " WHERE qc.contextid = :contextid "; + $userlist->add_from_sql('userid', $sql, $params); + + } + + public static function delete_data_for_users(approved_userlist $userlist) { + // TODO: Implement delete_data_for_users() method. + } } From ef512396627dd023b2a51ec42a3aca63b7f77ceb Mon Sep 17 00:00:00 2001 From: Guillaume Barat Date: Mon, 4 Sep 2023 11:13:17 +1000 Subject: [PATCH 2/2] fix : issue 78 failing privacy provider test. adding method delete_data_for_users --- classes/privacy/provider.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 49f2b264..ee3e2bfe 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -248,8 +248,13 @@ public static function _delete_data_for_user(approved_contextlist $contextlist) $records->close(); } } + + /** + * Get the list of users within a specific context. + * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. + * @return void + */ public static function get_users_in_context(userlist $userlist) { - // TODO: Implement get_users_in_context() method. $context = $userlist->get_context(); if(!$context instanceof \context_user) { return; @@ -274,7 +279,16 @@ public static function get_users_in_context(userlist $userlist) { } + /** + * Delete multiple users within a single context. + * @param approved_userlist $userlist The approved context and user information to delete information for. + * @return void + */ public static function delete_data_for_users(approved_userlist $userlist) { - // TODO: Implement delete_data_for_users() method. + $context = $userlist->get_context(); + + if ($context instanceof \context_user) { + static::_delete_data_for_user($context->instanceid); + } } }