Skip to content

Commit

Permalink
message_edit: Fix false sub/unsub bookend on using a near link.
Browse files Browse the repository at this point in the history
We were not setting the `historical` flag correctly for
messages fetched via `json_fetch_raw_message` when used didn't
have any UserMessage.

Extended relevant tests to fetch check message flags too.
  • Loading branch information
amanagr authored and timabbott committed Apr 4, 2022
1 parent 0b03275 commit dcdf071
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions zerver/tests/test_message_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test_fetch_message_from_id(self) -> None:
self.assert_json_success(result)
self.assertEqual(result.json()["raw_content"], "Personal message")
self.assertEqual(result.json()["message"]["id"], msg_id)
self.assertEqual(result.json()["message"]["flags"], [])

# Send message to web public stream where hamlet is not subscribed.
# This will test case of user having no `UserMessage` but having access
Expand All @@ -335,6 +336,7 @@ def test_fetch_message_from_id(self) -> None:
self.assert_json_success(result)
self.assertEqual(result.json()["raw_content"], "web-public message")
self.assertEqual(result.json()["message"]["id"], web_public_stream_msg_id)
self.assertEqual(result.json()["message"]["flags"], ["read", "historical"])

# Spectator should be able to fetch message in web public stream.
self.logout()
Expand Down Expand Up @@ -416,6 +418,7 @@ def test_fetch_raw_message_spectator(self) -> None:
result = self.client_get("/json/messages/" + str(web_public_stream_msg_id))
self.assert_json_success(result)
self.assertEqual(result.json()["raw_content"], "web-public message")
self.assertEqual(result.json()["message"]["flags"], ["read"])

# Verify LIMITED plan type does not allow web-public access.
do_change_realm_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
Expand Down
2 changes: 2 additions & 0 deletions zerver/views/message_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def json_fetch_raw_message(
else:
if user_message:
flags = user_message.flags_list()
else:
flags = ["read", "historical"]
allow_edit_history = maybe_user_profile.realm.allow_edit_history

# Security note: It's important that we call this only with a
Expand Down

0 comments on commit dcdf071

Please sign in to comment.