Commit Graph

784 Commits

Author SHA1 Message Date
Sahil Batra
764f4aa2e0 groups: Use realm_for_sharding for limiting NamedUserGroup queries.
For get and filter queries of NamedUserGroup, realm_for_sharding
field is used instead of realm field, as directly using
realm_for_sharding field on NamedUserGroup makes the query faster
than using realm present on the base UserGroup table.
2025-09-23 12:15:53 -07:00
Sahil Batra
d4d7a8fe2a streams: Make sure that unused anonymous groups are not created.
Anonymous groups were being created for stream permission
settings when calling the subscriptions endpoint without
any streams data or when calling it only for subscribing
users to streams and not for creating any new streams.

This commit makes sure that no such unused anonymous groups
are created.
2025-09-23 12:15:51 -07:00
Anders Kaseorg
40a022dcc3 zephyr: Remove Zephyr mirroring support.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-16 11:18:18 -07:00
Lauryn Menard
1030f41884 test-subs: Make new channel name consistent in notification bot test.
Updates final check in test_notification_bot_dm_on_subscription to
use the same pattern for the new channel name, and adds a comment
to clarify what that final check is for since it doesn't look at
the Notification Bot DM or channel messages for that case.
2025-09-08 16:52:37 -07:00
Lauryn Menard
14581de0de test-subs: Fix comment in test_notification_bot_dm_on_subscription. 2025-09-08 16:52:37 -07:00
Kislay Verma
9b7d6335c1 test_subs: Add send_new_subscription_messages parameter false test case.
For the sake of completion, we add a test case ensuring that
the response does not contain `new_subscription_messages_sent` if
the parameter `send_new_subscription_messages` is `false`,
as mentioned in the API documentation.
2025-08-27 17:06:31 -07:00
Kislay Verma
18d9b686b7 add_subscriptions: Only exclude DMs and not new channel notifications.
When the number of new subscriptions crosses a threshold, we wish to
avoid sending DMs to the user as implemented in #31206. But there was
a bug causing announcement channel and new channel notification
messages to also not be sent.

This commit fixes that bug by ensuring that we only exclude direct
message notications.
2025-08-27 17:06:31 -07:00
Kislay Verma
06d2ecb482 test_subs: Add test for all notification bot messages.
In #31206, we changed `add_subscriptions_backend` to exclude the
notification bot DMs when subscribing users to a channel when the
number of subscriptions exceeds MAX_BULK_NEW_SUBSCRIPTION_MESSAGES.

This caused a bug where new channel announcement and creation
notification messages were not being sent. Here we add a test that
confirmes the current behavior, which will be corrected in a
subsequent commit.

Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2025-08-27 17:06:31 -07:00
Lauryn Menard
8b1e536e6b create-channel: Rename send_messages_for_new_subscribers helper.
Because send_messages_for_new_subscribers also sends channel
notification messages about newly created channels, a clearer
name for is send_user_subscribed_and_new_channel_notifications.
2025-08-27 11:12:05 -07:00
apoorvapendse
6203861529 zerver: API to create channel.
Fixes #16206.

Co-authored-by: Sahil Batra <sahil@zulip.com>
Co-authored-by: Steve Howell <showell@zulip.com>
Signed-off-by: apoorvapendse <apoorvavpendse@gmail.com>
2025-08-08 19:29:17 -07:00
Vector73
0ac24bd437 api: Add support for passing partial to include_subscribers parameter.
Fixes #35318.
2025-08-04 18:43:14 -07:00
Sahil Batra
eb57fe10a2 streams: Handle empty topic only streams being used for announcements.
This commit updates code to send messages to "general chat" topic
if streams used for announcements for "New user signups",
"New created streams", "Moderation requests" and "Zulip updates"
have topics policy set to allow only "general chat" messages.
2025-07-22 16:59:47 -07:00
Sahil Batra
70d18d7528 tests: Move test for permission to update topics_policy.
This commit updates tests for permission to update topics_policy
of a channel to test_channel_permissions.py.
2025-07-15 15:54:30 -07:00
Vector73
a77fc6aa79 stream_settings: Add new disable_topics option to topics_policy.
Adds new configuration option `disable_topics` in `topics_policy`
channel setting to support disabling topics in the channel.

Fixes #34553.
2025-07-09 14:25:53 -07:00
Evy Kassirer
0c5e1ac492 subscription_data: Flesh out partial suscription data sent to client.
Part of #34244.
2025-06-30 17:10:36 -07:00
Kislay Verma
5f80f0a970 channel: Add option to notify users newly added to a channel.
When a user is added to a channel, we send
the user that was added a Notification Bot
DMs to let them know about it.

In this commit, we add an option for whether or not
this message is sent.

If more than 100 users are added at once, we
do not send notification bot DMs since it would
be a performance-costly operation.

We also send this threshold value of 100 in the
initial state data to the clients.

Fixes part of #31189
2025-06-26 10:08:11 -07:00
Prakhar Pratyush
7970e1fa45 streams: Fix error while sending notice in deactivated stream.
Sending messages to a deactivated stream is not allowed with
the exception of notices sent in "channel events" topic.

Earlier, notice sent to a deactivated stream when it is
deactivated was working correctly but it was resulting in
an error in the following cases:
* Renaming stream
* Changing stream description
* Changing message retention period
* Changing posting permission
* Changing access permission

This commit makes sure to send notice successfully in those cases.
2025-06-19 12:47:54 -07:00
Tim Abbott
f5d0a3ee30 test_subs: Fix incorrect removed import.
Another use got added before the commit removing the import was merged.
2025-06-19 10:55:36 -07:00
Sahil Batra
e06c181a95 tests: Move test to check permission to deactivate streams.
This commit moves test to check permission to deactivate
streams to test_channel_permissions.py.
2025-06-19 10:42:52 -07:00
Sahil Batra
3f8518f9d1 tests: Move channel administering permission tests.
This commit moves tests to check permission for administering
streams as per can_administer_channel_group setting to
test_channel_permissions.py.
2025-06-19 10:42:52 -07:00
Vector73
6094bbe8a5 stream_settings: Add new topics_policy setting.
Added `topics_policy` channel setting to configure sending
messages in the empty topic.

Fixes #33549.
2025-06-17 17:05:58 -07:00
whilstsomebody
053f30aace test_subs: Fix syntax errors in tests.
This commit fixes the use of `/json/...` by replacing
it with the correct `/api/v1/...`. Also removes
unnecessary `login_user` call when using `api_patch`.
2025-06-16 11:51:14 -07:00
whilstsomebody
26e5b916bc test_subs: Fix the incorrect syntax in 'test_unarchive_stream'.
This commit fixes the use of `/json/streams/...` by replacing
it with the correct `/api/v1/streams/...`. Also removes
unnecessary `login_user` call when using `api_patch`.
2025-06-16 09:14:03 -07:00
Sahil Batra
79c2972232 tests: Move test to check permission to update message retention setting.
This commit moves test to check permission to update message retention
setting of a stream to test_channel_permissions.py.
2025-06-11 15:41:50 -07:00
Sahil Batra
0dee5f4c0d tests: Move subscription properties test to new file.
This commit moves subscription properties test to
test_subscription_settings.py.
2025-06-11 15:41:50 -07:00
Sahil Batra
62579b5b24 tests: Move tests to get streams and subscriptions to test_channel_fetch. 2025-06-11 15:41:50 -07:00
Sahil Batra
679a8363cb tests: Move test for updating default stream to test_default_channels.
This commit moves test for add or removing a stream as default using
"/json/streams/{stream_id}" endpoint to test_default_channels.py.
2025-06-11 15:41:50 -07:00
Sahil Batra
5228c2c97c tests: Create new test_default_channels.py file.
This commit moves tests for default streams and default
stream groups to a new file.

This commit also moves test_guest_user_access_to_streams
test to a different class in test_subs.py since it was
present in DefaultStreamTest class before.
2025-06-11 15:41:50 -07:00
Sahil Batra
88b47be938 channel_folders: Pass realm as argument to check_add_channel_folder.
Passing realm explicitly to check_add_channel_folder instead of
using realm field from acting_user seems much cleaner and readable.
2025-05-29 15:39:03 -07:00
Sahil Batra
460c471a29 tests: Move channel access tests to test_channel_access. 2025-05-28 17:02:41 -07:00
Sahil Batra
bf7f567009 tests: Move stream permission tests to test_channel_permissions. 2025-05-28 17:02:41 -07:00
Sahil Batra
4b29d402c6 tests: Move channel creation tests to test_channel_creation. 2025-05-28 17:02:41 -07:00
Sahil Batra
2f34e6d24c streams: Add API support to update folder of a stream.
Fixes part of #31972.
2025-05-20 13:25:06 -07:00
Sahil Batra
ec96fc9659 streams: Allow adding newly created channels to folders.
Fixes part of #31972.
2025-05-20 13:25:06 -07:00
Mohammad Reza Kianifar
a0488715f3 direct_messages: Use DM groups for 1:1 or self DMs if present.
This is a preparatory refactor for migrating the internal structure of
Recipient objects for group DMs to use the DirectMessageGroup type,
not the legacy PERSONAL type. This step has the message-sending code
path check if a DirectMessageGroupe exists and prefer it if available.

It should have no effect in production other than doing a useless
database query for each outgoing DM, since we do not at present ever
create such DirectMessageGroup objects. (It will not add a marginal
database query once the migration is complete, just during this
transition).
2025-05-18 23:58:59 -07:00
whilstsomebody
5c33cc9eab streams: Improve formatting of channel archive/unarchive notifications.
This commit updates the formatting of the channel archive and
unarchive notifications to make the channel name bold and clickable.
The channel name is now displayed as a Markdown link with bold
formatting, ensuring it stands out while remaining a clickable link
to the channel.
2025-05-16 11:39:40 -07:00
whilstsomebody
2780360b00 unarchive: Add support for unarchiving archived channels.
This commit adds support for unarchiving archived channels
by introducing the `is_archived` parameter to the
`PATCH /streams/{stream_id}` API endpoint. Sending a PATCH
request with `is_archived: false` will unarchive the specified
channel.
2025-05-16 11:39:40 -07:00
Sahil Batra
d2ff4bda4c streams: Check creation permission when updating channel privacy.
User who did not have permission to create public channels
could create them by first creating a private or web-public
channel, if they had the permission to create them, and then
changing privacy of that stream to be a public stream.

Similarly user without permission to create private channels
could also create them.

This commit fixes both these bugs.
2025-05-15 15:37:41 -07:00
bedo
c04558fe31 stream: Add subscriber_count field.
Fixes #34246.

Add subscriber_count field to Stream model to track number of
non-deactivated users subscribed to the channel.
2025-05-13 17:36:53 -07:00
Shubham Padia
700da670cf attachments: Allow seeing attachments to users with content access.
Fixes https://chat.zulip.org/#narrow/channel/9-issues/topic/Can't.20view.20images.20in.20private.20channel.2E
2025-04-23 12:43:54 -07:00
Shubham Padia
6baa106460 test_subs: Add check_subscription_exists helper.
Fetching a subscription and then checking if it exists was taking too
much space in a test and making it feel convoluted. We're planning to
check it more in future commits.
2025-04-23 12:43:54 -07:00
Shubham Padia
b8ba174455 users: Return true for admins for is_moderator.
This change is for consistency with how is_admin works.

API design discussion at https://chat.zulip.org/#narrow/channel/378-api-design/topic/Should.20is_moderator.20have.20admins
2025-04-22 11:24:49 -07:00
Ritwik
2429157498 streams: Don't glue translated strings in new channel notification.
We now translate the whole notification message instead of substituting
an already translated policy_name. This avoids scenarios where only part
of the notification message is translated.

Fixes #30212.

Co-authored-by: Tanmay Kumar <tnmdotkr@gmail.com>
2025-04-15 16:28:38 -07:00
Kislay Verma
54be18d430 streams: Change text in notification bot DM.
This commit addresses the second bullet in
zulip#31206 (comment).
2025-04-15 10:35:59 -07:00
bedo
c0a9ca8e9a tests: Pass update_fields to all stream.save().
A prep PR to 34308.

Explicitly pass the fields to be updated,
This increases performance but most importantly
prevents overwriting the db-saved value of
"subscriber_count" field (added in an upcoming PR)
with the in-memory default value of 0,
since "subscriber_count" will only be updted
via the db.

Migrate some tests to use do_ functions instead of
direclty modifying the state.
2025-04-15 10:28:18 -07:00
Sahil Batra
c5b005833c groups: Do not prefetch can_access_all_users_group setting.
This commit updates code to not prefetch can_access_all_users_group
and can_access_all_users_group__named_user_group fields using
select_related. We can just use get_realm_system_groups_name_dict
function to check if setting is set to "Everyone" group when
needed and can avoid unnecessarily fetching groups for every user
query.
2025-04-11 17:37:06 -07:00
Shubham Padia
de7efd23bc streams: Simplify send_peer_subscriber_events logic.
Earlier, we used to check whether the length of altered_user_ids was 1
and then create a dict of that user id and the streams that they were
added/removed to/from, and optimise our event sending that way. But that
was making the code harder to read.
Now, we just keep the key of user_streams as a concanated list of
user_ids and then add streams accordingly to user_streams.
Furthermore we do not check for peer_user_ids before modifying
user_streams anymore, since it is very highly unlikely that it will be
empty and if it is, send_event can handle it just fine.
2025-04-10 15:08:48 -07:00
Shubham Padia
1014de23a8 streams: Send different peer events for web & non-web public streams.
Earlier, we used to send a single event for all web-public and public
streams. But public streams can have guests, which means the peer user
ids for each of them can be different based on which guests are
subscribed to which channel.
In the previous code, we were using the last stream id from another loop
to get subscribers, which was causing a lot of non-deterministic
failures in our test, since that stream id could keep on changing.
Moreover, it doesn't make much sense to use that id here.
This commit still keeps around the optimisation for public channels with
non-guest users. It will send one event for all public channels with
non-guest users, one for web public channels and for the rest of the
channels it will send an event for each channel with a different set of
peer user ids.
2025-04-10 15:08:48 -07:00
Sahil Batra
7c470f0161 streams: Fix events send when archiving and unarchiving streams. 2025-04-08 12:41:09 -07:00
Sahil Batra
179782eaba user_groups: Refactor is_user_in_group and is_any_user_in_group.
This commit updates is_user_in_group and is_any_user_in_group
to accept group ID as parameter instead of UserGroup object.

This is a prep commit for updating code to not prefetch
direct message permissions group.
2025-04-07 15:34:30 -07:00