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.

scheduled_messages: Extract exception for invalid delivery time.

Aman Agrawalad9cb5018319
diff --git a/zerver/actions/scheduled_messages.py b/zerver/actions/scheduled_messages.py
index e15713975a4..25af8f834a7 100644
--- a/zerver/actions/scheduled_messages.py
+++ b/zerver/actions/scheduled_messages.py
@@ -16,7 +16,12 @@ from zerver.actions.message_send import (
from zerver.actions.uploads import check_attachment_reference_change, do_claim_attachments
from zerver.lib.addressee import Addressee
from zerver.lib.display_recipient import get_recipient_ids
-from zerver.lib.exceptions import JsonableError, RealmDeactivatedError, UserDeactivatedError
+from zerver.lib.exceptions import (
+ DeliveryTimeNotInFutureError,
+ JsonableError,
+ RealmDeactivatedError,
+ UserDeactivatedError,
+)
from zerver.lib.markdown import render_message_markdown
from zerver.lib.message import SendMessageRequest, truncate_topic
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
@@ -153,7 +158,7 @@ def edit_scheduled_message(
# If the server failed to send the scheduled message, a new scheduled
# delivery timestamp (`deliver_at`) is required.
if scheduled_message_object.failed and deliver_at is None:
- raise JsonableError(_("Scheduled delivery time must be in the future."))
+ raise DeliveryTimeNotInFutureError
# Get existing scheduled message's recipient IDs and recipient_type_name.
existing_recipient, existing_recipient_type_name = get_recipient_ids(
diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py
index 0c154d04592..a0a0b654f68 100644
--- a/zerver/lib/exceptions.py
+++ b/zerver/lib/exceptions.py
@@ -766,3 +766,13 @@ class EmailAlreadyInUseError(JsonableError):
@override
def msg_format() -> str:
return _("Email is already in use.")
+
+
+class DeliveryTimeNotInFutureError(JsonableError):
+ def __init__(self) -> None:
+ pass
+
+ @staticmethod
+ @override
+ def msg_format() -> str:
+ return _("Scheduled delivery time must be in the future.")
diff --git a/zerver/views/scheduled_messages.py b/zerver/views/scheduled_messages.py
index 538fb027e58..644565a2327 100644
--- a/zerver/views/scheduled_messages.py
+++ b/zerver/views/scheduled_messages.py
@@ -10,7 +10,7 @@ from zerver.actions.scheduled_messages import (
delete_scheduled_message,
edit_scheduled_message,
)
-from zerver.lib.exceptions import JsonableError
+from zerver.lib.exceptions import DeliveryTimeNotInFutureError, JsonableError
from zerver.lib.recipient_parsing import extract_direct_message_recipient_ids, extract_stream_id
from zerver.lib.request import RequestNotes
from zerver.lib.response import json_success
@@ -101,7 +101,7 @@ def update_scheduled_message_backend(
if scheduled_delivery_timestamp is not None:
deliver_at = timestamp_to_datetime(scheduled_delivery_timestamp)
if deliver_at <= timezone_now():
- raise JsonableError(_("Scheduled delivery time must be in the future."))
+ raise DeliveryTimeNotInFutureError
sender = user_profile
client = RequestNotes.get_notes(request).client
@@ -151,7 +151,7 @@ def create_scheduled_message_backend(
deliver_at = timestamp_to_datetime(scheduled_delivery_timestamp)
if deliver_at <= timezone_now():
- raise JsonableError(_("Scheduled delivery time must be in the future."))
+ raise DeliveryTimeNotInFutureError
sender = user_profile
client = RequestNotes.get_notes(request).client