Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

topic_mutes: Filter deactivated streams from get_topic_mutes.

lukem1105a5a95ee91
diff --git a/zerver/lib/topic_mutes.py b/zerver/lib/topic_mutes.py
index 2d26e14f028..59b9b22a519 100644
--- a/zerver/lib/topic_mutes.py
+++ b/zerver/lib/topic_mutes.py
@@ -9,8 +9,15 @@ from zerver.lib.topic import topic_match_sa
from zerver.models import MutedTopic, UserProfile, get_stream
-def get_topic_mutes(user_profile: UserProfile) -> List[Tuple[str, str, float]]:
- rows = MutedTopic.objects.filter(user_profile=user_profile).values(
+def get_topic_mutes(
+ user_profile: UserProfile, include_deactivated: bool = False
+) -> List[Tuple[str, str, float]]:
+ query = MutedTopic.objects.filter(user_profile=user_profile)
+ # Exclude muted topics that are part of deactivated streams unless
+ # explicitly requested.
+ if not include_deactivated:
+ query = query.filter(stream__deactivated=False)
+ rows = query.values(
"stream__name",
"topic_name",
"date_muted",
@@ -88,6 +95,9 @@ def topic_is_muted(user_profile: UserProfile, stream_id: int, topic_name: str) -
def exclude_topic_mutes(
conditions: List[ClauseElement], user_profile: UserProfile, stream_id: Optional[int]
) -> List[ClauseElement]:
+ # Note: Unlike get_topic_mutes, here we always want to
+ # consider topics in deactivated streams, so they are
+ # never filtered from the query in this method.
query = MutedTopic.objects.filter(
user_profile=user_profile,
)
diff --git a/zerver/tests/test_muting.py b/zerver/tests/test_muting.py
index 07dc0641dba..e605cea343b 100644
--- a/zerver/tests/test_muting.py
+++ b/zerver/tests/test_muting.py
@@ -16,6 +16,29 @@ from zerver.models import MutedTopic, UserProfile, get_stream
class MutedTopicsTests(ZulipTestCase):
+ def test_get_deactivated_muted_topic(self) -> None:
+ user = self.example_user("hamlet")
+ self.login_user(user)
+
+ stream = get_stream("Verona", user.realm)
+ recipient = stream.recipient
+
+ mock_date_muted = datetime(2020, 1, 1, tzinfo=timezone.utc).timestamp()
+
+ add_topic_mute(
+ user_profile=user,
+ stream_id=stream.id,
+ recipient_id=recipient.id,
+ topic_name="Verona3",
+ date_muted=datetime(2020, 1, 1, tzinfo=timezone.utc),
+ )
+
+ stream.deactivated = True
+ stream.save()
+
+ self.assertNotIn((stream.name, "Verona3", mock_date_muted), get_topic_mutes(user))
+ self.assertIn((stream.name, "Verona3", mock_date_muted), get_topic_mutes(user, True))
+
def test_user_ids_muting_topic(self) -> None:
hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia")