Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
invite: Any combination of default streams should be subscribe-able.
Shubham Padiaa76042ce395b
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex c5fe6affc6c..7b4d05bd584 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -32,6 +32,9 @@ format used by the Zulip server that they are interacting with.`can_add_subscribers_group` parameter to support setting andchanging the user group whose members can add other subscribersto the specified stream.+* [`POST /invites`](/api/send-invites), [`POST+ /invites/multiuse`](/api/create-invite-link): Users can now always+ include default channels in an invite's initial subscriptions.**Feature level 341**diff --git a/help/set-default-channels-for-new-users.md b/help/set-default-channels-for-new-users.mdindex f5c2ad1c1c8..1bda1164c2f 100644--- a/help/set-default-channels-for-new-users.md+++ b/help/set-default-channels-for-new-users.md@@ -28,6 +28,14 @@ that default set.{end_tabs}+!!! tip ""++ A user with permission to invite other users will be able to subscribe those+ users to these default channel at the time of invitation irrespective of+ whether they have individual permission to subscribe other users to that channel.+ This will only apply at the time of invitation and not once the invited user has+ become a member.+## Related articles* [User roles](/help/user-roles)diff --git a/web/src/invite.ts b/web/src/invite.tsindex bd506154df5..d41d2bfce43 100644--- a/web/src/invite.ts+++ b/web/src/invite.ts@@ -82,10 +82,7 @@ function get_common_invitation_data(): {let stream_ids: number[] = [];let include_realm_default_subscriptions = false;- if (- $("#invite_select_default_streams").prop("checked") ||- !settings_data.can_subscribe_others_to_all_streams()- ) {+ if ($("#invite_select_default_streams").prop("checked")) {include_realm_default_subscriptions = true;} else {stream_ids = stream_pill.get_stream_ids(stream_pill_widget);@@ -389,7 +386,6 @@ function open_invite_user_modal(e: JQuery.ClickEvent<Document, undefined>): voidtime_choices: settings_config.custom_time_unit_values,show_select_default_streams_option: stream_data.get_default_stream_ids().length > 0,user_has_email_set: !settings_data.user_email_not_configured(),- can_subscribe_other_users: settings_data.can_subscribe_others_to_all_streams(),});function invite_user_modal_post_render(): void {@@ -414,11 +410,9 @@ function open_invite_user_modal(e: JQuery.ClickEvent<Document, undefined>): voidconst valid_to_text = valid_to();settings_components.set_time_input_formatted_text($expires_in, valid_to_text);- if (settings_data.can_subscribe_others_to_all_streams()) {- set_streams_to_join_list_visibility();- const $stream_pill_container = $("#invite_streams_container .pill-container");- stream_pill_widget = invite_stream_picker_pill.create($stream_pill_container);- }+ set_streams_to_join_list_visibility();+ const $stream_pill_container = $("#invite_streams_container .pill-container");+ stream_pill_widget = invite_stream_picker_pill.create($stream_pill_container);if (show_group_pill_container) {const $user_group_pill_container = $("#invite-user-group-container .pill-container");diff --git a/web/templates/invite_user_modal.hbs b/web/templates/invite_user_modal.hbsindex c7d0c656b68..e4eec69d9b5 100644--- a/web/templates/invite_user_modal.hbs+++ b/web/templates/invite_user_modal.hbs@@ -10,12 +10,6 @@{{#*inline "z-link"}}<a href="/help/demo-organizations#configure-email-for-demo-organization-owner" target="_blank" rel="noopener noreferrer">{{> @partial-block }}</a>{{/inline}}{{/tr}}</div>- {{else if (not can_subscribe_other_users)}}- <div class="invite-stream-notice">- {{#tr}}The users you invite will be automatically added to <z-link>default channels</z-link> for this organization, as you do not have permission to configure which channels new users join.- {{#*inline "z-link"}}<a target="_blank" rel="noopener noreferrer" href="#organization/default-channels-list">{{> @partial-block}}</a>{{/inline}}- {{/tr}}- </div>{{/if}}<div class="input-group"><div id="invite_users_option_tabs_container"></div>@@ -68,7 +62,6 @@{{/if}}</select></div>- {{#if can_subscribe_other_users}}<div class="input-group"><label>{{t "Channels they should join" }}</label><div id="streams_to_add">@@ -93,7 +86,6 @@</div><div id="guest_visible_users_container" class="input-group" style="display: none;"></div>- {{/if}}{{#if show_group_pill_container}}<div class="input-group"><label class="modal-field-label">{{t "User groups they should join" }} {{> help_link_widget link="/help/user-groups"}}</label>diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 82b5daacb0e..821386d903e 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -780,7 +780,10 @@ def can_remove_subscribers_from_stream(def get_streams_to_which_user_cannot_add_subscribers(- streams: list[Stream], user_profile: UserProfile+ streams: list[Stream],+ user_profile: UserProfile,+ *,+ allow_default_streams: bool = False,) -> list[Stream]:# IMPORTANT: This function expects its callers to have already# checked that the user can access the provided channels, and thus@@ -800,7 +803,17 @@ def get_streams_to_which_user_cannot_add_subscribers(user_recursive_group_ids = set(get_recursive_membership_groups(user_profile).values_list("id", flat=True))+ if allow_default_streams:+ default_stream_ids = get_default_stream_ids_for_realm(user_profile.realm_id)+for stream in streams:+ # We only allow this exception for the invite code path and not+ # for other code paths, since a user should be able to add the+ # invited users to default channels regardless of their permission+ # for that individual channel.+ if allow_default_streams and stream.id in default_stream_ids:+ continue+group_allowed_to_administer_channel_id = stream.can_administer_channel_group_idassert group_allowed_to_administer_channel_id is not Noneif group_allowed_to_administer_channel_id in user_recursive_group_ids:diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 8e2204d26bc..e2e97903c27 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -13627,12 +13627,20 @@ paths:be subscribed to based on the `include_realm_default_subscriptions`parameter.+ Requested channels must either be default channels for the+ organization, or ones the acting user has permission to add+ subscribers to.+This list must be empty if the current user has the unlikelyconfiguration of being able to send invitations while lackingpermission to [subscribe other users to channels][can-subscribe-others].- **Changes**: Before Zulip 7.0 (feature level 180), specifying `stream_ids`- as an empty list resulted in an error.+ **Changes**: Prior to Zulip 10.0 (feature level 342), default channels+ that the acting user did not directly have permission to add+ subscribers to would be rejected.++ Before Zulip 7.0 (feature level 180), specifying `stream_ids` as an+ empty list resulted in an error.[can-subscribe-others]: /help/configure-who-can-invite-to-channelstype: array@@ -13821,11 +13829,19 @@ paths:be subscribed to based on the `include_realm_default_subscriptions`parameter.+ Requested channels must either be default channels for the+ organization, or ones the acting user has permission to add+ subscribers to.+This list must be empty if the current user has the unlikelyconfiguration of being able to create reusable invitation links whilelacking permission to [subscribe other users tochannels][can-subscribe-others].+ **Changes**: Prior to Zulip 10.0 (feature level 342), default channels+ that the acting user did not directly have permission to add+ subscribers to would be rejected.+[can-subscribe-others]: /help/configure-who-can-invite-to-channelstype: arrayitems:diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.pyindex 28937035617..663bfedf022 100644--- a/zerver/tests/test_invite.py+++ b/zerver/tests/test_invite.py@@ -54,7 +54,7 @@ from zerver.lib.send_email import FromAddress, deliver_scheduled_emails, send_fufrom zerver.lib.streams import ensure_streamfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import find_key_by_email-from zerver.lib.user_groups import get_direct_user_groups+from zerver.lib.user_groups import get_direct_user_groups, is_user_in_groupfrom zerver.models import (DefaultStream,Message,@@ -956,7 +956,8 @@ class InviteUserTest(InviteUserBase):def test_successful_invite_users_with_specified_streams(self) -> None:invitee = self.nonreg_email("alice")realm = get_realm("zulip")- self.login("hamlet")+ current_user = self.example_user("hamlet")+ self.login_user(current_user)stream_names = ["Rome", "Scotland", "Venice"]streams = {get_stream(stream_name, realm) for stream_name in stream_names}@@ -1007,6 +1008,59 @@ class InviteUserTest(InviteUserBase):self.submit_reg_form_for_user(invitee, "password")self.check_user_subscribed_only_to_streams("test1", {denmark, sandbox, verona, zulip})+ admins_group = NamedUserGroup.objects.get(+ name=SystemGroups.ADMINISTRATORS, realm=realm, is_system_group=True+ )+ nobody_group = NamedUserGroup.objects.get(+ name=SystemGroups.NOBODY, realm=realm, is_system_group=True+ )+ members_group = NamedUserGroup.objects.get(+ name=SystemGroups.MEMBERS, realm=realm, is_system_group=True+ )++ do_change_stream_group_based_setting(+ denmark, "can_add_subscribers_group", admins_group, acting_user=None+ )+ do_change_realm_permission_group_setting(+ realm, "can_add_subscribers_group", nobody_group, acting_user=None+ )+ # This is not a default stream, so we are making sure that the+ # user has the permission to add subscribers to this channel.+ do_change_stream_group_based_setting(+ verona, "can_add_subscribers_group", members_group, acting_user=None+ )+ invitee = self.nonreg_email("newguy")+ self.assertEqual(is_user_in_group(admins_group, current_user), False)+ self.assert_json_success(+ self.invite(+ invitee,+ [denmark.name, sandbox.name, verona.name],+ include_realm_default_subscriptions=False,+ )+ )+ self.assertTrue(find_key_by_email(invitee))+ # Check that the user is subscribed to default streams+ # regardless of whether they have permission to add subscribers+ # to them when inviting them.+ self.submit_reg_form_for_user(invitee, "password")+ self.check_user_subscribed_only_to_streams("newguy", {denmark, sandbox, verona})++ invitee = self.nonreg_email("newuser")+ self.assertEqual(get_slim_realm_default_streams(realm.id), {denmark, sandbox, zulip})+ self.assert_json_success(+ self.invite(+ invitee, [sandbox.name, verona.name], include_realm_default_subscriptions=False+ )+ )+ self.assertTrue(find_key_by_email(invitee))+ # Sandbox is no longer a default stream, but since it was a+ # default stream when creating the invite, invitee should be+ # subscribed to that stream+ do_remove_default_stream(sandbox)+ self.assertEqual(get_slim_realm_default_streams(realm.id), {denmark, zulip})+ self.submit_reg_form_for_user(invitee, "password")+ self.check_user_subscribed_only_to_streams("newuser", {sandbox, verona})+def test_successful_invite_users_with_specified_user_groups(self) -> None:invitee = self.nonreg_email("bob")iago = self.example_user("iago")diff --git a/zerver/views/invite.py b/zerver/views/invite.pyindex 60973347a02..00a1dc23491 100644--- a/zerver/views/invite.py+++ b/zerver/views/invite.py@@ -94,7 +94,7 @@ def access_streams_for_invite(stream_ids: list[int], user_profile: UserProfile)streams.append(stream)streams_to_which_user_cannot_add_subscribers = get_streams_to_which_user_cannot_add_subscribers(- streams, user_profile+ streams, user_profile, allow_default_streams=True)if len(streams_to_which_user_cannot_add_subscribers) > 0:raise JsonableError(_("You do not have permission to subscribe other users to channels."))