mirror of https://github.com/zulip/zulip.git
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:
parent
8711ab7676
commit
34f134d58d
|
@ -489,6 +489,7 @@ exports.fixtures = {
|
||||||
is_admin: false,
|
is_admin: false,
|
||||||
is_active: true,
|
is_active: true,
|
||||||
is_owner: false,
|
is_owner: false,
|
||||||
|
role: 400,
|
||||||
is_bot: false,
|
is_bot: false,
|
||||||
is_guest: false,
|
is_guest: false,
|
||||||
profile_data: {},
|
profile_data: {},
|
||||||
|
|
|
@ -12,6 +12,14 @@ below features are supported.
|
||||||
|
|
||||||
**Feature level 59**
|
**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
|
* [`GET /events`](/api/get-events): Added new `zulip_version` and
|
||||||
`zulip_feature_level` fields to the `restart` event.
|
`zulip_feature_level` fields to the `restart` event.
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,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 = 58
|
API_FEATURE_LEVEL = 59
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -1013,6 +1013,7 @@ realm_user_type = DictType(
|
||||||
("is_owner", bool),
|
("is_owner", bool),
|
||||||
("is_bot", bool),
|
("is_bot", bool),
|
||||||
("is_guest", bool),
|
("is_guest", bool),
|
||||||
|
("role", EnumType(UserProfile.ROLE_TYPES)),
|
||||||
("is_active", bool),
|
("is_active", bool),
|
||||||
("profile_data", StringDictType(dict)),
|
("profile_data", StringDictType(dict)),
|
||||||
("timezone", str),
|
("timezone", str),
|
||||||
|
|
|
@ -374,6 +374,7 @@ def format_user_row(
|
||||||
is_admin=is_admin,
|
is_admin=is_admin,
|
||||||
is_owner=is_owner,
|
is_owner=is_owner,
|
||||||
is_guest=is_guest,
|
is_guest=is_guest,
|
||||||
|
role=row["role"],
|
||||||
is_bot=is_bot,
|
is_bot=is_bot,
|
||||||
full_name=row["full_name"],
|
full_name=row["full_name"],
|
||||||
timezone=canonicalize_timezone(row["timezone"]),
|
timezone=canonicalize_timezone(row["timezone"]),
|
||||||
|
|
|
@ -814,6 +814,7 @@ paths:
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
"is_guest": false,
|
"is_guest": false,
|
||||||
|
"role": 400,
|
||||||
"is_bot": false,
|
"is_bot": false,
|
||||||
"full_name": "full name",
|
"full_name": "full name",
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
|
@ -5036,6 +5037,7 @@ paths:
|
||||||
"email": "AARON@zulip.com",
|
"email": "AARON@zulip.com",
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 400,
|
||||||
"avatar_url": "https://secure.gravatar.com/avatar/818c212b9f8830dfef491b3f7da99a14?d=identicon&version=1",
|
"avatar_url": "https://secure.gravatar.com/avatar/818c212b9f8830dfef491b3f7da99a14?d=identicon&version=1",
|
||||||
"bot_type": null,
|
"bot_type": null,
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
|
@ -5079,6 +5081,7 @@ paths:
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 400,
|
||||||
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
||||||
"is_active": true,
|
"is_active": true,
|
||||||
"email": "hamlet@zulip.com",
|
"email": "hamlet@zulip.com",
|
||||||
|
@ -5093,6 +5096,7 @@ paths:
|
||||||
"avatar_url": "https://secure.gravatar.com/avatar/7328586831cdbb1627649bd857b1ee8c?d=identicon&version=1",
|
"avatar_url": "https://secure.gravatar.com/avatar/7328586831cdbb1627649bd857b1ee8c?d=identicon&version=1",
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 400,
|
||||||
"user_id": 23,
|
"user_id": 23,
|
||||||
"bot_type": 1,
|
"bot_type": 1,
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
|
@ -5337,6 +5341,25 @@ paths:
|
||||||
|
|
||||||
**Changes**: New in Zulip 3.0 (feature level 8).
|
**Changes**: New in Zulip 3.0 (feature level 8).
|
||||||
example: false
|
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:
|
is_guest:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: |
|
description: |
|
||||||
|
@ -5405,6 +5428,7 @@ paths:
|
||||||
"full_name": "Iago",
|
"full_name": "Iago",
|
||||||
"is_admin": true,
|
"is_admin": true,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 200,
|
||||||
"is_guest": false,
|
"is_guest": false,
|
||||||
"is_bot": false,
|
"is_bot": false,
|
||||||
"is_active": true,
|
"is_active": true,
|
||||||
|
@ -6612,6 +6636,7 @@ paths:
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 400,
|
||||||
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
||||||
"is_active": true,
|
"is_active": true,
|
||||||
"email": "hamlet@zulip.com",
|
"email": "hamlet@zulip.com",
|
||||||
|
@ -6686,6 +6711,7 @@ paths:
|
||||||
"timezone": "",
|
"timezone": "",
|
||||||
"is_admin": false,
|
"is_admin": false,
|
||||||
"is_owner": false,
|
"is_owner": false,
|
||||||
|
"role": 400,
|
||||||
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
"avatar_url": "https://secure.gravatar.com/avatar/6d8cad0fd00256e7b40691d27ddfd466?d=identicon&version=1",
|
||||||
"is_active": true,
|
"is_active": true,
|
||||||
"email": "hamlet@zulip.com",
|
"email": "hamlet@zulip.com",
|
||||||
|
@ -8969,6 +8995,7 @@ paths:
|
||||||
full_name: {}
|
full_name: {}
|
||||||
is_admin: {}
|
is_admin: {}
|
||||||
is_owner: {}
|
is_owner: {}
|
||||||
|
role: {}
|
||||||
bot_type: {}
|
bot_type: {}
|
||||||
user_id: {}
|
user_id: {}
|
||||||
bot_owner_id: {}
|
bot_owner_id: {}
|
||||||
|
@ -11635,6 +11662,7 @@ components:
|
||||||
full_name: {}
|
full_name: {}
|
||||||
is_admin: {}
|
is_admin: {}
|
||||||
is_owner: {}
|
is_owner: {}
|
||||||
|
role: {}
|
||||||
bot_type: {}
|
bot_type: {}
|
||||||
user_id: {}
|
user_id: {}
|
||||||
bot_owner_id: {}
|
bot_owner_id: {}
|
||||||
|
@ -11692,6 +11720,25 @@ components:
|
||||||
If true, is_admin will also be true.
|
If true, is_admin will also be true.
|
||||||
|
|
||||||
**Changes**: New in Zulip 3.0 (feature level 8).
|
**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:
|
bot_type:
|
||||||
type: integer
|
type: integer
|
||||||
nullable: true
|
nullable: true
|
||||||
|
|
|
@ -782,6 +782,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
|
||||||
"is_guest",
|
"is_guest",
|
||||||
"is_bot",
|
"is_bot",
|
||||||
"is_owner",
|
"is_owner",
|
||||||
|
"role",
|
||||||
"full_name",
|
"full_name",
|
||||||
"timezone",
|
"timezone",
|
||||||
"is_active",
|
"is_active",
|
||||||
|
@ -801,6 +802,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
|
||||||
"is_guest",
|
"is_guest",
|
||||||
"is_bot",
|
"is_bot",
|
||||||
"is_owner",
|
"is_owner",
|
||||||
|
"role",
|
||||||
"full_name",
|
"full_name",
|
||||||
"timezone",
|
"timezone",
|
||||||
"is_active",
|
"is_active",
|
||||||
|
@ -832,6 +834,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
|
||||||
"is_bot",
|
"is_bot",
|
||||||
"is_admin",
|
"is_admin",
|
||||||
"is_owner",
|
"is_owner",
|
||||||
|
"role",
|
||||||
"profile_data",
|
"profile_data",
|
||||||
"avatar_version",
|
"avatar_version",
|
||||||
"timezone",
|
"timezone",
|
||||||
|
|
|
@ -631,6 +631,7 @@ class HomeTest(ZulipTestCase):
|
||||||
is_bot=True,
|
is_bot=True,
|
||||||
is_admin=False,
|
is_admin=False,
|
||||||
is_owner=False,
|
is_owner=False,
|
||||||
|
role=email_gateway_bot.role,
|
||||||
is_cross_realm_bot=True,
|
is_cross_realm_bot=True,
|
||||||
is_guest=False,
|
is_guest=False,
|
||||||
),
|
),
|
||||||
|
@ -645,6 +646,7 @@ class HomeTest(ZulipTestCase):
|
||||||
is_bot=True,
|
is_bot=True,
|
||||||
is_admin=False,
|
is_admin=False,
|
||||||
is_owner=False,
|
is_owner=False,
|
||||||
|
role=notification_bot.role,
|
||||||
is_cross_realm_bot=True,
|
is_cross_realm_bot=True,
|
||||||
is_guest=False,
|
is_guest=False,
|
||||||
),
|
),
|
||||||
|
@ -659,6 +661,7 @@ class HomeTest(ZulipTestCase):
|
||||||
is_bot=True,
|
is_bot=True,
|
||||||
is_admin=False,
|
is_admin=False,
|
||||||
is_owner=False,
|
is_owner=False,
|
||||||
|
role=welcome_bot.role,
|
||||||
is_cross_realm_bot=True,
|
is_cross_realm_bot=True,
|
||||||
is_guest=False,
|
is_guest=False,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1709,7 +1709,7 @@ class GetProfileTest(ZulipTestCase):
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
iago = self.example_user("iago")
|
iago = self.example_user("iago")
|
||||||
desdemona = self.example_user("desdemona")
|
desdemona = self.example_user("desdemona")
|
||||||
|
shiva = self.example_user("shiva")
|
||||||
self.login("hamlet")
|
self.login("hamlet")
|
||||||
result = orjson.loads(self.client_get("/json/users/me").content)
|
result = orjson.loads(self.client_get("/json/users/me").content)
|
||||||
self.assertEqual(result["email"], hamlet.email)
|
self.assertEqual(result["email"], hamlet.email)
|
||||||
|
@ -1719,6 +1719,7 @@ class GetProfileTest(ZulipTestCase):
|
||||||
self.assertFalse(result["is_admin"])
|
self.assertFalse(result["is_admin"])
|
||||||
self.assertFalse(result["is_owner"])
|
self.assertFalse(result["is_owner"])
|
||||||
self.assertFalse(result["is_guest"])
|
self.assertFalse(result["is_guest"])
|
||||||
|
self.assertEqual(result["role"], UserProfile.ROLE_MEMBER)
|
||||||
self.assertFalse("delivery_email" in result)
|
self.assertFalse("delivery_email" in result)
|
||||||
self.login("iago")
|
self.login("iago")
|
||||||
result = orjson.loads(self.client_get("/json/users/me").content)
|
result = orjson.loads(self.client_get("/json/users/me").content)
|
||||||
|
@ -1728,6 +1729,7 @@ class GetProfileTest(ZulipTestCase):
|
||||||
self.assertTrue(result["is_admin"])
|
self.assertTrue(result["is_admin"])
|
||||||
self.assertFalse(result["is_owner"])
|
self.assertFalse(result["is_owner"])
|
||||||
self.assertFalse(result["is_guest"])
|
self.assertFalse(result["is_guest"])
|
||||||
|
self.assertEqual(result["role"], UserProfile.ROLE_REALM_ADMINISTRATOR)
|
||||||
self.login("desdemona")
|
self.login("desdemona")
|
||||||
result = orjson.loads(self.client_get("/json/users/me").content)
|
result = orjson.loads(self.client_get("/json/users/me").content)
|
||||||
self.assertEqual(result["email"], desdemona.email)
|
self.assertEqual(result["email"], desdemona.email)
|
||||||
|
@ -1735,6 +1737,15 @@ class GetProfileTest(ZulipTestCase):
|
||||||
self.assertTrue(result["is_admin"])
|
self.assertTrue(result["is_admin"])
|
||||||
self.assertTrue(result["is_owner"])
|
self.assertTrue(result["is_owner"])
|
||||||
self.assertFalse(result["is_guest"])
|
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.
|
# Tests the GET ../users/{id} API endpoint.
|
||||||
user = self.example_user("hamlet")
|
user = self.example_user("hamlet")
|
||||||
|
|
Loading…
Reference in New Issue