mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
muting: Handle the case of a race muting the same user twice.
This commit is contained in:
committed by
Tim Abbott
parent
781107308d
commit
141b0c4cec
@@ -77,6 +77,14 @@ class MutedUsersTests(ZulipTestCase):
|
|||||||
result = self.api_post(hamlet, url)
|
result = self.api_post(hamlet, url)
|
||||||
self.assert_json_error(result, "User already muted")
|
self.assert_json_error(result, "User already muted")
|
||||||
|
|
||||||
|
# Verify the error handling for the database level
|
||||||
|
# IntegrityError we'll get with a race between two processes
|
||||||
|
# trying to mute the user. To do this, we patch the
|
||||||
|
# get_mute_object function to always return None.
|
||||||
|
with mock.patch("zerver.views.muting.get_mute_object", return_value=None):
|
||||||
|
result = self.api_post(hamlet, url)
|
||||||
|
self.assert_json_error(result, "User already muted")
|
||||||
|
|
||||||
def _test_add_muted_user_valid_data(self, deactivate_user: bool = False) -> None:
|
def _test_add_muted_user_valid_data(self, deactivate_user: bool = False) -> None:
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
self.login_user(hamlet)
|
self.login_user(hamlet)
|
||||||
|
|||||||
@@ -106,7 +106,11 @@ def mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: in
|
|||||||
if get_mute_object(user_profile, muted_user) is not None:
|
if get_mute_object(user_profile, muted_user) is not None:
|
||||||
raise JsonableError(_("User already muted"))
|
raise JsonableError(_("User already muted"))
|
||||||
|
|
||||||
do_mute_user(user_profile, muted_user, date_muted)
|
try:
|
||||||
|
do_mute_user(user_profile, muted_user, date_muted)
|
||||||
|
except IntegrityError:
|
||||||
|
raise JsonableError(_("User already muted"))
|
||||||
|
|
||||||
return json_success(request)
|
return json_success(request)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user