Commit Graph

221 Commits

Author SHA1 Message Date
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
Sahil Batra
943e754a90 streams: Do not include deactivated users in group setting values.
This commit fixes the code to not include deactivated groups in
stream setting values when the setting is set to an anonymous
group. This is consistent with what we do for realm and user
group settings.

As a result, we also deduplicate some code by using existing
function used for realm and group settings.
2025-03-12 17:14:05 -07:00
Tim Abbott
c58f14b159 streams: Allow editing subscriptions in archived channels.
Since this does impact the ability to access the channel's content, it
makes sense to permit changing subscriptions, just like other
permissions settings on the archived channel.
2025-03-07 18:08:41 -08:00
Tim Abbott
494f28c64e streams: Add require_active_channel access parameter. 2025-03-07 18:08:41 -08:00
Tim Abbott
f68692a893 access_stream: Use mandatory kwargs. 2025-03-07 18:08:41 -08:00
Tim Abbott
e92d68fffe streams: Remove require_active in access_stream code path.
This was confusingly doing an assertion about the subscription being
active, not the channel. We could rename it to
require_active_subscription. But it was only passed with a non-default
value in b2cb443d24, and that call was
removed in 378062cc83.
2025-03-07 18:08:41 -08:00
ImDooMLorD
6dea58623c errors: Standardize "already in use" error messages.
Updates these error messages to have "X is already in use." format,
e.g., "Channel name is already in use." and "Name is already in use."

Fixes #33629.
2025-03-04 16:10:25 -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
Shubham Padia
e57c43b705 bots: Do not remove bot from inaccessible streams on owner change.
See
https://chat.zulip.org/#narrow/channel/101-design/topic/manage.20bot.20access.20feature.20removal
2025-02-26 09:30:24 -08:00
Shubham Padia
a80b2e478c get_streams: Return metadata access streams in include_all.
This parameter is no longer restricted to realm administrators. Any
user can get the streams they have metadata access to by setting this
parameter to true.
2025-02-25 14:25:43 -08:00
Sahil Batra
7d0cef6911 streams: Do not fetch can_add_subscribers_group unnecessarily.
In public_stream_user_ids function, which is used to get users
who can access public streams, there is no need to fetch members
of can_add_subscribers_group as we eventually exclude guests
from them and we have already included all non guest users of
the realm.
2025-02-25 13:17:15 -08:00
Sahil Batra
62478f900d streams: Modfiy stream permissions to use can_subscribe_group.
Fixes part of #33417.
2025-02-25 13:17:15 -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
Shubham Padia
ce031c4b52 get_stream: Rename include_all_active to include_all.
We keep around the old `include_all_active` parameter for backwards
compatibility.
Web frontend doesn't use this API and thus there were no changes needed
there.
2025-02-24 22:17:15 -08:00
Shubham Padia
6dde44cf37 get_streams: Add include_can_access_content.
Also add some query count checks.
See https://chat.zulip.org/#narrow/channel/378-api-design/topic/GET.20.2Fstreams.20with.20new.20permissions/with/2096944
for API design discussion.
2025-02-24 22:15:18 -08:00
Shubham Padia
f6bb990b91 user_group: Move UserGroupMembershipDetails from lib/streams.py. 2025-02-21 15:36:07 -08:00
Shubham Padia
63a4aea7a8 streams: Add get_content_access_streams function.
To get content access streams for mention.py, we will now use
get_content_access_streams and we have done a lot more other refactors
in this commit around filter_stream_authorization. Mainly making that
function only to be used for adding subscribers and naming it
accordingly.
2025-02-21 15:36:07 -08:00
Shubham Padia
a7b5960c98 message: Allow to send without subscribing if user has content access.
If the user has content access and is part of the
`can_send_message_group`, they can send a message to streams with shared
history. We do not allow them to send messages to stream with protected
history since they it would go into a void and they cannot see the
message later.
See https://chat.zulip.org/#narrow/channel/101-design/topic/shared.20history.20can.20send.20message/with/2095398
2025-02-21 15:36:07 -08:00
Shubham Padia
dcaf0dd103 stream: Function to check if user is in groups granting content access.
We're going to be adding a new setting called `can_join_group` soon and
it would be good to have this wrapper function ready for it to be used
in.
2025-02-16 17:12:30 -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
Aman Agrawal
75be449d45 CVE-2025-25195: Only send "active" change events to channel subscribers.
This fixes a bug where private stream event to update stream's
active status was sent to all active users instead of just
its subscribers.
2025-02-13 11:58:23 -08:00
Aman Agrawal
a2a1a7f8d1 streams: Use a common func to send stream recently active update event.
This helps us to apply fix for sending event update for
private stream to only its subscribers.
2025-02-13 11:58:23 -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
1db2487f1c stream: Guest users cannot get metadata access to channel via groups. 2025-02-12 09:35:17 -08:00
Tim Abbott
77d3029ec5 streams: Exclude guests from permissions groups access.
This adds missing enforcement and explanatory comments regarding
`allow_everyone_group` for these permissions code paths.
2025-02-11 15:09:16 -08:00
Shubham Padia
cbd23cc535 stream: Notify guest add subscribers group users for public channels.
For the test, we've only modified `test_rename_stream` to test for this
+ the guest susbcriber test case that was missing.
2025-02-11 15:09:16 -08:00
Shubham Padia
33ea2b366e user_groups: Add function to get union of members of two groups.
This helps us important database queries when we want to perform a union
on the members of multiple user groups.
2025-02-11 15:09:16 -08:00
Shubham Padia
121af1c815 stream: Pass group id to get recursive group members.
Previously, we needed to pass the group to the function, which sometimes
meant having 1 extra query to fetch the user group when we just needed
the group id for this function.
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
aabf42c2ce stream: Show private channel for their channel admins.
Fixes https://chat.zulip.org/#narrow/channel/101-design/topic/permissions.20for.20admin.20to.20unsubscribe.20others/near/2060197
Non realm admin users were not able to view private channels they were
an administrator of but not subscribed to it. This commit changes that.
We also made changes for those users to be able to see the subscribers
list.

The increase in query count in test_home and test_event_system can be
mitigated by only fetching recursive user group ids when needed within
the `validate_user_access_to_subscribers_helper` function. But that
would require refactoring that function to handle multiple streams and
subscriptions at once, along with changing how that function is used at
different places, which might be an exercise better left as a follow up.
We have optimised the code a little bit by not fetching the group ids in
case the current user is a realm admin.

We are fetching channel_admin_ids and users belonging to
can_add_subscribers_group directly in stream_subscription.py without
using the helper function
`get_user_ids_with_metadata_access_via_permission_groups`. This is due
to a cyclic dependency and we will move `bulk_get_subscriber_peer_info`
to another file in the next commit.
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
ca1aba9fc3 stream: Allow realm & channel admins to change private channel setting.
Previously, realm and channel admins were not able to change settings
for a private channel they were not subscribed to. This commit changes
that.

We have only added the exception for can_add_subscribers_group
and not privacy settings.

We also need proper functions with proper terminologies for content
and metadata access.
2025-02-11 15:09:16 -08:00
Shubham Padia
4d02a082a0 stream: Users with permission to administer can unsubscribe others.
We've also converted the function to check for permission to unsubscribe
others to accept a list of streams instead of checking each stream one
by one.
2025-02-11 15:09:16 -08:00
Shubham Padia
0f51b029a0 stream: User with just can add permissions should be able to add. 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
Shubham Padia
98c5243c9b stream: Refactor to use functions for administer and add subscribers. 2025-02-11 15:09:16 -08:00
Tim Abbott
bd8b845a4d mention: Use filter_stream_authorization.
In preparation for accessing the messages in channels to link topics
in them, we need to check channel access.
2025-02-03 18:48:24 -08:00
Shubham Padia
6852142b00 stream: Rename can_administer_channel to reflect what it checks.
We've added a comment highlighting that the function does not check
whether a user has access to the channel or not. Adding `accessible` to
the function name further emphasises that.
2025-01-27 11:26:06 -08:00
Shubham Padia
bf5bdacf51 stream: Use dataclass for filter_stream_authorization return type. 2025-01-27 11:26:06 -08:00
Shubham Padia
e912ada51e stream: Rename can_subscribe_others_to_all_streams.
Rename `can_subscribe_others_to_all_streams` to
`can_subscribe_others_to_all_accessible_streams` so it's clear that we
are not attempting to check basic access in this function.
2025-01-27 11:26:06 -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
a76042ce39 invite: Any combination of default streams should be subscribe-able.
Fixes #32706.

A user with permission to invite users should be able to subscribe users
to any of the default streams whether they have the permission to do so
or not for each of those default streams or not. This should only happen
in the invite code path, and not the subscribe code path.

This commit also adds the ability to pick and chose default streams if
you do not have the permission to subscribe to any other channels.

Before this, if you did not have the permission to subscribe any other
channels, only the checkbox to subscribe to all the default streams at
once was available to you.

For the stream pill typeahead, we don't show streams that the user
cannot subscribe other users to. For more details, see

   https://chat.zulip.org/#narrow/channel/101-design/topic/can.20subscribe.20other.20users.20permission.20invite
2025-01-22 14:27:06 -08:00
Shubham Padia
41c74314c0 streams: Use can_add_subscribers_group for permission check.
The function to check relevant permissions does so for multiple streams
at once to save us database query counts. Doing it one by one for every
stream would become very expensive.
We've also added `insufficient_permission_streams` to the filter
functions return type for streams for which the current user does not
have permission to subscribe other users.
2025-01-22 14:27:06 -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
Mateusz Mandera
e41ee8abf5 streams: Tweak query in update_stream_active_status_for_realm.
The NOT EXISTS structure might be better optimized by the Postgres query
planner and might lead to slightly better performance than the id NOT IN
(<subquery>) structure.
2025-01-09 11:56:11 -08:00
Sahil Batra
b4b571d60c streams: Remove stream_post_policy field from Stream. 2025-01-07 12:17:37 -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
2d09cd899e message: Use new setting for checking stream posting permissions. 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