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.

register-queue: Remove `push_devices` map and `push_device` event.

Prakhar Pratyush559ff1444c28
diff --git a/api_docs/unmerged.d/ZF-42fbcd.md b/api_docs/unmerged.d/ZF-42fbcd.md
index 369033e8d88..b7dfc1a565b 100644
--- a/api_docs/unmerged.d/ZF-42fbcd.md
+++ b/api_docs/unmerged.d/ZF-42fbcd.md
@@ -11,3 +11,6 @@
of `push_key` and FCM/APNs provided token.
* [`POST /mobile_push/e2ee/test_notification`](/api/e2ee-test-notify):
Replaced `push_account_id` parameter with `device_id`.
+* [`POST /register`](/api/register-queue): Removed `push_devices`
+ field from response.
+* [`GET /events`](/api/get-events): Removed `push_device` event.
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index c122e65c146..fc6c9d545a8 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -48,7 +48,6 @@ from zerver.lib.event_types import (
EventNavigationViewRemove,
EventNavigationViewUpdate,
EventOnboardingSteps,
- EventPushDevice,
EventReactionAdd,
EventReactionRemove,
EventRealmBotAdd,
@@ -191,7 +190,6 @@ check_navigation_view_add = make_checker(EventNavigationViewAdd)
check_navigation_view_remove = make_checker(EventNavigationViewRemove)
check_navigation_view_update = make_checker(EventNavigationViewUpdate)
check_onboarding_steps = make_checker(EventOnboardingSteps)
-check_push_device = make_checker(EventPushDevice)
check_reaction_add = make_checker(EventReactionAdd)
check_reaction_remove = make_checker(EventReactionRemove)
check_realm_bot_delete = make_checker(EventRealmBotDelete)
diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.py
index 988b6f162d6..5770bf9d1b4 100644
--- a/zerver/lib/event_types.py
+++ b/zerver/lib/event_types.py
@@ -290,13 +290,6 @@ class EventOnboardingSteps(BaseEvent):
onboarding_steps: list[OnboardingSteps]
-class EventPushDevice(BaseEvent):
- type: Literal["push_device"]
- push_account_id: int
- status: Literal["active", "failed", "pending"]
- error_code: str | None = None
-
-
class EventDeviceAdd(BaseEvent):
type: Literal["device"]
op: Literal["add"]
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 1a0df57b90a..3ed73673fcb 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -55,7 +55,6 @@ from zerver.lib.narrow_predicate import check_narrow_for_events
from zerver.lib.navigation_views import get_navigation_views_for_user
from zerver.lib.onboarding_steps import get_next_onboarding_steps
from zerver.lib.presence import get_presence_for_user, get_presences_for_realm
-from zerver.lib.push_notifications import get_push_devices
from zerver.lib.realm_icon import realm_icon_url
from zerver.lib.realm_logo import get_realm_logo_source, get_realm_logo_url
from zerver.lib.scheduled_messages import (
@@ -949,9 +948,6 @@ def fetch_initial_state_data(
# See Giphy comment above; Tenor API keys work similarly.
state["tenor_api_key"] = settings.TENOR_API_KEY or ""
- if want("push_device"):
- state["push_devices"] = {} if user_profile is None else get_push_devices(user_profile)
-
if want("device"):
state["devices"] = {} if user_profile is None else get_devices(user_profile)
@@ -2017,9 +2013,6 @@ def apply_event(
elif event["type"] == "restart":
# The Tornado process restarted. This has no effect; we ignore it.
pass
- elif event["type"] == "push_device":
- 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")
elif event["type"] == "device":
if event["op"] == "add":
state["devices"][str(event["device_id"])] = {
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index 7022f8e5789..9e81967e9f1 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -68,7 +68,6 @@ from zerver.models import (
ArchivedMessage,
Device,
Message,
- PushDevice,
PushDeviceToken,
Realm,
Recipient,
@@ -2038,19 +2037,6 @@ class PushDeviceInfoDict(TypedDict):
error_code: str | None
-def get_push_devices(user_profile: UserProfile) -> dict[str, PushDeviceInfoDict]:
- # We intentionally don't try to save a database query
- # if `push_notifications_configured()` is False, in order to avoid
- # risk of clients deleting their Account records if the server
- # has its mobile notifications configuration temporarily disabled.
- rows = PushDevice.objects.filter(user=user_profile)
-
- return {
- str(row.push_account_id): {"status": row.status, "error_code": row.error_code}
- for row in rows
- }
-
-
class NoActivePushDeviceError(JsonableError):
code = ErrorCode.NO_ACTIVE_PUSH_DEVICE
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 76a46e61fde..9bd6101304d 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -1791,63 +1791,6 @@ paths:
"upload_space_used": 0,
"id": 0,
}
- - type: object
- additionalProperties: false
- description: |
- Event sent to a user's clients when the metadata in the
- `push_devices` dictionary for the user changes.
-
- Helps clients to live-update the `push_devices` dictionary
- returned in [`POST /register`](/api/register-queue) response.
-
- **Changes**: New in Zulip 11.0 (feature level 406).
- properties:
- id:
- $ref: "#/components/schemas/EventIdSchema"
- type:
- allOf:
- - $ref: "#/components/schemas/EventTypeSchema"
- - enum:
- - push_device
- push_account_id:
- 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:
- - active
- - failed
- - pending
- description: |
- The updated registration status. Will be `"active"`, `"failed"`, or
- `"pending"`.
- error_code:
- type: string
- nullable: true
- description: |
- If the status is `"failed"`, a [Zulip API error
- code](/api/rest-error-handling) indicating the type of failure that
- occurred.
-
- The following error codes have recommended client behavior:
-
- - `"INVALID_BOUNCER_PUBLIC_KEY"` - Inform the user to update app.
- - `"REQUEST_EXPIRED` - Retry with a fresh payload.
- If the status is "failed", an error code explaining the failure.
- example:
- {
- "id": 1,
- "type": "push_device",
- "push_account_id": 1234,
- "status": "active",
- }
- type: object
additionalProperties: false
description: |
@@ -18687,39 +18630,6 @@ paths:
[Tenor API TOS](https://developers.google.com/tenor/guides/api-terms).
**Changes**: New in Zulip 12.0 (feature level 442).
- push_devices:
- type: object
- description: |
- Present if `push_device` is present in `fetch_event_types`.
-
- Dictionary where each entry describes the user's push device's
- registration status and error code (if registration failed).
-
- **Changes**: New in Zulip 11.0 (feature level 406).
- additionalProperties:
- description: |
- `{push_account_id}`: Dictionary containing the details of
- a push device with the push account ID as the key.
- type: object
- additionalProperties: false
- properties:
- status:
- type: string
- description: |
- The push account's registration status.
- Either `"active"`, `"pending"`, or `"failed"`.
- error_code:
- type: string
- nullable: true
- description: |
- If the status is `"failed"`, a [Zulip API error
- code](/api/rest-error-handling) indicating the type of failure that
- occurred.
-
- The following error codes have recommended client behavior:
-
- - `"INVALID_BOUNCER_PUBLIC_KEY"` - Inform the user to update app.
- - `"REQUEST_EXPIRED` - Retry with a fresh payload.
devices:
type: object
description: |
diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py
index 65719d14ef5..1ae66b6072a 100644
--- a/zerver/tests/test_event_system.py
+++ b/zerver/tests/test_event_system.py
@@ -1223,7 +1223,7 @@ class FetchQueriesTest(ZulipTestCase):
self.login_user(user)
with (
- self.assert_database_query_count(49),
+ self.assert_database_query_count(48),
mock.patch("zerver.lib.events.always_want") as want_mock,
):
fetch_initial_state_data(user, realm=user.realm)
@@ -1244,7 +1244,6 @@ class FetchQueriesTest(ZulipTestCase):
navigation_views=1,
onboarding_steps=1,
presence=1,
- push_device=1,
# 2 of the 3 queries here are a single query that is used
# for all the 'realm', 'stream', 'subscription'
# and 'realm_user_groups' event types.
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index e5135524a66..02e1deeb4e2 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -4,7 +4,6 @@
# This module is closely integrated with zerver/lib/event_schema.py
# and zerver/lib/data_types.py systems for validating the schemas of
# events; it also uses the OpenAPI tools to validate our documentation.
-import base64
import copy
import time
from collections.abc import Callable, Iterator
@@ -195,7 +194,6 @@ from zerver.lib.event_schema import (
check_navigation_view_remove,
check_navigation_view_update,
check_onboarding_steps,
- check_push_device,
check_reaction_add,
check_reaction_remove,
check_realm_bot_add,
@@ -250,14 +248,9 @@ from zerver.lib.event_schema import (
check_user_topic,
)
from zerver.lib.events import apply_events, fetch_initial_state_data, post_process_state
-from zerver.lib.exceptions import InvalidBouncerPublicKeyError
from zerver.lib.markdown import render_message_markdown
from zerver.lib.mention import MentionBackend, MentionData
from zerver.lib.muted_users import get_mute_object
-from zerver.lib.push_registration import (
- RegisterPushDeviceToBouncerQueueItem,
- handle_register_push_device_to_bouncer,
-)
from zerver.lib.streams import check_update_all_streams_active_status, user_has_metadata_access
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import (
@@ -290,7 +283,6 @@ from zerver.models import (
MultiuseInvite,
NamedUserGroup,
PreregistrationUser,
- PushDevice,
Realm,
RealmAuditLog,
RealmDomain,
@@ -4290,35 +4282,6 @@ class NormalActionsTest(BaseAction):
self.assertEqual(audit_log.acting_user, self.user_profile)
self.assertEqual(audit_log.extra_data["realm_export_id"], export_row_id)
- def test_push_device_registration_failure(self) -> None:
- hamlet = self.example_user("hamlet")
- self.login_user(hamlet)
-
- push_device = PushDevice.objects.create(
- user=hamlet,
- token_kind=PushDevice.TokenKind.FCM,
- push_account_id=2408,
- push_key=base64.b64decode("MbZ1JWx6YMHw1cZEgCPRQAgolV3lBRefP5qp/GNisiP+"),
- )
-
- queue_item: RegisterPushDeviceToBouncerQueueItem = {
- "user_profile_id": push_device.user.id,
- "push_account_id": push_device.push_account_id,
- "bouncer_public_key": "bouncer-public-key",
- "encrypted_push_registration": "encrypted-push-registration",
- }
- with (
- mock.patch(
- "zerver.lib.push_registration.do_register_remote_push_device",
- side_effect=InvalidBouncerPublicKeyError,
- ),
- self.verify_action(state_change_expected=True, num_events=1) as events,
- ):
- handle_register_push_device_to_bouncer(queue_item)
- check_push_device("events[0]", events[0])
- self.assertEqual(events[0]["status"], "failed")
- self.assertEqual(events[0]["error_code"], "INVALID_BOUNCER_PUBLIC_KEY")
-
def test_register_device(self) -> None:
with self.verify_action() as events:
do_register_device(self.user_profile)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 4d85a296422..8452d7e95ca 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -123,7 +123,6 @@ class HomeTest(ZulipTestCase):
"password_max_length",
"presences",
"presence_last_update_id",
- "push_devices",
"queue_id",
"realm_allow_edit_history",
"realm_allow_message_editing",
@@ -299,7 +298,7 @@ class HomeTest(ZulipTestCase):
# Verify succeeds once logged-in
with (
- self.assert_database_query_count(59),
+ self.assert_database_query_count(58),
patch("zerver.lib.cache.cache_set") as cache_mock,
):
result = self._get_home_page(stream="Denmark")
@@ -606,7 +605,7 @@ class HomeTest(ZulipTestCase):
# Verify number of queries for Realm admin isn't much higher than for normal users.
self.login("iago")
with (
- self.assert_database_query_count(58),
+ self.assert_database_query_count(57),
patch("zerver.lib.cache.cache_set") as cache_mock,
):
result = self._get_home_page()
@@ -638,7 +637,7 @@ class HomeTest(ZulipTestCase):
self._get_home_page()
# Then for the second page load, measure the number of queries.
- with self.assert_database_query_count(54):
+ with self.assert_database_query_count(53):
result = self._get_home_page()
# Do a sanity check that our new streams were in the payload.