mirror of https://github.com/zulip/zulip.git
zilencer: Improve json error when plan doesn't allow push notifs.
This allows the self-hosted server to explicitly test for that exception and catch and log it nicely.
This commit is contained in:
parent
d29cd04387
commit
3bda31c48c
|
@ -51,6 +51,7 @@ class ErrorCode(Enum):
|
||||||
STREAM_WILDCARD_MENTION_NOT_ALLOWED = auto()
|
STREAM_WILDCARD_MENTION_NOT_ALLOWED = auto()
|
||||||
REMOTE_BILLING_UNAUTHENTICATED_USER = auto()
|
REMOTE_BILLING_UNAUTHENTICATED_USER = auto()
|
||||||
REMOTE_REALM_SERVER_MISMATCH_ERROR = auto()
|
REMOTE_REALM_SERVER_MISMATCH_ERROR = auto()
|
||||||
|
PUSH_NOTIFICATIONS_DISALLOWED = auto()
|
||||||
|
|
||||||
|
|
||||||
class JsonableError(Exception):
|
class JsonableError(Exception):
|
||||||
|
|
|
@ -829,8 +829,11 @@ class PushBouncerNotificationTest(BouncerTestCase):
|
||||||
payload,
|
payload,
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
self.assert_json_error(result, "Your plan doesn't allow sending push notifications.")
|
self.assert_json_error(
|
||||||
self.assertEqual(orjson.loads(result.content)["code"], "BAD_REQUEST")
|
result,
|
||||||
|
"Your plan doesn't allow sending push notifications. Reason provided by the server: Missing data",
|
||||||
|
)
|
||||||
|
self.assertEqual(orjson.loads(result.content)["code"], "PUSH_NOTIFICATIONS_DISALLOWED")
|
||||||
|
|
||||||
human_counts = {
|
human_counts = {
|
||||||
str(UserProfile.ROLE_REALM_ADMINISTRATOR): 1,
|
str(UserProfile.ROLE_REALM_ADMINISTRATOR): 1,
|
||||||
|
@ -854,8 +857,11 @@ class PushBouncerNotificationTest(BouncerTestCase):
|
||||||
payload,
|
payload,
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
self.assert_json_error(result, "Your plan doesn't allow sending push notifications.")
|
self.assert_json_error(
|
||||||
self.assertEqual(orjson.loads(result.content)["code"], "BAD_REQUEST")
|
result,
|
||||||
|
"Your plan doesn't allow sending push notifications. Reason provided by the server: No plan many users",
|
||||||
|
)
|
||||||
|
self.assertEqual(orjson.loads(result.content)["code"], "PUSH_NOTIFICATIONS_DISALLOWED")
|
||||||
|
|
||||||
# Check that sponsored realms are allowed to send push notifications.
|
# Check that sponsored realms are allowed to send push notifications.
|
||||||
remote_server.plan_type = RemoteRealm.PLAN_TYPE_COMMUNITY
|
remote_server.plan_type = RemoteRealm.PLAN_TYPE_COMMUNITY
|
||||||
|
|
|
@ -472,6 +472,16 @@ class OldZulipServerError(JsonableError):
|
||||||
self._msg: str = msg
|
self._msg: str = msg
|
||||||
|
|
||||||
|
|
||||||
|
class PushNotificationsDisallowedError(JsonableError):
|
||||||
|
code = ErrorCode.PUSH_NOTIFICATIONS_DISALLOWED
|
||||||
|
|
||||||
|
def __init__(self, reason: str) -> None:
|
||||||
|
msg = _(
|
||||||
|
"Your plan doesn't allow sending push notifications. Reason provided by the server: {reason}"
|
||||||
|
).format(reason=reason)
|
||||||
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def remote_server_notify_push(
|
def remote_server_notify_push(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
|
@ -502,7 +512,8 @@ def remote_server_notify_push(
|
||||||
if server.last_api_feature_level is None:
|
if server.last_api_feature_level is None:
|
||||||
raise OldZulipServerError(_("Your plan doesn't allow sending push notifications."))
|
raise OldZulipServerError(_("Your plan doesn't allow sending push notifications."))
|
||||||
else:
|
else:
|
||||||
raise JsonableError(_("Your plan doesn't allow sending push notifications."))
|
reason = push_status.message
|
||||||
|
raise PushNotificationsDisallowedError(reason=reason)
|
||||||
|
|
||||||
android_devices = list(
|
android_devices = list(
|
||||||
RemotePushDeviceToken.objects.filter(
|
RemotePushDeviceToken.objects.filter(
|
||||||
|
|
Loading…
Reference in New Issue