users: Remove short_name and client_id from get_profile_backend.

This commit removes short_name and client_id fields from the user
objects returned by get_profile_backend because neither of them
had a purpose.

* short_name hasn't been present anywhere else in the Zulip API for
  several years, and isn't set through any coherent algorithm.
* client_id was a forgotten 2013-era predecessor to the queue_id field
  returned by the register_event_queue process.

The combination of these changes gets us close to having `get_profile`
have the exact same format as other endpoints fetching a user object.
This commit is contained in:
sahil839 2020-06-09 03:37:13 +05:30 committed by Tim Abbott
parent 1f5778bad7
commit 7de23b8b5c
6 changed files with 9 additions and 27 deletions

View File

@ -14,6 +14,9 @@ below features are supported.
* [`GET users/me`](/api/get-profile): Added `avatar_version`, `is_guest`, * [`GET users/me`](/api/get-profile): Added `avatar_version`, `is_guest`,
`is_active`, `timezone`, and `date_joined` fields to the User objects. `is_active`, `timezone`, and `date_joined` fields to the User objects.
* [`GET users/me`](/api/get-profile): Removed `client_id` and `short_name`
from the reponse to this endpoint. These fields had no purpose and
were inconsistent with other API responses describing users.
**Feature level 9** **Feature level 9**

View File

@ -29,7 +29,7 @@ DESKTOP_WARNING_VERSION = "5.2.0"
# #
# Changes should be accompanied by documentation explaining what the # Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md. # new level means in templates/zerver/api/changelog.md.
API_FEATURE_LEVEL = 9 API_FEATURE_LEVEL = 10
# Bump the minor PROVISION_VERSION to indicate that folks should provision # 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 # only when going from an old version of the code to a newer version. Bump

View File

@ -1846,11 +1846,6 @@ paths:
**Changes**: New in Zulip 2.2 (feature level 10). Previous **Changes**: New in Zulip 2.2 (feature level 10). Previous
versions do not return this field. versions do not return this field.
example: 1 example: 1
client_id:
type: string
description: |
NA
example: "74c768b081076fdb3c4326256c17467e"
email: email:
type: string type: string
description: | description: |
@ -1926,11 +1921,6 @@ paths:
**Deprecated**. We plan to remove the `pointer` as a concept in Zulip. **Deprecated**. We plan to remove the `pointer` as a concept in Zulip.
example: -1 example: -1
short_name:
type: string
description: |
Short name of the requesting user.
example: "iago"
user_id: user_id:
type: integer type: integer
description: | description: |
@ -1942,7 +1932,6 @@ paths:
{ {
"avatar_url": "https://secure.gravatar.com/avatar/af4f06322c177ef4e1e9b2c424986b54?d=identicon&version=1", "avatar_url": "https://secure.gravatar.com/avatar/af4f06322c177ef4e1e9b2c424986b54?d=identicon&version=1",
"avatar_version": 1, "avatar_version": 1,
"client_id": "74c768b081076fdb3c4326256c17467e",
"email": "iago@zulip.com", "email": "iago@zulip.com",
"full_name": "Iago", "full_name": "Iago",
"is_admin": true, "is_admin": true,
@ -1956,7 +1945,6 @@ paths:
"msg": "", "msg": "",
"pointer": -1, "pointer": -1,
"result": "success", "result": "success",
"short_name": "iago",
"user_id": 5, "user_id": 5,
"profile_data": { "profile_data": {
"5": { "5": {

View File

@ -696,10 +696,10 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
def test_get_custom_profile_fields_from_api_for_single_user(self) -> None: def test_get_custom_profile_fields_from_api_for_single_user(self) -> None:
self.login('iago') self.login('iago')
expected_keys = { expected_keys = {
"result", "msg", "pointer", "client_id", "max_message_id", "user_id", "result", "msg", "pointer", "max_message_id", "user_id", "avatar_url",
"avatar_url", "full_name", "email", "is_bot", "is_admin", "is_owner", "full_name", "email", "is_bot", "is_admin", "is_owner", "profile_data",
"short_name", "profile_data", "avatar_version", "timezone", "delivery_email", "avatar_version", "timezone", "delivery_email", "is_active", "is_guest",
"is_active", "is_guest", "date_joined"} "date_joined"}
url = "/json/users/me" url = "/json/users/me"
response = self.client_get(url) response = self.client_get(url)

View File

@ -1337,7 +1337,6 @@ class GetProfileTest(ZulipTestCase):
self.assert_json_success(result) self.assert_json_success(result)
json = result.json() json = result.json()
self.assertIn("client_id", json)
self.assertIn("max_message_id", json) self.assertIn("max_message_id", json)
self.assertIn("pointer", json) self.assertIn("pointer", json)
@ -1372,7 +1371,6 @@ class GetProfileTest(ZulipTestCase):
self.login('hamlet') self.login('hamlet')
result = ujson.loads(self.client_get('/json/users/me').content) result = ujson.loads(self.client_get('/json/users/me').content)
self.assertEqual(result['short_name'], 'hamlet')
self.assertEqual(result['email'], hamlet.email) self.assertEqual(result['email'], hamlet.email)
self.assertEqual(result['full_name'], 'King Hamlet') self.assertEqual(result['full_name'], 'King Hamlet')
self.assertIn("user_id", result) self.assertIn("user_id", result)
@ -1383,7 +1381,6 @@ class GetProfileTest(ZulipTestCase):
self.assertFalse('delivery_email' in result) self.assertFalse('delivery_email' in result)
self.login('iago') self.login('iago')
result = ujson.loads(self.client_get('/json/users/me').content) result = ujson.loads(self.client_get('/json/users/me').content)
self.assertEqual(result['short_name'], 'iago')
self.assertEqual(result['email'], iago.email) self.assertEqual(result['email'], iago.email)
self.assertEqual(result['full_name'], 'Iago') self.assertEqual(result['full_name'], 'Iago')
self.assertFalse(result['is_bot']) self.assertFalse(result['is_bot'])
@ -1392,7 +1389,6 @@ class GetProfileTest(ZulipTestCase):
self.assertFalse(result['is_guest']) self.assertFalse(result['is_guest'])
self.login('desdemona') self.login('desdemona')
result = ujson.loads(self.client_get('/json/users/me').content) result = ujson.loads(self.client_get('/json/users/me').content)
self.assertEqual(result['short_name'], 'desdemona')
self.assertEqual(result['email'], desdemona.email) self.assertEqual(result['email'], desdemona.email)
self.assertFalse(result['is_bot']) self.assertFalse(result['is_bot'])
self.assertTrue(result['is_admin']) self.assertTrue(result['is_admin'])

View File

@ -31,7 +31,7 @@ from zerver.lib.users import check_valid_bot_type, check_bot_creation_policy, \
check_full_name, check_short_name, check_valid_interface_type, check_valid_bot_config, \ check_full_name, check_short_name, check_valid_interface_type, check_valid_bot_config, \
access_bot_by_id, add_service, access_user_by_id, check_bot_name_available, \ access_bot_by_id, add_service, access_user_by_id, check_bot_name_available, \
validate_user_custom_profile_data, get_raw_user_data, get_api_key validate_user_custom_profile_data, get_raw_user_data, get_api_key
from zerver.lib.utils import generate_api_key, generate_random_token from zerver.lib.utils import generate_api_key
from zerver.models import UserProfile, Stream, Message, \ from zerver.models import UserProfile, Stream, Message, \
get_user_by_delivery_email, Service, get_user_including_cross_realm, \ get_user_by_delivery_email, Service, get_user_including_cross_realm, \
DomainNotAllowedForRealmError, DisposableEmailError, get_user_profile_by_id_in_realm, \ DomainNotAllowedForRealmError, DisposableEmailError, get_user_profile_by_id_in_realm, \
@ -454,16 +454,11 @@ def create_user_backend(request: HttpRequest, user_profile: UserProfile,
do_create_user(email, password, realm, full_name, short_name) do_create_user(email, password, realm, full_name, short_name)
return json_success() return json_success()
def generate_client_id() -> str:
return generate_random_token(32)
def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
raw_user_data = get_raw_user_data(user_profile.realm, user_profile, raw_user_data = get_raw_user_data(user_profile.realm, user_profile,
client_gravatar=False, target_user=user_profile) client_gravatar=False, target_user=user_profile)
result: Dict[str, Any] = raw_user_data[user_profile.id] result: Dict[str, Any] = raw_user_data[user_profile.id]
result['client_id'] = generate_client_id()
result['short_name'] = user_profile.short_name
result['max_message_id'] = -1 result['max_message_id'] = -1
result['pointer'] = user_profile.pointer result['pointer'] = user_profile.pointer