Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

events: Pass can_invite_others_to_realm to client using page_params.

sahil83986f7b6af6060
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index bea7f28c1df..a6e4258a1e4 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -10,6 +10,11 @@ below features are supported.
## Changes in Zulip 4.0
+**Feature level 51**
+
+* [`POST /register`](/api/register-queue): Added a new boolean field
+`can_invite_others_to_realm`.
+
**Feature level 50**
* [`POST /register`](/api/register-queue): Replaced `invite_by_admins_only`
diff --git a/version.py b/version.py
index e25cb10126c..5993716d368 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 = 50
+API_FEATURE_LEVEL = 51
# 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
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 30ab172ee42..e87eba74e6a 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -315,6 +315,7 @@ def fetch_initial_state_data(
state["can_create_streams"] = settings_user.can_create_streams()
state["can_subscribe_other_users"] = settings_user.can_subscribe_other_users()
+ 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_guest"] = settings_user.is_guest
@@ -593,6 +594,7 @@ def apply_event(
# Recompute properties based on is_admin/is_guest
state["can_create_streams"] = user_profile.can_create_streams()
state["can_subscribe_other_users"] = user_profile.can_subscribe_other_users()
+ state["can_invite_others_to_realm"] = user_profile.can_invite_others_to_realm()
# TODO: Probably rather than writing the perfect
# live-update code for the case of racing with the
@@ -751,6 +753,7 @@ def apply_event(
policy_permission_dict = {
"create_stream_policy": "can_create_streams",
"invite_to_stream_policy": "can_subscribe_other_users",
+ "invite_to_realm_policy": "can_invite_others_to_realm",
}
# Tricky interaction: Whether we can create streams and can subscribe other users
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index b5f8eaba106..a3cdfa34935 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -8366,6 +8366,15 @@ paths:
Whether the current user is allowed to subscribe other users to streams with
the organization's [streams policy](/help/configure-who-can-invite-to-streams).
+ can_invite_others_to_realm:
+ type: boolean
+ description: |
+ Present if `realm_user` is present in `fetch_event_types`.
+
+ Whether the current user [is allowed to invite others]
+ (/help/invite-new-users#change-who-can-send-invitations) to the organization.
+
+ **Changes**: New in Zulip 4.0 (feature level 51).
is_admin:
type: boolean
description: |
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index d4f0e8139d4..5d7522da2a5 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -50,6 +50,7 @@ class HomeTest(ZulipTestCase):
"avatar_url_medium",
"bot_types",
"can_create_streams",
+ "can_invite_others_to_realm",
"can_subscribe_other_users",
"color_scheme",
"cross_realm_bots",