Skip to content
Permalink
Browse files

MDL-64773 core_message: updated privacy provider

  • Loading branch information...
markn86 committed Feb 6, 2019
1 parent 086409f commit 1c36c11a18c08d6389992f696b270bf5b3e742f3
Showing with 122 additions and 3 deletions.
  1. +5 −0 lang/en/message.php
  2. +35 −0 message/classes/privacy/provider.php
  3. +82 −3 message/tests/privacy_provider_test.php
@@ -162,6 +162,11 @@
$string['privacy:metadata:message_contact_requests:requesteduserid'] = 'The ID of the user who received the contact request';
$string['privacy:metadata:message_contact_requests:timecreated'] = 'The time when the contact request was created';
$string['privacy:metadata:message_contact_requests:userid'] = 'The ID of the user who sent the contact request';
$string['privacy:metadata:message_conversation_actions'] = 'The list of conversation user actions';
$string['privacy:metadata:message_conversation_actions:action'] = 'The action that was performed';
$string['privacy:metadata:message_conversation_actions:conversationid'] = 'The ID of the conversation this action belongs to';
$string['privacy:metadata:message_conversation_actions:timecreated'] = 'The time when the action was created';
$string['privacy:metadata:message_conversation_actions:userid'] = 'The ID of the user who performed this action';
$string['privacy:metadata:message_conversation_members'] = 'The list of users in a conversation';
$string['privacy:metadata:message_conversation_members:conversationid'] = 'The ID of the conversation';
$string['privacy:metadata:message_conversation_members:timecreated'] = 'The time when the member was created';
@@ -99,6 +99,16 @@ public static function get_metadata(collection $items) : collection {
'privacy:metadata:message_conversation_members'
);
$items->add_database_table(
'message_conversation_actions',
[
'conversationid' => 'privacy:metadata:message_conversation_actions:conversationid',
'userid' => 'privacy:metadata:message_conversation_actions:userid',
'timecreated' => 'privacy:metadata:message_conversation_actions:timecreated',
],
'privacy:metadata:message_conversation_actions'
);
$items->add_database_table(
'message_contacts',
[
@@ -205,6 +215,8 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
// It is enough to add the user's context as soon as we come to the conclusion that the user has some data.
// Also, the order of checking is sorted by the probability of occurrence (just by guess).
// There is no need to check the message_user_actions table, as there needs to be a message in order to be a message action.
// There is no need to check the message_conversation_actions table, as there needs to be a conversation in order to
// be a conversation action.
// So, checking messages table would suffice.
$hasdata = false;
@@ -258,6 +270,8 @@ public static function get_users_in_context(userlist $userlist) {
// It is enough to add the user's context as soon as we come to the conclusion that the user has some data.
// Also, the order of checking is sorted by the probability of occurrence (just by guess).
// There is no need to check the message_user_actions table, as there needs to be a message in order to be a message action.
// There is no need to check the message_conversation_actions table, as there needs to be a conversation in order to
// be a conversation action.
// So, checking messages table would suffice.
$hasdata = false;
@@ -568,6 +582,7 @@ public static function delete_conversations_for_all_users(\context $context, str
// Delete members and conversations.
$DB->delete_records_list('message_conversation_members', 'conversationid', $conversationids);
$DB->delete_records_list('message_conversation_actions', 'conversationid', $conversationids);
$DB->delete_records_list('message_conversations', 'id', $conversationids);
}
}
@@ -673,6 +688,9 @@ public static function delete_conversations_for_users(approved_userlist $userlis
// Reuse the $params var because it contains the useridparams and the conversationids.
$DB->delete_records_select('message_conversation_members', $sql, $params);
// Delete any conversation actions.
$DB->delete_records_select('message_conversation_actions', $sql, $params);
// Delete the favourite conversations.
$userlist = new \core_privacy\local\request\approved_userlist($context, 'core_message', $userids);
\core_favourites\privacy\provider::delete_favourites_for_userlist(
@@ -763,6 +781,9 @@ protected static function delete_user_data_conversations(int $userid, array $con
// Reuse the $params var because it contains the userid and the conversationids.
$DB->delete_records_select('message_conversation_members', $sql, $params);
// Delete any conversation actions.
$DB->delete_records_select('message_conversation_actions', $sql, $params);
// Delete the favourite conversations.
if (empty($contextids) && empty($component) && empty($itemtype) && empty($itemid)) {
// Favourites for individual conversations are stored into the user context.
@@ -974,6 +995,20 @@ protected static function export_user_data_conversation_messages(int $userid, \s
// If the conversation has been favorited by the user, include it in the export.
writer::with_context($context)->export_related_data($subcontext, 'starred', (object) $conversationfavourite);
}
// Check if the conversation was muted.
$params = [
'userid' => $userid,
'conversationid' => $conversation->id,
'action' => \core_message\api::CONVERSATION_ACTION_MUTED
];
if ($mca = $DB->get_record('message_conversation_actions', $params)) {
$mcatostore = [
'muted' => transform::yesno(true),
'timecreated' => transform::datetime($mca->timecreated),
];
writer::with_context($context)->export_related_data($subcontext, 'muted', (object) $mcatostore);
}
}
}

0 comments on commit 1c36c11

Please sign in to comment.
You can’t perform that action at this time.