Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
events: Add 'is_moderator' field to the page_params object sent to clients.
sahil839bd78b1ff90b7
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.mdindex 76bb546d9e2..c86b38446b8 100644--- a/templates/zerver/api/changelog.md+++ b/templates/zerver/api/changelog.md@@ -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 forchanging a user's organization-level role to moderator.* API endpoints that return `role` values can now return `300`, thediff --git a/version.py b/version.pyindex 5589ccbe2e4..ee9f9816f92 100644--- a/version.py+++ b/version.py@@ -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. Bumpdiff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 6607606a0e9..dc674582e46 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -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_adminstate["is_owner"] = settings_user.is_realm_owner+ state["is_moderator"] = settings_user.is_moderatorstate["is_guest"] = settings_user.is_gueststate["user_id"] = settings_user.idstate["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_MODERATORstate["is_guest"] = person["role"] == UserProfile.ROLE_GUEST# Recompute properties based on is_admin/is_gueststate["can_create_streams"] = user_profile.can_create_streams()diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex f9d622029a1..e594b33bd57 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -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: booleandescription: |diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex e33daf5e676..6b8e4c6cc4b 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -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()diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex d5b16d09baf..1bea988b923 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -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",