messages: Add support for admins deleting messages.

This makes it possible for Zulip administrators to delete messages.
This is primarily intended for use in deleting early test messages,
but it can solve other problems as well.

Later we'll want to play with the permissions model for this, but for
now, the goal is just to integrate the feature.

Note that it saves the deleted messages for some time using the same
approach as Zulip's message retention policy feature.

Fixes #135.
This commit is contained in:
K.Kanakhin
2017-05-15 01:14:26 +06:00
committed by Tim Abbott
parent 9b13b19006
commit 2434f2d96c
18 changed files with 377 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ from zerver.lib.message import (
render_markdown,
)
from zerver.lib.realm_icon import realm_icon_url
from zerver.lib.retention import move_message_to_archive
from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, \
RealmDomain, \
Subscription, Recipient, Message, Attachment, UserMessage, RealmAuditLog, \
@@ -2821,6 +2822,19 @@ def do_update_message(user_profile, message, subject, propagate_mode, content, r
send_event(event, list(map(user_info, ums)))
return len(changed_messages)
def do_delete_message(user_profile, message):
# type: (UserProfile, Message) -> None
event = {
'type': 'delete_message',
'sender': user_profile.email,
'message_id': message.id} # type: Dict[str, Any]
ums = [{'id': um.user_profile_id} for um in
UserMessage.objects.filter(message=message.id)]
move_message_to_archive(message.id)
send_event(event, ums)
def encode_email_address(stream):
# type: (Stream) -> Text
return encode_email_address_helper(stream.name, stream.email_token)