mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
reactions.py: Don't check for valid emoji name while removing reaction.
On receiving a request for deleting a reaction, just check if such a reaction exists or not. If it exists then just delete the reaction otherwise send an error message that such a reaction doesn't exist. It doesn't make sense to check whether an emoji name is valid or not.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from typing import Any, Mapping, List
|
from typing import Any, Mapping, List
|
||||||
|
from unittest import mock
|
||||||
from six import string_types
|
from six import string_types
|
||||||
|
|
||||||
from zerver.lib.emoji import emoji_name_to_emoji_code
|
from zerver.lib.emoji import emoji_name_to_emoji_code
|
||||||
@@ -32,16 +33,6 @@ class ReactionEmojiTest(ZulipTestCase):
|
|||||||
**self.api_auth(sender))
|
**self.api_auth(sender))
|
||||||
self.assert_json_error(result, "Emoji 'foo' does not exist")
|
self.assert_json_error(result, "Emoji 'foo' does not exist")
|
||||||
|
|
||||||
def test_remove_invalid_emoji(self):
|
|
||||||
# type: () -> None
|
|
||||||
"""
|
|
||||||
Removing invalid emoji fails
|
|
||||||
"""
|
|
||||||
sender = self.example_email("hamlet")
|
|
||||||
result = self.client_delete('/api/v1/messages/1/emoji_reactions/foo',
|
|
||||||
**self.api_auth(sender))
|
|
||||||
self.assert_json_error(result, "Emoji 'foo' does not exist")
|
|
||||||
|
|
||||||
def test_add_deactivated_realm_emoji(self):
|
def test_add_deactivated_realm_emoji(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""
|
"""
|
||||||
@@ -265,6 +256,40 @@ class ReactionTest(ZulipTestCase):
|
|||||||
**self.api_auth(reaction_sender))
|
**self.api_auth(reaction_sender))
|
||||||
self.assert_json_error(second, "Reaction does not exist")
|
self.assert_json_error(second, "Reaction does not exist")
|
||||||
|
|
||||||
|
def test_remove_existing_reaction_with_renamed_emoji(self):
|
||||||
|
# type: () -> None
|
||||||
|
"""
|
||||||
|
Removes an old existing reaction but the name of emoji got changed during
|
||||||
|
various emoji infra changes.
|
||||||
|
"""
|
||||||
|
sender = self.example_email("hamlet")
|
||||||
|
result = self.client_put('/api/v1/messages/1/emoji_reactions/smile',
|
||||||
|
**self.api_auth(sender))
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
with mock.patch('zerver.lib.emoji.name_to_codepoint', name_to_codepoint={}):
|
||||||
|
result = self.client_delete('/api/v1/messages/1/emoji_reactions/smile',
|
||||||
|
**self.api_auth(sender))
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
def test_remove_existing_reaction_with_deactivated_realm_emoji(self):
|
||||||
|
# type: () -> None
|
||||||
|
"""
|
||||||
|
Removes an old existing reaction but the realm emoji used there has been deactivated.
|
||||||
|
"""
|
||||||
|
sender = self.example_email("hamlet")
|
||||||
|
result = self.client_put('/api/v1/messages/1/emoji_reactions/green_tick',
|
||||||
|
**self.api_auth(sender))
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
# Deactivate realm emoji.
|
||||||
|
emoji = RealmEmoji.objects.get(name="green_tick")
|
||||||
|
emoji.deactivated = True
|
||||||
|
emoji.save(update_fields=['deactivated'])
|
||||||
|
|
||||||
|
result = self.client_delete('/api/v1/messages/1/emoji_reactions/green_tick',
|
||||||
|
**self.api_auth(sender))
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
class ReactionEventTest(ZulipTestCase):
|
class ReactionEventTest(ZulipTestCase):
|
||||||
def test_add_event(self):
|
def test_add_event(self):
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ def remove_reaction_backend(request, user_profile, message_id, emoji_name):
|
|||||||
# cannot see the message (e.g. for messages to private streams).
|
# cannot see the message (e.g. for messages to private streams).
|
||||||
message = access_message(user_profile, message_id)[0]
|
message = access_message(user_profile, message_id)[0]
|
||||||
|
|
||||||
check_valid_emoji(message.sender.realm, emoji_name)
|
|
||||||
|
|
||||||
# We could probably just make this check be a try/except for the
|
# We could probably just make this check be a try/except for the
|
||||||
# IntegrityError from it already existing, but this is a bit cleaner.
|
# IntegrityError from it already existing, but this is a bit cleaner.
|
||||||
if not Reaction.objects.filter(user_profile=user_profile,
|
if not Reaction.objects.filter(user_profile=user_profile,
|
||||||
|
|||||||
Reference in New Issue
Block a user