From 4ca887bade9645b10d504e45933c54f8cbf6dd03 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 26 Apr 2023 22:50:44 +0530 Subject: [PATCH] invites: Allow users to invite without specifying any stream to join. We now allow users to invite without specifying any stream to join. In such cases, the user would join the default streams, if any, during the process of account creation after accepting the invite. It is also fine if there are no default streams and user isn't subscribed to any stream initially. --- api_docs/changelog.md | 6 ++++++ version.py | 2 +- web/src/invite.js | 9 ++------- zerver/tests/test_invite.py | 17 ++++++++++++----- zerver/views/invite.py | 2 -- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/api_docs/changelog.md b/api_docs/changelog.md index a0bc811446..0383f6a867 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 7.0 +**Feature level 180** + +* `POST /invites`: Added support for invitations specifying the empty + list as the user's initial stream subscriptions. Previously, this + returned an error. + **Feature level 179**: * [`POST /scheduled_messages`](/api/create-or-update-scheduled-message): diff --git a/version.py b/version.py index e3d2ab20c2..0c65315773 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 179 +API_FEATURE_LEVEL = 180 # 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/web/src/invite.js b/web/src/invite.js index daacc938a7..68a4412c23 100644 --- a/web/src/invite.js +++ b/web/src/invite.js @@ -260,9 +260,8 @@ function open_invite_user_modal(e) { function toggle_invite_submit_button() { $("#invite-user-modal .dialog_submit_button").prop( "disabled", - ($("#invitee_emails").val().trim() === "" && - !$("#generate_multiuse_invite_radio").is(":checked")) || - $("#streams_to_add input:checked").length === 0, + $("#invitee_emails").val().trim() === "" && + !$("#generate_multiuse_invite_radio").is(":checked"), ); } @@ -326,10 +325,6 @@ function open_invite_user_modal(e) { $("#invite_uncheck_all_button").on("click", () => { $("#streams_to_add input[type=checkbox]").prop("checked", false); - $("#invite-user-modal .dialog_submit_button").prop( - "disabled", - !$("#generate_multiuse_invite_radio").is(":checked"), - ); }); } diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.py index 91e73f9622..170141eb1e 100644 --- a/zerver/tests/test_invite.py +++ b/zerver/tests/test_invite.py @@ -704,6 +704,18 @@ class InviteUserTest(InviteUserBase): self.submit_reg_form_for_user(invitee, "password") self.check_user_subscribed_only_to_streams("alice", streams) + invitee = self.nonreg_email("bob") + self.assert_json_success(self.invite(invitee, [])) + self.assertTrue(find_key_by_email(invitee)) + + default_streams = get_default_streams_for_realm(realm.id) + self.assert_length(default_streams, 1) + + self.submit_reg_form_for_user(invitee, "password") + # If no streams are provided, user is not subscribed to + # default streams as well. + self.check_user_subscribed_only_to_streams("bob", []) + def test_can_invite_others_to_realm(self) -> None: def validation_func(user_profile: UserProfile) -> bool: user_profile.refresh_from_db() @@ -921,11 +933,6 @@ earl-test@zulip.com""", do_set_realm_property(realm, "emails_restricted_to_domains", True, acting_user=None) self.login("hamlet") - invitee_emails = "foo@zulip.com" - self.assert_json_error( - self.invite(invitee_emails, []), - "You must specify at least one stream for invitees to join.", - ) for address in ("noatsign.com", "outsideyourdomain@example.net"): self.assert_json_error( diff --git a/zerver/views/invite.py b/zerver/views/invite.py index 78cd106567..cb98e5557d 100644 --- a/zerver/views/invite.py +++ b/zerver/views/invite.py @@ -70,8 +70,6 @@ def invite_users_backend( raise JsonableError(_("Must be an organization administrator")) if not invitee_emails_raw: raise JsonableError(_("You must specify at least one email address.")) - if not stream_ids: - raise JsonableError(_("You must specify at least one stream for invitees to join.")) invitee_emails = get_invitee_emails_set(invitee_emails_raw)