mirror of https://github.com/zulip/zulip.git
reactions: Add error code for duplicate addition/removal.
This commit is contained in:
parent
143baa4243
commit
3802503a8a
|
@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
|
|||
# Changes should be accompanied by documentation explaining what the
|
||||
# new level means in api_docs/changelog.md, as well as "**Changes**"
|
||||
# entries in the endpoint's documentation in `zulip.yaml`.
|
||||
API_FEATURE_LEVEL = 192
|
||||
API_FEATURE_LEVEL = 193
|
||||
|
||||
# Bump the minor PROVISION_VERSION to indicate that folks should provision
|
||||
# only when going from an old version of the code to a newer version. Bump
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
from typing import Any, Dict, Optional
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from zerver.actions.create_user import create_historical_user_messages
|
||||
from zerver.lib.emoji import check_emoji_request, get_emoji_data
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.exceptions import ReactionExistsError
|
||||
from zerver.lib.message import access_message, update_to_dict_cache
|
||||
from zerver.lib.stream_subscription import subscriber_ids_with_stream_history_access
|
||||
from zerver.models import Message, Reaction, Recipient, Stream, UserMessage, UserProfile
|
||||
|
@ -115,7 +113,7 @@ def check_add_reaction(
|
|||
emoji_code=emoji_code,
|
||||
reaction_type=reaction_type,
|
||||
).exists():
|
||||
raise JsonableError(_("Reaction already exists."))
|
||||
raise ReactionExistsError
|
||||
|
||||
query = Reaction.objects.filter(
|
||||
message=message, emoji_code=emoji_code, reaction_type=reaction_type
|
||||
|
|
|
@ -40,6 +40,8 @@ class ErrorCode(Enum):
|
|||
UNAUTHORIZED = auto()
|
||||
REQUEST_TIMEOUT = auto()
|
||||
MOVE_MESSAGES_TIME_LIMIT_EXCEEDED = auto()
|
||||
REACTION_ALREADY_EXISTS = auto()
|
||||
REACTION_DOES_NOT_EXIST = auto()
|
||||
|
||||
|
||||
class JsonableError(Exception):
|
||||
|
@ -503,3 +505,25 @@ class MessageMoveError(JsonableError):
|
|||
return _(
|
||||
"You only have permission to move the {total_messages_allowed_to_move}/{total_messages_in_topic} most recent messages in this topic."
|
||||
)
|
||||
|
||||
|
||||
class ReactionExistsError(JsonableError):
|
||||
code = ErrorCode.REACTION_ALREADY_EXISTS
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def msg_format() -> str:
|
||||
return _("Reaction already exists.")
|
||||
|
||||
|
||||
class ReactionDoesNotExistError(JsonableError):
|
||||
code = ErrorCode.REACTION_DOES_NOT_EXIST
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def msg_format() -> str:
|
||||
return _("Reaction doesn't exist.")
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.utils.translation import gettext as _
|
|||
|
||||
from zerver.actions.reactions import check_add_reaction, do_remove_reaction
|
||||
from zerver.lib.emoji import get_emoji_data
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.exceptions import JsonableError, ReactionDoesNotExistError
|
||||
from zerver.lib.message import access_message
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
|
@ -65,7 +65,7 @@ def remove_reaction(
|
|||
emoji_code=emoji_code,
|
||||
reaction_type=reaction_type,
|
||||
).exists():
|
||||
raise JsonableError(_("Reaction doesn't exist."))
|
||||
raise ReactionDoesNotExistError
|
||||
|
||||
# Unlike adding reactions, while deleting a reaction, we don't
|
||||
# check whether the provided (emoji_type, emoji_code) pair is
|
||||
|
|
Loading…
Reference in New Issue