events: Add 'is_moderator' field to the page_params object sent to clients.

This commit is contained in:
sahil839 2021-04-20 00:26:15 +05:30 committed by Tim Abbott
parent dc771f3a14
commit bd78b1ff90
6 changed files with 31 additions and 1 deletions

View File

@ -12,6 +12,9 @@ below features are supported.
**Feature level 60**
* [`POST /register`](/api/register-queue): Added a new boolean field
`is_moderator`, similar to the existing `is_admin`, `is_owner` and
`is_guest` fields, to the response.
* [`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

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 = 59
API_FEATURE_LEVEL = 60
# 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

@ -337,6 +337,7 @@ def fetch_initial_state_data(
state["can_invite_others_to_realm"] = settings_user.can_invite_others_to_realm()
state["is_admin"] = settings_user.is_realm_admin
state["is_owner"] = settings_user.is_realm_owner
state["is_moderator"] = settings_user.is_moderator
state["is_guest"] = settings_user.is_guest
state["user_id"] = settings_user.id
state["enter_sends"] = settings_user.enter_sends
@ -609,6 +610,7 @@ def apply_event(
if "role" in person:
state["is_admin"] = is_administrator_role(person["role"])
state["is_owner"] = person["role"] == UserProfile.ROLE_REALM_OWNER
state["is_moderator"] = person["role"] == UserProfile.ROLE_MODERATOR
state["is_guest"] = person["role"] == UserProfile.ROLE_GUEST
# Recompute properties based on is_admin/is_guest
state["can_create_streams"] = user_profile.can_create_streams()

View File

@ -8935,6 +8935,14 @@ paths:
Present if `realm_user` is present in `fetch_event_types`.
Whether the current user is an [organization owner](/help/roles-and-permissions).
is_moderator:
type: boolean
description: |
Present if `realm_user` is present in `fetch_event_types`.
Whether the current user is an [organization moderator](/help/roles-and-permissions).
**Changes**: New in Zulip 4.0 (feature level 60).
is_guest:
type: boolean
description: |

View File

@ -1303,6 +1303,22 @@ class NormalActionsTest(BaseAction):
check_realm_user_update("events[0]", events[0], "role")
self.assertEqual(events[0]["person"]["role"], role)
def test_change_is_moderator(self) -> None:
reset_emails_in_zulip_realm()
# Important: We need to refresh from the database here so that
# we don't have a stale UserProfile object with an old value
# for email being passed into this next function.
self.user_profile.refresh_from_db()
do_change_user_role(self.user_profile, UserProfile.ROLE_MEMBER, acting_user=None)
for role in [UserProfile.ROLE_MODERATOR, UserProfile.ROLE_MEMBER]:
events = self.verify_action(
lambda: do_change_user_role(self.user_profile, role, acting_user=None)
)
check_realm_user_update("events[0]", events[0], "role")
self.assertEqual(events[0]["person"]["role"], role)
def test_change_is_guest(self) -> None:
reset_emails_in_zulip_realm()

View File

@ -97,6 +97,7 @@ class HomeTest(ZulipTestCase):
"insecure_desktop_app",
"is_admin",
"is_guest",
"is_moderator",
"is_owner",
"is_web_public_visitor",
"jitsi_server_url",