user topic: Remove unnecessary check for double addition of muted topic.

This makes use of the new case insensitive UNIQUE index added in the
earlier commit. With that index present, we can now rely solely on the
database to correctly identify duplicates and throw integrity errors as
required.
This commit is contained in:
Abhijeet Prasad Bodas 2023-02-11 00:36:39 +05:30 committed by Tim Abbott
parent 80bf6b0777
commit 6e001d0672
2 changed files with 6 additions and 23 deletions

View File

@ -113,23 +113,14 @@ class MutedTopicsTests(ZulipTestCase):
topic_name="Verona3",
)
# Verify the error handling for the database level
# IntegrityError we'll get with a race between two processes
# trying to mute the topic. To do this, we patch the
# topic_is_muted function to always return False when trying
# to mute a topic that is already muted.
assert stream.recipient is not None
add_topic_mute(
user_profile=user,
stream_id=stream.id,
recipient_id=stream.recipient.id,
topic_name="Verona3",
date_muted=datetime(2020, 1, 1, tzinfo=timezone.utc),
)
result = self.api_patch(user, url, data)
with mock.patch("zerver.views.user_topics.topic_is_muted", return_value=False):
result = self.api_patch(user, url, data)
self.assert_json_error(result, "Topic already muted")
# Now check that error is raised when attempted to mute an already
# muted topic. This should be case-insensitive.
data["topic"] = "VERONA3"
result = self.api_patch(user, url, data)
self.assert_json_error(result, "Topic already muted")
def test_remove_muted_topic(self) -> None:
user = self.example_user("hamlet")
@ -181,10 +172,6 @@ class MutedTopicsTests(ZulipTestCase):
url = "/api/v1/users/me/subscriptions/muted_topics"
data: Dict[str, Any] = {"stream": stream.name, "topic": "Verona3", "op": "add"}
result = self.api_patch(user, url, data)
self.assert_json_error(result, "Topic already muted")
data = {"stream_id": 999999999, "topic": "Verona3", "op": "add"}
result = self.api_patch(user, url, data)
self.assert_json_error(result, "Invalid stream ID")

View File

@ -17,7 +17,6 @@ from zerver.lib.streams import (
access_stream_for_unmute_topic_by_name,
check_for_exactly_one_stream_arg,
)
from zerver.lib.user_topics import topic_is_muted
from zerver.lib.validator import check_int, check_string_in
from zerver.models import UserProfile
@ -35,9 +34,6 @@ def mute_topic(
assert stream_id is not None
(stream, sub) = access_stream_by_id(user_profile, stream_id)
if topic_is_muted(user_profile, stream.id, topic_name):
raise JsonableError(_("Topic already muted"))
try:
do_mute_topic(user_profile, stream, topic_name, date_muted)
except IntegrityError: