users: Add role field to user objects returned by format_user_row.

This commit modifies the user objects returned by 'GET /users',
'GET /users/me', 'GET /users/{user_id}' and 'GET /users/{email}'
endpoints to include role field.

We also include role field in the page_params['realm_users'] dict
and in the person object sent in (type="realm_user", op="add")
event.
This commit is contained in:
sahil839 2021-04-11 11:08:09 +05:30 committed by Tim Abbott
parent 8711ab7676
commit 34f134d58d
9 changed files with 77 additions and 2 deletions

View File

@ -489,6 +489,7 @@ exports.fixtures = {
is_admin: false,
is_active: true,
is_owner: false,
role: 400,
is_bot: false,
is_guest: false,
profile_data: {},

View File

@ -12,6 +12,14 @@ below features are supported.
**Feature level 59**
* [`GET /users`](/api/get-users), [`GET /users/{user_id}`](/api/get-user),
[`GET /users/{email}`](/api/get-user-by-email) and
[`GET /users/me`](/api/get-own-user): Added `role` field to returned
user objects.
* [`GET /events`](/api/get-events): Added `role` field to
user objects sent in `realm_user` events.
* [`POST /register`](/api/register-queue): Added `role` field
in the user objects returned in the `realm_users` field.
* [`GET /events`](/api/get-events): Added new `zulip_version` and
`zulip_feature_level` fields to the `restart` event.

View File

@ -30,7 +30,7 @@ DESKTOP_WARNING_VERSION = "5.2.0"
#
# Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md.
API_FEATURE_LEVEL = 58
API_FEATURE_LEVEL = 59
# 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

View File

@ -1013,6 +1013,7 @@ realm_user_type = DictType(
("is_owner", bool),
("is_bot", bool),
("is_guest", bool),
("role", EnumType(UserProfile.ROLE_TYPES)),
("is_active", bool),
("profile_data", StringDictType(dict)),
("timezone", str),

View File

@ -374,6 +374,7 @@ def format_user_row(
is_admin=is_admin,
is_owner=is_owner,
is_guest=is_guest,
role=row["role"],
is_bot=is_bot,
full_name=row["full_name"],
timezone=canonicalize_timezone(row["timezone"]),

View File

@ -814,6 +814,7 @@ paths:
"is_admin": false,
"is_owner": false,
"is_guest": false,
"role": 400,
"is_bot": false,
"full_name": "full name",
"timezone": "",
@ -5036,6 +5037,7 @@ paths:
"email": "AARON@zulip.com",
"is_admin": false,
"is_owner": false,
"role": 400,
"avatar_url": "https://secure.gravatar.com/avatar/818c212b9f8830dfef491b3f7da99a14?d=identicon&version=1",
"bot_type": null,
"timezone": "",
@ -5079,6 +5081,7 @@ paths:
"timezone": "",
"is_admin": false,
"is_owner": false,
"role": 400,
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
"is_active": true,
"email": "hamlet@zulip.com",
@ -5093,6 +5096,7 @@ paths:
"avatar_url": "https://secure.gravatar.com/avatar/7328586831cdbb1627649bd857b1ee8c?d=identicon&version=1",
"is_admin": false,
"is_owner": false,
"role": 400,
"user_id": 23,
"bot_type": 1,
"timezone": "",
@ -5337,6 +5341,25 @@ paths:
**Changes**: New in Zulip 3.0 (feature level 8).
example: false
role:
type: integer
enum:
- 100
- 200
- 300
- 400
- 600
description: |
[Organization-level role](/help/roles-and-permissions)) of the user.
Poosible values are:
* Organization owner => 100
* Organization administrator => 200
* Organization moderator => 300
* Member => 400
* Guest => 600
**Changes**: New in Zulip 4.0 (feature level 59).
is_guest:
type: boolean
description: |
@ -5405,6 +5428,7 @@ paths:
"full_name": "Iago",
"is_admin": true,
"is_owner": false,
"role": 200,
"is_guest": false,
"is_bot": false,
"is_active": true,
@ -6612,6 +6636,7 @@ paths:
"timezone": "",
"is_admin": false,
"is_owner": false,
"role": 400,
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
"is_active": true,
"email": "hamlet@zulip.com",
@ -6686,6 +6711,7 @@ paths:
"timezone": "",
"is_admin": false,
"is_owner": false,
"role": 400,
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
"is_active": true,
"email": "hamlet@zulip.com",
@ -8969,6 +8995,7 @@ paths:
full_name: {}
is_admin: {}
is_owner: {}
role: {}
bot_type: {}
user_id: {}
bot_owner_id: {}
@ -11635,6 +11662,7 @@ components:
full_name: {}
is_admin: {}
is_owner: {}
role: {}
bot_type: {}
user_id: {}
bot_owner_id: {}
@ -11692,6 +11720,25 @@ components:
If true, is_admin will also be true.
**Changes**: New in Zulip 3.0 (feature level 8).
role:
type: integer
enum:
- 100
- 200
- 300
- 400
- 600
description: |
[Organization-level role](/help/roles-and-permissions)) of the user.
Poosible values are:
* Organization owner => 100
* Organization administrator => 200
* Organization moderator => 300
* Member => 400
* Guest => 600
**Changes**: New in Zulip 4.0 (feature level 59).
bot_type:
type: integer
nullable: true

View File

@ -782,6 +782,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"is_guest",
"is_bot",
"is_owner",
"role",
"full_name",
"timezone",
"is_active",
@ -801,6 +802,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"is_guest",
"is_bot",
"is_owner",
"role",
"full_name",
"timezone",
"is_active",
@ -832,6 +834,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"is_bot",
"is_admin",
"is_owner",
"role",
"profile_data",
"avatar_version",
"timezone",

View File

@ -631,6 +631,7 @@ class HomeTest(ZulipTestCase):
is_bot=True,
is_admin=False,
is_owner=False,
role=email_gateway_bot.role,
is_cross_realm_bot=True,
is_guest=False,
),
@ -645,6 +646,7 @@ class HomeTest(ZulipTestCase):
is_bot=True,
is_admin=False,
is_owner=False,
role=notification_bot.role,
is_cross_realm_bot=True,
is_guest=False,
),
@ -659,6 +661,7 @@ class HomeTest(ZulipTestCase):
is_bot=True,
is_admin=False,
is_owner=False,
role=welcome_bot.role,
is_cross_realm_bot=True,
is_guest=False,
),

View File

@ -1709,7 +1709,7 @@ class GetProfileTest(ZulipTestCase):
hamlet = self.example_user("hamlet")
iago = self.example_user("iago")
desdemona = self.example_user("desdemona")
shiva = self.example_user("shiva")
self.login("hamlet")
result = orjson.loads(self.client_get("/json/users/me").content)
self.assertEqual(result["email"], hamlet.email)
@ -1719,6 +1719,7 @@ class GetProfileTest(ZulipTestCase):
self.assertFalse(result["is_admin"])
self.assertFalse(result["is_owner"])
self.assertFalse(result["is_guest"])
self.assertEqual(result["role"], UserProfile.ROLE_MEMBER)
self.assertFalse("delivery_email" in result)
self.login("iago")
result = orjson.loads(self.client_get("/json/users/me").content)
@ -1728,6 +1729,7 @@ class GetProfileTest(ZulipTestCase):
self.assertTrue(result["is_admin"])
self.assertFalse(result["is_owner"])
self.assertFalse(result["is_guest"])
self.assertEqual(result["role"], UserProfile.ROLE_REALM_ADMINISTRATOR)
self.login("desdemona")
result = orjson.loads(self.client_get("/json/users/me").content)
self.assertEqual(result["email"], desdemona.email)
@ -1735,6 +1737,15 @@ class GetProfileTest(ZulipTestCase):
self.assertTrue(result["is_admin"])
self.assertTrue(result["is_owner"])
self.assertFalse(result["is_guest"])
self.assertEqual(result["role"], UserProfile.ROLE_REALM_OWNER)
self.login("shiva")
result = orjson.loads(self.client_get("/json/users/me").content)
self.assertEqual(result["email"], shiva.email)
self.assertFalse(result["is_bot"])
self.assertFalse(result["is_admin"])
self.assertFalse(result["is_owner"])
self.assertFalse(result["is_guest"])
self.assertEqual(result["role"], UserProfile.ROLE_MODERATOR)
# Tests the GET ../users/{id} API endpoint.
user = self.example_user("hamlet")