From 86f7b6af60601b5ae47920f9dd4d8b59830326cb Mon Sep 17 00:00:00 2001 From: sahil839 Date: Sun, 4 Apr 2021 00:39:26 +0530 Subject: [PATCH] events: Pass can_invite_others_to_realm to client using page_params. This commit adds backend code for passing can_invite_others_to_realm field to clients using the fetch_initial_state_data in the page_params object. Though this field is not used by webapp as of now, but will be used to fix a bug of incorreclty showing the invite users option in settings overlay in the next commit. --- templates/zerver/api/changelog.md | 5 +++++ version.py | 2 +- zerver/lib/events.py | 3 +++ zerver/openapi/zulip.yaml | 9 +++++++++ zerver/tests/test_home.py | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index bea7f28c1d..a6e4258a1e 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 e25cb10126..5993716d36 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 30ab172ee4..e87eba74e6 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 b5f8eaba10..a3cdfa3493 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 d4f0e8139d..5d7522da2a 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",