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.

push_device_event: Change `push_account_id` field type to integer.

Prakhar Pratyushb0f42ab02da7
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 43b7d50bbd4..604429937f8 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 450**
+
+* [`GET /events`](/api/get-events): The `push_device` events now
+ encode `push_account_id` as an integer, not a string.
+
**Feature level 449**
* [`POST /export/realm`](/api/export-realm): The `export_type` parameter now
diff --git a/version.py b/version.py
index cb2c90e5728..000df52d1b4 100644
--- a/version.py
+++ b/version.py
@@ -35,7 +35,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 449
+API_FEATURE_LEVEL = 450
# 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
diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.py
index 7350c6cd2d7..85f9dd8948f 100644
--- a/zerver/lib/event_types.py
+++ b/zerver/lib/event_types.py
@@ -292,7 +292,7 @@ class EventOnboardingSteps(BaseEvent):
class EventPushDevice(BaseEvent):
type: Literal["push_device"]
- push_account_id: str
+ push_account_id: int
status: Literal["active", "failed", "pending"]
error_code: str | None = None
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index fa7a6b232ab..7a937faf84d 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -2005,8 +2005,8 @@ def apply_event(
# The Tornado process restarted. This has no effect; we ignore it.
pass
elif event["type"] == "push_device":
- state["push_devices"][event["push_account_id"]]["status"] = event["status"]
- state["push_devices"][event["push_account_id"]]["error_code"] = event.get("error_code")
+ state["push_devices"][str(event["push_account_id"])]["status"] = event["status"]
+ state["push_devices"][str(event["push_account_id"])]["error_code"] = event.get("error_code")
else:
raise AssertionError("Unexpected event type {}".format(event["type"]))
diff --git a/zerver/lib/push_registration.py b/zerver/lib/push_registration.py
index bb077868507..c6f6112ff86 100644
--- a/zerver/lib/push_registration.py
+++ b/zerver/lib/push_registration.py
@@ -55,7 +55,7 @@ def handle_registration_to_bouncer_failure(
)
event = dict(
type="push_device",
- push_account_id=str(push_account_id),
+ push_account_id=push_account_id,
status="failed",
error_code=error_code,
)
@@ -137,7 +137,7 @@ def handle_register_push_device_to_bouncer(
)
event = dict(
type="push_device",
- push_account_id=str(push_account_id),
+ push_account_id=push_account_id,
status="active",
)
send_event_on_commit(user_profile.realm, event, [user_profile.id])
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 7af39599b3e..9916911d7ee 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -1791,12 +1791,15 @@ paths:
- enum:
- push_device
push_account_id:
- type: string
+ type: integer
description: |
The push account ID for this client registration.
See [`POST /mobile_push/register`](/api/register-push-device)
for details on push account IDs.
+
+ **Changes**: Prior to Zulip 12.0 (feature level 450),
+ the integer value was expressed as a string.
status:
type: string
enum:
@@ -1823,7 +1826,7 @@ paths:
{
"id": 1,
"type": "push_device",
- "push_account_id": "1234",
+ "push_account_id": 1234,
"status": "active",
}
- type: object
diff --git a/zerver/tests/test_push_registration.py b/zerver/tests/test_push_registration.py
index e87337a51d5..f930b538f6e 100644
--- a/zerver/tests/test_push_registration.py
+++ b/zerver/tests/test_push_registration.py
@@ -274,7 +274,7 @@ class RegisterPushDeviceToServer(BouncerTestCase):
self.assertEqual(push_devices[0].status, "active")
self.assertEqual(
events[0]["event"],
- dict(type="push_device", push_account_id="2408", status="active"),
+ dict(type="push_device", push_account_id=2408, status="active"),
)
# Idempotent
@@ -299,7 +299,7 @@ class RegisterPushDeviceToServer(BouncerTestCase):
self.assertEqual(push_devices[1].status, "active")
self.assertEqual(
events[0]["event"],
- dict(type="push_device", push_account_id="5555", status="active"),
+ dict(type="push_device", push_account_id=5555, status="active"),
)
@override_settings(ZILENCER_ENABLED=False)
@@ -366,7 +366,7 @@ class RegisterPushDeviceToServer(BouncerTestCase):
events[0]["event"],
dict(
type="push_device",
- push_account_id="2408",
+ push_account_id=2408,
status="failed",
error_code="INVALID_BOUNCER_PUBLIC_KEY",
),
@@ -407,7 +407,7 @@ class RegisterPushDeviceToServer(BouncerTestCase):
events[0]["event"],
dict(
type="push_device",
- push_account_id="2408",
+ push_account_id=2408,
status="failed",
error_code="BAD_REQUEST",
),
@@ -441,7 +441,7 @@ class RegisterPushDeviceToServer(BouncerTestCase):
events[0]["event"],
dict(
type="push_device",
- push_account_id="2408",
+ push_account_id=2408,
status="failed",
error_code="REQUEST_EXPIRED",
),