Commit Graph

140 Commits

Author SHA1 Message Date
Anders Kaseorg
40a022dcc3 zephyr: Remove Zephyr mirroring support.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-16 11:18:18 -07:00
Alex Vandiver
9c92fe8f34 streams: Skip pickling the recipient string in cache. 2025-08-27 09:22:56 -07:00
Vector73
97a43fa6b6 stream_settings: Add can_delete_own_message_group setting.
Adds per-channel `can_delete_own_message_group` setting for
defining who can delete their own message in the channel.
2025-07-17 15:44:52 -07:00
Vector73
c4e641365b stream_settings: Add can_delete_any_message_group setting.
Adds per-channel can_delete_any_message_group setting for
defining who can delete any message in the channel.
2025-07-17 15:44:42 -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
Vector73
7afed92c00 streams: Add function to get topic for channel events notifications.
Refactored the code to add a function `channel_events_topic_name`
to get the topic name for sending notification for channel events.
2025-07-09 14:25:53 -07:00
opmkumar
8786b12f0c streams: Add can_resolve_topics_group setting.
Fixes #19955.
2025-07-08 16:53:43 -07:00
Vector73
b612351e48 stream_setting: Add setting for who can move messages out of channel.
Adds `can_move_messages_out_of_channel_group` channel-level
permission for who can move messages out of the channel.

Fixes #34243.
2025-06-24 16:52:53 -07:00
Vector73
703601a5d5 stream_setting: Add setting for who can move messages within channel.
Adds `can_move_messages_within_channel_group` channel-level
permission for who can move messages within the channel.
2025-06-24 16:52:53 -07:00
Evy Kassirer
4313648ca5 streams: Add subscriber_count to page load data. 2025-06-19 14:25:41 -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
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
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
202bebda89 streams: Add folder foreign key to Stream table.
This commit also adds "folder_id" field in stream and subscription
objects.

Fixes part of #31972.
2025-05-20 13:25:06 -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
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
Ritwik
187a008f13 streams: Modify get_stream_permission_policy_name to return dict key.
This is a prep commit for #30212. It will allow us to compare the key
and not translated policy name.

Co-authored-by: Tanmay Kumar <tnmdotkr@gmail.com>
2025-04-15 16:28:38 -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
Shubham Padia
b3862c5008 user_groups: Use UserGroupMembersDict in initial state data.
On the event side, orjson does the work of converting
UserGroupMembersData to json. But when fetching intial state data,
UserGroupMembersData was being returned which is not
json-serializable. This was causing a mismatch in the `verify_action`
workflow of test_events related to stream group settings where
apply_events resulted in a state with `direct_members` and
`direct_subgroups` as part of an ordinary dict, while fetching initial
state data was giving us a UserGroupMembersData class.
This commit uses UserGroupMembersDict where appropriate. It will
still be good to keep around the dataclass class since it has the added
benefit of storing the relevant value when needed.
2025-03-18 11:53:48 -07:00
Shubham Padia
25f91a51ec streams: Do not send update event to users gaining metadata access. 2025-03-18 11:14:39 -07:00
Shubham Padia
ac9b7b5fa1 user_groups: Rename UserGroupMembersDict to UserGroupMembersData.
UserGroupMembersData is not serializable by orjson. We will be
introducing a TypedDict (which is serializable) in the next commit
called UserGroupMembersDict. This rename will help us distinguish
between the two.
2025-03-17 14:21:37 -07:00
Sahil Batra
bc2afd45b3 streams: Refactor code to handle group setting values.
This commit updates the code which computes the dict for
setting groups mapping named user groups to ID and anonymous
groups to UserGroupMembersDict. After the changes, the dict
contains only anonymous groups values and the setting values
for group IDs not present in dict will be computed based on
the fact that those are named user groups.

This is a preparatory refactor for optimizing computing group
setting values for register response by fetching all anonymous
groups membership data just once.
2025-03-14 18:31:18 -07:00
Shubham Padia
86579c02f3 stream: Send stream create/delete event on group setting change.
Fixes part of #33420.
If a group setting that can grant metadata access is changed, send a
create or delete event accordingly.
2025-03-04 11:34:59 -08:00
Shubham Padia
8481dcedc4 stream: Do not pass user group object when changing group setting.
Passing the user group object in case of named user group is fine for
`do_change_stream_group_based_setting`. But for anonymous groups, if the
code path calling that function is not creating a new anonymous user
group, it has to modify the user group by itself before calling that
function. In that case, if `old_setting_api_value` is not provided,
`old_user_group` is calculated false, since the group id has not changed
for the stream, but the group membership has changed.
old_setting_api_value will be the same as new_setting_api_value in such
a case.
It is better to accept the new setting value as either an int or
UserGroupMembersDict, so that `do_change_stream_group_based_setting` can
decide what to do with that argument.
2025-03-04 11:34:59 -08:00
Sahil Batra
75b5d43a91 groups: Rename AnonymousSettingGroupDict to UserGroupMembersDict.
This change is done because we would use the same data structure
for named user groups as well in future commits.
2025-02-27 10:03:28 -08:00
Sahil Batra
f9107adaa4 streams: Do not archive vacant private streams.
We no longer archive private streams when they become vacant,
since user can still have permissions to subscribe to it.

And streams can anyways be archived manually if needed.

Fixes #33689.
2025-02-27 09:21:03 -08:00
Sahil Batra
bafec11c61 streams: Add new can_subscribe_group permission setting.
Fixes part of #33417.
2025-02-25 13:17:15 -08:00
Sahil Batra
a1ac49582b streams: Optimize computing users with metadata access.
This commit updates code to optimize computing users who have
metadata access via permission groups so that we do not have
to do DB query for each stream to get recursive members for
the groups having permissions.
2025-02-14 12:00:37 -08:00
roanster007
c562503089 markdown: Fix stream description with topic permalink not rendered.
Previously, when description for a channel -- either during its
creating or when we change its description contained a topic
permalink (through #-mention), then it was not rendered. This
is because of lack of authorization to access the channel.

This is fixed by passing the acting_user through the methods
which update or add the description, so that permissions
of the acting_user could be used to determine whether to
render the #-mention in stream description or not.
2025-02-12 12:50:25 -08:00
Shubham Padia
552b464de7 stream: Notify all users with metadata access when unarchiving. 2025-02-12 09:35:17 -08:00
Shubham Padia
3893dcfcb8 stream: Do not send redundant events to users with metadata access.
When a user gets access to a private channel, they get a stream creation
event. Channel admins and users in `can_add_subscribers_group` already
have metadata access to a private channel and therefore do not need to
be notified.
2025-02-11 15:09:16 -08:00
Shubham Padia
35f9305acb stream: Modify flag to allow access for users with metadata access. 2025-02-11 15:09:16 -08:00
Shubham Padia
9725de99e9 stream: Move bulk_get_subscriber_peer_info to subscription_info.
We were not able to use
get_user_ids_with_metadata_access_via_permission_groups in the function
in question due to a cyclic dependency to `lib/streams.py`.
2025-02-11 15:09:16 -08:00
Shubham Padia
48eec43f48 stream: Notify users with metadata access on unarchiving stream. 2025-02-11 15:09:16 -08:00
Shubham Padia
f6301c24fe stream: Notify users with metadata access for lib/streams.py.
Users in `can_administer_channel_group` and `can_add_subscribers_group`
have access to private channel metadata. They should be notified of
relevant events.
We've only made relevant changes to lib/streams.py in this commit to
make the changes small and reviewable.
2025-02-11 15:09:16 -08:00
Shubham Padia
9e09a240d7 stream: Pass is_subscribed to check_basic_stream_access.
Earlier, we were passing the whole subscription object to the function
in order to check if the user was subscribed or not. In the future
commits, we want to check that without fetching and passing the complete
subscription object and this commit will help us do that.
2025-02-11 15:09:16 -08:00
Prakhar Pratyush
77baa05aa9 streams: Set realm stream fields to NULL when streams are deactivated.
When a stream configured for any of these settings is deactivated,
the corresponding realm settings should be set to NULL:
* new_stream_announcements_stream
* signup_announcements_stream
* zulip_update_announcements_stream
* moderation_request_channel

Earlier, we were not updating those realm settings to NULL.
We had helper functions like 'get_new_stream_announcements_stream'
to return None if the configured stream was deactivated.
But it makes more sense to just set them to NULL in DB.

This commit also includes a migration to clear those fields
if the configured channels are deactivated.
2025-02-05 12:21:55 -08:00
Aditya Kumar Kasaudhan
21412b9f79 channels: Auto-mark channel archival event messages as read.
Previously, channel archival event messages were unread in
archived channels, which makes the archived channel accessible
from the inbox view.
This commit fixes this issue by auto-marking the channel archival
event message as read.

Fixes: zulip#33258.
2025-02-04 11:01:20 -08:00
bedo
21199beb73 stream_delete_event: Include only stream IDs in the event.
Fixes #32369

Migrate stream delete event to include only stream ids in the form of
"stream_ids": [1,...], because clients only need the ids.

While keep sending ids in the form of "streams": [{stream_id: 1},...]
for compatibility with all clients other than web.
2025-01-24 17:58:32 -08:00
Shubham Padia
97996b9929 streams: Add can_add_subscribers_group as a setting.
We're not using this setting to check the permissions yet.
2025-01-22 14:27:06 -08:00
Sahil Batra
8d6a8f8833 streams: Remove API support for changing stream_post_policy. 2025-01-07 12:17:36 -08:00
Sahil Batra
82781d3281 streams: Send message on changing stream posting permission. 2025-01-07 12:17:35 -08:00
Sahil Batra
1d7a77b9a8 streams: Pass stream_post_policy value according to the group setting.
The stream and subscription objects now have stream_post_policy value
set according to the can_send_message_group setting representing the
superset of users who have permission to post in the channel.
2025-01-07 12:17:09 -08:00
Sahil Batra
101e94b052 streams: Add group based setting to control posting permissions. 2025-01-07 12:17:07 -08:00
Shubham Padia
eb943d54a9 streams: Add can_administer_channel_group as a stream setting.
We have not added current user as the default for new channels in this
commit.
2024-12-03 18:38:25 -08:00
Aman Agrawal
50256f4831 stream: Add field to track active status of stream. 2024-11-27 17:31:06 -08:00