users: Add support for changing user role to moderator in api.

This commit adds backend support for changing a user role to
moderator and also to change role from moderator to any other
role.
This commit is contained in:
sahil839 2021-04-19 22:11:20 +05:30 committed by Tim Abbott
parent 34f134d58d
commit dc771f3a14
4 changed files with 43 additions and 1 deletions

View File

@ -10,6 +10,13 @@ below features are supported.
## Changes in Zulip 4.0
**Feature level 60**
* [`PATCH /users/{user_id}`](/api/update-user): Added support for
changing a user's organization-level role to moderator.
* API endpoints that return `role` values can now return `300`, the
encoding of the moderator role.
**Feature level 59**
* [`GET /users`](/api/get-users), [`GET /users/{user_id}`](/api/get-user),

View File

@ -1186,6 +1186,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
ROLE_TYPES = [
ROLE_REALM_OWNER,
ROLE_REALM_ADMINISTRATOR,
ROLE_MODERATOR,
ROLE_MEMBER,
ROLE_GUEST,
]

View File

@ -390,6 +390,7 @@ paths:
enum:
- 100
- 200
- 300
- 400
- 600
- type: object
@ -6750,6 +6751,7 @@ paths:
* Organization owner: 100
* Organization administrator: 200
* Organization moderator: 300
* Member: 400
* Guest: 600
@ -6758,7 +6760,8 @@ paths:
The owner role cannot be removed from the only organization owner.
**Changes**: New in Zulip 3.0 (feature level 8), replacing the previous
pair of `is_admin` and `is_guest` boolean parameters.
pair of `is_admin` and `is_guest` boolean parameters. Organization moderator
role added in Zulip 4.0 (feature level 60).
schema:
type: integer
example: 400

View File

@ -447,17 +447,27 @@ class PermissionTest(ZulipTestCase):
user_profile.is_realm_admin
and not user_profile.is_guest
and not user_profile.is_realm_owner
and not user_profile.is_moderator
)
elif role == UserProfile.ROLE_REALM_OWNER:
return (
user_profile.is_realm_owner
and user_profile.is_realm_admin
and not user_profile.is_moderator
and not user_profile.is_guest
)
elif role == UserProfile.ROLE_MODERATOR:
return (
user_profile.is_moderator
and not user_profile.is_realm_owner
and not user_profile.is_realm_admin
and not user_profile.is_guest
)
if role == UserProfile.ROLE_MEMBER:
return (
not user_profile.is_guest
and not user_profile.is_moderator
and not user_profile.is_realm_admin
and not user_profile.is_realm_owner
)
@ -465,6 +475,7 @@ class PermissionTest(ZulipTestCase):
assert role == UserProfile.ROLE_GUEST
return (
user_profile.is_guest
and not user_profile.is_moderator
and not user_profile.is_realm_admin
and not user_profile.is_realm_owner
)
@ -524,6 +535,26 @@ class PermissionTest(ZulipTestCase):
do_change_user_role(iago, UserProfile.ROLE_REALM_OWNER, acting_user=None)
self.check_user_role_change("iago", UserProfile.ROLE_REALM_ADMINISTRATOR)
def test_change_owner_to_moderator(self) -> None:
iago = self.example_user("iago")
do_change_user_role(iago, UserProfile.ROLE_REALM_OWNER, acting_user=None)
self.check_user_role_change("iago", UserProfile.ROLE_MODERATOR)
def test_change_moderator_to_owner(self) -> None:
self.check_user_role_change("shiva", UserProfile.ROLE_REALM_OWNER)
def test_change_admin_to_moderator(self) -> None:
self.check_user_role_change("iago", UserProfile.ROLE_MODERATOR)
def test_change_moderator_to_admin(self) -> None:
self.check_user_role_change("shiva", UserProfile.ROLE_REALM_ADMINISTRATOR)
def test_change_guest_to_moderator(self) -> None:
self.check_user_role_change("polonius", UserProfile.ROLE_MODERATOR)
def test_change_moderator_to_guest(self) -> None:
self.check_user_role_change("shiva", UserProfile.ROLE_GUEST)
def test_admin_user_can_change_profile_data(self) -> None:
realm = get_realm("zulip")
self.login("iago")