Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api: Fix sending fake users when fetching inaccessible users via API.
Vector73dec9fd3908bb
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex b90f1f73a2a..74f7858996b 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -20,6 +20,16 @@ format used by the Zulip server that they are interacting with.## Changes in Zulip 12.0+**Feature level 437**++* [`GET /users`](/api/get-users), [`GET+ /users/{user_id}`](/api/get-user), [`GET+ /users/{email}`](/api/get-user-by-email): Fixed a bug dating to+ feature level 232, where guest users might incorrectly receive fake+ backwards-compatibility users in the format intended for clients+ using `POST /register` without the `user_list_incomplete` client+ capability.+**Feature level 436*** [Message formatting](/api/message-formatting): Added newdiff --git a/version.py b/version.pyindex 8b1f32225b6..2ed38014469 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 = 436+API_FEATURE_LEVEL = 437# 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. Bumpdiff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex 3c0ac6b29bd..a8886e10627 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -1133,7 +1133,7 @@ def get_users_for_api(client_gravatar: bool,user_avatar_url_field_optional: bool,include_custom_profile_fields: bool = True,- user_list_incomplete: bool = False,+ user_list_incomplete: bool = True,user_ids: list[int] | None = None,) -> dict[int, APIUserDict]:"""Fetches data about the target user(s) appropriate for sending todiff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 72cb5551108..16fefa2f7e8 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -10409,7 +10409,13 @@ paths:You can also [fetch details on a single user](/api/get-user).- **Changes**: This endpoint did not support unauthenticated+ **Changes**: In Zulip 12.0 (feature level 437), fixed a bug+ dating to feature level 232, which caused guest users to+ receive fake backwards-compatibility users in the format+ intended for clients using `POST /register` without the+ `user_list_incomplete` client capability.++ This endpoint did not support unauthenticatedaccess in organizations using the [public accessoption](/help/public-access-option) prior to Zulip 11.0(feature level 387).@@ -14815,7 +14821,13 @@ paths:either of which could change the client's ability to look them up by thatemail address.- **Changes**: Starting with Zulip 10.0 (feature level 302), the real email+ **Changes**: In Zulip 12.0 (feature level 437), fixed a bug+ dating to feature level 232, which caused guest users to+ receive fake backwards-compatibility users in the format+ intended for clients using `POST /register` without the+ `user_list_incomplete` client capability.++ Starting with Zulip 10.0 (feature level 302), the real emailaddress can be used in the `email` parameter and will fetch the target user'sdata if and only if the target's email visibility setting permits the requesterto see the email address.@@ -14981,7 +14993,13 @@ paths:You can also fetch details on [all users in the organization](/api/get-users)or [by a user's Zulip API email](/api/get-user-by-email).- **Changes**: New in Zulip 3.0 (feature level 1).+ **Changes**: In Zulip 12.0 (feature level 437), fixed a bug+ dating to feature level 232, which caused guest users to+ receive fake backwards-compatibility users in the format+ intended for clients using `POST /register` without the+ `user_list_incomplete` client capability.++ New in Zulip 3.0 (feature level 1).x-curl-examples-parameters:oneOf:- type: includediff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 41f620b32e3..cde24e55399 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -3020,9 +3020,6 @@ class GetProfileTest(ZulipTestCase):self.assertEqual(result["user"].get("email"), hamlet.delivery_email)def test_restricted_access_to_users(self) -> None:- othello = self.example_user("othello")- cordelia = self.example_user("cordelia")- desdemona = self.example_user("desdemona")hamlet = self.example_user("hamlet")iago = self.example_user("iago")prospero = self.example_user("prospero")@@ -3036,11 +3033,7 @@ class GetProfileTest(ZulipTestCase):self.login("polonius")with self.assert_database_query_count(9):result = orjson.loads(self.client_get("/json/users").content)- accessible_users = [- user- for user in result["members"]- if user["full_name"] != UserProfile.INACCESSIBLE_USER_NAME- ]+ accessible_users = result["members"]# The user can access 3 bot users and 7 human users.self.assert_length(accessible_users, 10)accessible_human_users = [user for user in accessible_users if not user["is_bot"]]@@ -3059,22 +3052,11 @@ class GetProfileTest(ZulipTestCase):{polonius.id, hamlet.id, iago.id, prospero.id, aaron.id, zoe.id, shiva.id},)- inaccessible_user_ids = {- user["user_id"]- for user in result["members"]- if user["full_name"] == UserProfile.INACCESSIBLE_USER_NAME- }- self.assertEqual(inaccessible_user_ids, {cordelia.id, desdemona.id, othello.id})-do_deactivate_user(hamlet, acting_user=None)do_deactivate_user(aaron, acting_user=None)do_deactivate_user(shiva, acting_user=None)result = orjson.loads(self.client_get("/json/users").content)- accessible_users = [- user- for user in result["members"]- if user["full_name"] != UserProfile.INACCESSIBLE_USER_NAME- ]+ accessible_users = result["members"]self.assert_length(accessible_users, 9)# Guests can only access those deactivated users who were involved in# DMs and not those who were subscribed to some common streams.@@ -3085,13 +3067,6 @@ class GetProfileTest(ZulipTestCase):accessible_user_ids, {polonius.id, iago.id, prospero.id, aaron.id, zoe.id, shiva.id})- inaccessible_user_ids = {- user["user_id"]- for user in result["members"]- if user["full_name"] == UserProfile.INACCESSIBLE_USER_NAME- }- self.assertEqual(inaccessible_user_ids, {cordelia.id, desdemona.id, othello.id, hamlet.id})-def test_get_user_dicts_with_ids(self) -> None:cordelia = self.example_user("cordelia")desdemona = self.example_user("desdemona")@@ -3117,11 +3092,7 @@ class GetProfileTest(ZulipTestCase):"/json/users", {"user_ids": orjson.dumps(user_ids_to_fetch).decode()}).content)- accessible_users = [- user- for user in result["members"]- if user["full_name"] != UserProfile.INACCESSIBLE_USER_NAME- ]+ accessible_users = result["members"]self.assert_length(accessible_users, len(accessible_user_ids_subset))accessible_user_ids = [user["user_id"] for user in accessible_users]self.assertCountEqual(@@ -3130,13 +3101,6 @@ class GetProfileTest(ZulipTestCase):)accessible_human_users = [user for user in accessible_users if not user["is_bot"]]self.assert_length(accessible_human_users, 4)- inaccessible_users = [- user- for user in result["members"]- if user["full_name"] == UserProfile.INACCESSIBLE_USER_NAME- ]- inaccessible_user_ids = [user["user_id"] for user in inaccessible_users]- self.assertCountEqual(inaccessible_user_ids, inaccessible_user_ids_subset)# Desdemona can access all users since she is an admin.self.login("desdemona")