messages: Allow "no topic" topics editable indefinitely.

Fixes: #9484.
This commit is contained in:
Shubham Dhama 2018-05-24 17:38:50 +05:30 committed by Tim Abbott
parent 1c5147c46c
commit fc3dcbfb5a
2 changed files with 10 additions and 2 deletions

View File

@ -2116,6 +2116,12 @@ class EditMessageTest(ZulipTestCase):
self.login(self.example_email("cordelia"))
do_edit_message_assert_error(id_, 'F', "The time limit for editing this message has passed")
# anyone should be able to edit "no topic" indefinitely
message.subject = "(no topic)"
message.save()
self.login(self.example_email("cordelia"))
do_edit_message_assert_success(id_, 'D')
def test_propagate_topic_forward(self) -> None:
self.login(self.example_email("hamlet"))
id1 = self.send_stream_message(self.example_email("hamlet"), "Scotland",

View File

@ -1285,6 +1285,7 @@ def update_message_backend(request: HttpRequest, user_profile: UserMessage,
return json_error(_("Your organization has turned off message editing"))
message, ignored_user_message = access_message(user_profile, message_id)
is_no_topic_msg = (message.topic_name() == "(no topic)")
# You only have permission to edit a message if:
# you change this value also change those two parameters in message_edit.js.
@ -1294,7 +1295,7 @@ def update_message_backend(request: HttpRequest, user_profile: UserMessage,
# 4. This is a topic-only edit and your realm allows users to edit topics.
if message.sender == user_profile:
pass
elif (content is None) and ((message.topic_name() == "(no topic)") or
elif (content is None) and (is_no_topic_msg or
user_profile.is_realm_admin or
user_profile.realm.allow_community_topic_editing):
pass
@ -1316,7 +1317,8 @@ def update_message_backend(request: HttpRequest, user_profile: UserMessage,
# edit it and that it has not been too long. If this is not the user who
# sent the message, they are not the admin, and the time limit for editing
# topics is passed, raise an error.
if content is None and message.sender != user_profile and not user_profile.is_realm_admin:
if content is None and message.sender != user_profile and not user_profile.is_realm_admin and \
not is_no_topic_msg:
deadline_seconds = Realm.DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS + edit_limit_buffer
if (timezone_now() - message.pub_date) > datetime.timedelta(seconds=deadline_seconds):
raise JsonableError(_("The time limit for editing this message has passed"))