Skip to content

Commit

Permalink
MDL-64773 core_message: updated privacy provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Mar 13, 2019
1 parent 086409f commit 1c36c11
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lang/en/message.php
Expand Up @@ -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: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: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_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'] = '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:conversationid'] = 'The ID of the conversation';
$string['privacy:metadata:message_conversation_members:timecreated'] = 'The time when the member was created'; $string['privacy:metadata:message_conversation_members:timecreated'] = 'The time when the member was created';
Expand Down
35 changes: 35 additions & 0 deletions message/classes/privacy/provider.php
Expand Up @@ -99,6 +99,16 @@ public static function get_metadata(collection $items) : collection {
'privacy:metadata:message_conversation_members' '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( $items->add_database_table(
'message_contacts', 'message_contacts',
[ [
Expand Down Expand Up @@ -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. // 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). // 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_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. // So, checking messages table would suffice.


$hasdata = false; $hasdata = false;
Expand Down Expand Up @@ -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. // 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). // 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_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. // So, checking messages table would suffice.


$hasdata = false; $hasdata = false;
Expand Down Expand Up @@ -568,6 +582,7 @@ public static function delete_conversations_for_all_users(\context $context, str


// Delete members and conversations. // Delete members and conversations.
$DB->delete_records_list('message_conversation_members', 'conversationid', $conversationids); $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); $DB->delete_records_list('message_conversations', 'id', $conversationids);
} }
} }
Expand Down Expand Up @@ -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. // Reuse the $params var because it contains the useridparams and the conversationids.
$DB->delete_records_select('message_conversation_members', $sql, $params); $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. // Delete the favourite conversations.
$userlist = new \core_privacy\local\request\approved_userlist($context, 'core_message', $userids); $userlist = new \core_privacy\local\request\approved_userlist($context, 'core_message', $userids);
\core_favourites\privacy\provider::delete_favourites_for_userlist( \core_favourites\privacy\provider::delete_favourites_for_userlist(
Expand Down Expand Up @@ -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. // Reuse the $params var because it contains the userid and the conversationids.
$DB->delete_records_select('message_conversation_members', $sql, $params); $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. // Delete the favourite conversations.
if (empty($contextids) && empty($component) && empty($itemtype) && empty($itemid)) { if (empty($contextids) && empty($component) && empty($itemtype) && empty($itemid)) {
// Favourites for individual conversations are stored into the user context. // Favourites for individual conversations are stored into the user context.
Expand Down Expand Up @@ -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. // 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); 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);
}
} }
} }


Expand Down

0 comments on commit 1c36c11

Please sign in to comment.