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.

api: Remove 'PATCH /users/me/subscriptions' endpoint.

Agnish Bauri4ceb7af24865
diff --git a/api_docs/unmerged.d/ZF-354733.md b/api_docs/unmerged.d/ZF-354733.md
new file mode 100644
index 00000000000..767d8f72a0e
--- /dev/null
+++ b/api_docs/unmerged.d/ZF-354733.md
@@ -0,0 +1,7 @@
+* The undocumented `PATCH /users/me/subscriptions` endpoint for
+ updating channel subscriptions has been deprecated and
+ removed. It was a duplicate of the documented bulk-subscribe
+ ([`POST /users/me/subscriptions`](/api/subscribe)) and
+ bulk-unsubscribe ([`DELETE /users/me/subscriptions`](/api/unsubscribe))
+ endpoints, which clients should use to subscribe/unsubscribe
+ users from channels.
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 444c8979bb4..b10f152bf6f 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -13462,140 +13462,6 @@ paths:
description: |
An example JSON response for when the requesting user does not have
access to a private channel and `"authorization_errors_fatal": true`:
- patch:
- operationId: update-subscriptions
- summary: Update subscriptions
- tags: ["channels"]
- description: |
- Update which channels you are subscribed to.
-
- **Changes**: Before Zulip 10.0 (feature level 362),
- subscriptions in archived channels could not be modified.
- requestBody:
- required: false
- content:
- application/x-www-form-urlencoded:
- schema:
- type: object
- properties:
- delete:
- description: |
- A list of channel names to unsubscribe from.
- type: array
- items:
- type: string
- example: ["Verona", "Denmark"]
- add:
- description: |
- A list of objects describing which channels to subscribe to, optionally
- including per-user subscription parameters (e.g. color) and if the
- channel is to be created, its description.
- type: array
- items:
- type: object
- additionalProperties: false
- properties:
- name:
- type: string
- color:
- type: string
- description:
- type: string
- example:
- [
- {"name": "Verona"},
- {
- "name": "Denmark",
- "color": "#e79ab5",
- "description": "A Scandinavian country",
- },
- ]
- encoding:
- delete:
- contentType: application/json
- add:
- contentType: application/json
- responses:
- "200":
- description: Success.
- content:
- application/json:
- schema:
- allOf:
- - $ref: "#/components/schemas/JsonSuccessBase"
- - required:
- - subscribed
- - already_subscribed
- - removed
- additionalProperties: false
- properties:
- result: {}
- msg: {}
- ignored_parameters_unsupported: {}
- subscribed:
- type: object
- description: |
- A dictionary where the key is the Zulip API email
- address of the user/bot and the value is a
- list of the names of the channels that were
- subscribed to as a result of the query.
- additionalProperties:
- description: |
- `{email_id}`: A list of the names of channels that
- the user was subscribed to as a result of the query.
- type: array
- items:
- type: string
- already_subscribed:
- type: object
- description: |
- A dictionary where the key is the Zulip API email
- address of the user/bot and the value is a
- list of the names of the channels that the
- user/bot is already subscribed to.
- additionalProperties:
- description: |
- `{email_id}`: A list of the names of channels that
- the user was already subscribed to.
- type: array
- items:
- type: string
- not_removed:
- type: array
- items:
- type: string
- description: |
- A list of the names of channels that the user
- is already unsubscribed from, and hence
- doesn't need to be unsubscribed.
- removed:
- type: array
- items:
- type: string
- description: |
- A list of the names of channels which were unsubscribed
- from as a result of the query.
- new_subscription_messages_sent:
- type: boolean
- description: |
- Only present if the parameter `send_new_subscription_messages`
- in the request was `true`.
-
- Whether Notification Bot DMs in fact sent to the added
- subscribers as requested by the `send_new_subscription_messages`
- parameter. Clients may find this value useful to communicate
- with users about the effect of this request.
-
- **Changes**: New in Zulip 11.0 (feature level 397).
- example:
- {
- "msg": "",
- "subscribed": {},
- "already_subscribed": {"[email protected]": ["Verona"]},
- "not_removed": [],
- "removed": ["testing-help"],
- "result": "success",
- }
delete:
operationId: unsubscribe
summary: Unsubscribe from a channel
diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py
index 94dcabdfc4d..9ddb811d60f 100644
--- a/zerver/tests/test_openapi.py
+++ b/zerver/tests/test_openapi.py
@@ -1027,9 +1027,6 @@ class APIDocsSidebarTest(ZulipTestCase):
exempted_docs = {
# (No /api/v1/ or /json prefix).
"get-file-temporary-url",
- # This one is not used by any clients and is likely to get
- # deprecated.
- "update-subscriptions",
# This is rendered on the "Outgoing webhooks" page and hence is not
# linked in the sidebar.
"zulip-outgoing-webhooks",
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index b36bc75493c..bc0627abd6d 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -3511,40 +3511,10 @@ class StreamAdminTest(ZulipTestCase):
class SubscriptionRestApiTest(ZulipTestCase):
- def test_basic_add_delete(self) -> None:
+ def test_add_with_invalid_color(self) -> None:
user = self.example_user("hamlet")
self.login_user(user)
- # add
- request = {
- "add": orjson.dumps([{"name": "my_test_stream_1"}]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_success(result)
- streams = self.get_streams(user)
- self.assertTrue("my_test_stream_1" in streams)
-
- # now delete the same stream
- request = {
- "delete": orjson.dumps(["my_test_stream_1"]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_success(result)
- streams = self.get_streams(user)
- self.assertTrue("my_test_stream_1" not in streams)
-
- def test_add_with_color(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- # add with color proposition
- request = {
- "add": orjson.dumps([{"name": "my_test_stream_2", "color": "#afafaf"}]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_success(result)
-
- # incorrect color format
subscriptions = [{"name": "my_test_stream_3", "color": "#0g0g0g"}]
result = self.subscribe_via_post(user, subscriptions, allow_fail=True)
self.assert_json_error(
@@ -3661,92 +3631,10 @@ class SubscriptionRestApiTest(ZulipTestCase):
result = self.api_delete(user, "/api/v1/users/me/subscriptions", request)
self.assert_json_error(result, "Invalid character in channel name, at position 4.")
- def test_bad_add_parameters(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- def check_for_error(val: Any, expected_message: str) -> None:
- request = {
- "add": orjson.dumps(val).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, expected_message)
-
- check_for_error(
- ["foo"],
- "Invalid add[0]: Input should be a valid dictionary or instance of AddSubscriptionData",
- )
- check_for_error([{"bogus": "foo"}], 'add[0]["name"] field is missing: Field required')
- check_for_error([{"name": {}}], 'add[0]["name"] is not a string')
-
- def test_bad_principals(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- request = {
- "add": orjson.dumps([{"name": "my_new_stream"}]).decode(),
- "principals": orjson.dumps([{}]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, 'principals["list[str]"][0] is not a string')
-
- def test_bad_delete_parameters(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- request = {
- "delete": orjson.dumps([{"name": "my_test_stream_1"}]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, "delete[0] is not a string")
-
- def test_add_or_delete_not_specified(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", {})
- self.assert_json_error(result, 'Nothing to do. Specify at least one of "add" or "delete".')
-
- def test_patch_enforces_valid_stream_name_check(self) -> None:
- """
- Only way to force an error is with an empty string.
- """
- user = self.example_user("hamlet")
- self.login_user(user)
-
- invalid_stream_name = ""
- request = {
- "delete": orjson.dumps([invalid_stream_name]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, "Channel name can't be empty.")
-
- def test_stream_name_too_long(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- long_stream_name = "a" * 61
- request = {
- "delete": orjson.dumps([long_stream_name]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, "Channel name too long (limit: 60 characters).")
-
- def test_stream_name_contains_null(self) -> None:
- user = self.example_user("hamlet")
- self.login_user(user)
-
- stream_name = "abc\000"
- request = {
- "delete": orjson.dumps([stream_name]).decode(),
- }
- result = self.api_patch(user, "/api/v1/users/me/subscriptions", request)
- self.assert_json_error(result, "Invalid character in channel name, at position 4.")
-
def test_compose_views_rollback(self) -> None:
"""
The compose_views function() is used under the hood by
- update_subscriptions_backend. It's a pretty simple method in terms of
+ zerver.views.user_groups. It's a pretty simple method in terms of
control flow, but it uses a Django rollback, which may make it brittle
code when we upgrade Django. We test the functions's rollback logic
here with a simple scenario to avoid false positives related to
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 2ff92aa639a..5a39823d0a2 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -572,30 +572,6 @@ class AddSubscriptionData(BaseModel):
return self
-@typed_endpoint
-def update_subscriptions_backend(
- request: HttpRequest,
- user_profile: UserProfile,
- *,
- add: Json[list[AddSubscriptionData]] | None = None,
- delete: Json[list[str]] | None = None,
-) -> HttpResponse:
- if delete is None:
- delete = []
- if add is None:
- add = []
- if not add and not delete:
- raise JsonableError(_('Nothing to do. Specify at least one of "add" or "delete".'))
-
- thunks = [
- lambda: add_subscriptions_backend(request, user_profile, streams_raw=add),
- lambda: remove_subscriptions_backend(request, user_profile, streams_raw=delete),
- ]
- data = compose_views(thunks)
-
- return json_success(request, data)
-
-
def compose_views(thunks: list[Callable[[], HttpResponse]]) -> dict[str, Any]:
"""
This takes a series of thunks and calls them in sequence, and it
diff --git a/zproject/urls.py b/zproject/urls.py
index fe37bc5d930..f3a133ed8df 100644
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -203,7 +203,6 @@ from zerver.views.streams import (
update_default_stream_group_streams,
update_stream_backend,
update_subscription_properties_backend,
- update_subscriptions_backend,
update_subscriptions_property,
)
from zerver.views.submessage import process_submessage
@@ -574,12 +573,11 @@ v1_api_and_json_patterns = [
rest_path(
"default_stream_groups/<int:group_id>/streams", PATCH=update_default_stream_group_streams
),
- # GET lists your streams, POST bulk adds, PATCH bulk modifies/removes
+ # GET lists your streams, POST bulk adds, DELETE bulk removes
rest_path(
"users/me/subscriptions",
GET=list_subscriptions_backend,
POST=add_subscriptions_backend,
- PATCH=update_subscriptions_backend,
DELETE=remove_subscriptions_backend,
),
rest_path("channel_folders/create", POST=create_channel_folder),