933 Commits

Author SHA1 Message Date
Prakhar Pratyush
621eb1f610 prior_mention_user_ids: Exclude user who no longer has message access.
This commit updates the 'get_mentions_for_message_updates' function to
use the generic 'event_recipient_ids_for_action_on_messages' function
to determine users having access to the message and perform an
intersection with the mentioned users to filter out the users who
no longer can access the message.

It helps to add hardening such that if the invariant "no usermessage
row corresponding to a message exists if the user loses access to the
message" is violated due to some bug, it has minimal user impact.
2025-01-28 13:59:08 -08:00
Prakhar Pratyush
ce6b5cf068 message_edit: Fix recipient of event due to 'do_update_embedded_data'.
This commit updates the 'do_update_embedded_data' function to use
the generic 'event_recipient_ids_for_action_on_messages' function
while deciding the event's recipients.

It helps to add hardening such that if the invariant "no usermessage
row corresponding to a message exists if the user loses access to the
message" is violated due to some bug, it has minimal user impact.
2025-01-28 13:59:08 -08:00
Mateusz Mandera
0caf815e36 do_activate_mirror_dummy_user: Assert user_profile is a mirror dummy.
If this is called on a user without is_mirror_dummy=True, that seems
certain to be a bug. Therefore, an assert is preferable in order to
catch this, rather than returning early with noop like some other
function such as do_deactivate_user.
2025-01-28 09:38:56 -08:00
whilstsomebody
b571f92206 message_edit: Disallow empty topic when mandatory topic is true.
Previously, 'check_update_message' allowed moving messages to
empty topic even with `mandatory_topic=true`.

This commit fixes the bug. We now raise an error in that case.

Co-authored-by: Prakhar Pratyush <prakhar@zulip.com>
2025-01-27 11:45:58 -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
PieterCK
25f64a9a67 message_send: Include service bots as UserMessage eligible.
Previously, service bots don't get UserMessage rows for new messages to
optimize performance. This commit adds UserMessage row for service bots
so that they behave more similarly to generic bots.
2025-01-24 17:56:44 -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
Shubham Padia
275a1a4c69 realm: Use can_add_subscribers_group instead of invite_to_stream_policy.
We remove `invite_to_stream_policy` from the backend wherever applicable
except deleting the field. We have just ported the existing behaviour of
`invite_to_stream_policy` to `can_add_subscribers_group` except one
change. We have added an explicit exception for admins to have this
permission whether they are part of this group or not. The reason for
this is we are adding `stream.can_add_susbcribers_group` in the future
which will grant all admins permission to subscribe other users to a
channel given they have access to a channel. So it makes sense that we
add this exception to the realm level property also.
See https://chat.zulip.org/#narrow/channel/101-design/topic/Can.20subscribe.20other.20users.20on.20user.20profile/near/2039825
2025-01-22 12:33:58 -08:00
Steve Howell
deb53070ae default streams: Return set instead of a list.
We also change the test helper.

The tests hopefully read more clearly in places
here, and we also communicate to the dev that
order is arbitrary.
2025-01-22 10:55:25 -08:00
ritwik-69
dd56e04dc6 presence: Record stats for invisible users. 2025-01-22 09:19:15 -08:00
Sahil Batra
92376fc133 message_edit: Rename get_message_edit_request_object.
"build_message_edit_request" is a better name for the function.
2025-01-22 09:11:47 -08:00
Sahil Batra
5f8959397b message_edit: Set stream_topic only if content is edited.
stream_topic variable is needed only when updating content
so we set the field inside is_content_edited block.

Also added a comment clarifying about why we use orig_stream
for stream ID.
2025-01-21 15:33:45 -08:00
Sahil Batra
37f2c5bc78 message_edit: Refactor message edit code.
We add two dataclasses which stored the info for what
needs to be changed the original values to make the
code easy to read.
2025-01-21 15:33:45 -08:00
Sahil Batra
187cd18e12 message_edit: Refactor message edit code for updating content. 2025-01-21 15:33:45 -08:00
Sahil Batra
a2c6997879 message_edit: Always pass realm ID to update_message_cache.
We already have realm_id from message object passed to
do_update_message so there is no need to pass "None" to
update_message_cache for direct messages.

Previously, if "None" was passed to update_message_cache,
realm_id was eventually computed from stream if it was
a stream message and from Message object for direct messages.
But we always passed a value which is not "None" for stream
messages, and we can be sure that the message.realm will
always be the realm in which stream is present to which the
message was sent.
2025-01-21 15:33:45 -08:00
Prakhar Pratyush
fb91cd6f4d message_edit: Disallow resolving empty string topic.
This commit makes changes to the edit message endpoint
to disallow resolving empty string topic.

It also removes the resolve topic button in the web client
from topic popover and message header for empty string topic.
2025-01-14 14:22:21 -08:00
Anders Kaseorg
f223251ffe requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-01-14 09:42:16 -08:00
Vector73
e487a5c8c7 reaction: Add user object back in reaction events.
The deprecated `user` object was removed from message objects
and reaction events in #32701. This commit restores the `user` object
in reaction events to maintain compatibility with mobile clients.
2025-01-13 12:57:55 -08:00
Alex Vandiver
9fa5ab951c mime_types: Move INLINE_MIME_TYPES to prevent future import loops. 2025-01-09 09:09:13 -08:00
Lauryn Menard
e5bafb625b email: Update realm deactivation email for data deletion information.
Fixes #24686.
2025-01-08 16:27:11 -08:00
Prakhar Pratyush
27e95f7d33 user_topic: Add support for empty topic name.
This commit is a part of the work to support empty string
as a topic name.

Previously, empty string was not a valid topic name.

Now, toggling topic visibility policy operation supports
empty topic name.

Adds backward compatibility for:
- `topic_name` field in the `user_topic` event type
2025-01-07 17:24:00 -08:00
Prakhar Pratyush
2dea392d9e message_edit: Add support for empty topic name.
This commit is a part of the work to support empty string
as a topic name.

Previously, empty string was not a valid topic name.

Now, message edit operation supports empty topic name.

Adds backward compatibility for:
- `topic` field in the `delete_message` event type
- `orig_subject` and `subject` fields in the `update_message`
   event type
2025-01-07 17:24:00 -08:00
Prakhar Pratyush
3ba198e79a message_send: Add support to send message with an empty topic name.
This commit is a part of the work to support empty string
as a topic name.

Previously, empty string was not a valid topic name.

Adds a `empty_topic_name` client capability to allow client
to specify whether it supports empty string as a topic name.

Adds backward compatibility for:
- `subject` field in the `message` event type
2025-01-07 17:24:00 -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
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
opmkumar
3b3ab05f67 cron: Add cron job logic to delete fully deactivated realms.
Fixes #32763.
2025-01-06 16:10:14 -08:00
Aman Agrawal
0a6579640f message_send: Fix stream still inactive after sending message.
We updated the stream property but forgot to inform the client.
2025-01-03 14:14:39 -08:00
Anders Kaseorg
19b8cde27f ruff: Fix PLC0206 Extracting value from dictionary without calling .items().
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-12-21 21:06:53 -08:00
opmkumar
5b0c55fda3 realm: Add option to schedule data deletion while deactivating.
Introduce a feature to schedule realm data deletion time during realm
deactivation. This includes a server-level setting to configure the
minimum and maximum allowed deletion days.

Co-authored-by: Ujjawal Modi <umodi2003@gmail.com>
Co-authored-by: Lauryn Menard <lauryn@zulip.com>

Fixes #24677.
2024-12-18 23:06:12 -08:00
PieterCK
943fbb76fe settings: Add realm-level setting moderation_request_channel.
This commit introduces a new non-operational
`moderation_request_channel` field to the server/API. This setting will
support a feature allowing users to flag or report abusive content
(harassment, spam, etc.).

Fixes part of #20047.
2024-12-18 11:36:19 -08:00
Sahil Batra
1c933dd231 streams: Include only IDs in default streams data.
Clients do not need complete stream objects in the default
streams data since they already have that via streams and
subscriptions data.
2024-12-17 09:40:10 -08:00
Vector73
143ca5065e api: Remove user object from reactions objects in the API.
Removes deprecated `user` object from reactions objects returned by
the API as it is redundant because of the presence of `user_id` field in
the API and is not used by any clients now.
2024-12-13 09:58:25 -08:00
Sahil Batra
118e6c36f8 message_send: Fix checking permission to send DMs.
This commit fixes the code to add a check for whether the
setting is set to an anonymous group or not before checking
if the setting is set to "Nobody" group by checking the
group name.
2024-12-06 09:23:45 -08:00
Prakhar Pratyush
3bad36ef8c queue: Rename queue_json_publish to queue_json_publish_rollback_unsafe.
This commit renames the 'queue_json_publish' function to
'queue_json_publish_rollback_unsafe' to reflect the fact that it doesn't
wait for the db transaction (within which it gets called, if any)
to commit and sends event irrespective of commit or rollback.

In most of the cases we don't want to send event in the case of
rollbacks, so the caller should be aware that calling the function
directly is rollback unsafe.

Fixes part of #30489.
2024-12-06 09:23:02 -08:00
Prakhar Pratyush
ebf1438640 message_edit: Update check_message_update to use queue_event_on_commit.
Earlier, we were using 'queue_json_publish' in 'check_message_update'
which can lead to a situation where we enqueue event but the
transaction fails at a later stage.

Events should not be sent until we know we're not rolling back.
2024-12-04 12:14:23 -08:00
Sahil Batra
74f7488009 user_groups: Refactor code creating group objects for creation events.
This commit refactors code to use a loop over GROUP_PERMISSION_SETTINGS
for adding setting values to the group objects sent in group creation
events.
2024-12-04 12:11:52 -08:00
Sahil Batra
367a0bdbff groups: Remove id_field_name field from GroupPermissionSetting.
id_field_name was being used only to set the initial dummy
values for realm settings. We can directly add "_id" to the
setting name instead of having an extra id_field_name field.
2024-12-04 11:15:17 -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
Sahil Batra
7e6a02b82d user_groups: Add setting to control who can remove members.
This commit adds a new setting to control who can remove
members from the group.
2024-12-02 17:38:44 -08:00
Aman Agrawal
81c345483e message_edit: Update stream active status when moving messages.
Update the active status of new stream where the messages are moved
into, if appropriate.

Tested by deleting all messages in a stream. Running the command
to update stream status to mark it inactive. Then moving messages
into the stream to check if the status is updated correctly to active.
2024-11-27 17:31:06 -08:00
Aman Agrawal
50256f4831 stream: Add field to track active status of stream. 2024-11-27 17:31:06 -08:00
sujal shah
771d3b1434 invites: Enable adding users to user groups during invitations.
This commit allows users to be assigned to custom groups when
inviting them to join Zulip, similar to how channels are handled.
The implementation follows a similar pattern for adding pills,
ensuring consistency, as user groups and channels are parallel
in nature.

Fixes #24365.
2024-11-26 11:26:34 -08:00
Prakhar Pratyush
ded6bfd3f2 add_new_user_history: Remove the RECENT_MESSAGES_TIMEDELTA limit.
We give the new users some messages in their feed.

Earlier, we were including upto 1000 messages which were sent
within the last 12 weeks.

For realms with low-traffic it results in very few messages
being included in the new user's feed.

This commit removes the 12 week limit.
Now, we simply include upto 1000 recent messages.
2024-11-22 10:41:27 -08:00
Prakhar Pratyush
175104ea01 streams: Add 'ChannelEmailAddress' model.
This commit removes the 'email_token' field from the
'Stream' model, introduces a new model 'ChannelEmailAddress',
and backfills it.

This is a prep work towards our plan to generate unique
channel emails for different users, which can be used
to check post permissions at message send time.
2024-11-21 14:53:28 -08:00
Vector73
4e89b4a88c settings: Add can_invite_users_group realm setting.
Added `can_invite_users_group` realm setting to replace
`invite_to_realm_policy`.
2024-11-20 13:35:05 -08:00
Sahil Batra
7adc83d2a0 streams: Optimize code for computing stream objects.
This commit updates code to optimize code for computing stream
objects to be sent with stream creation event and in response
for 'GET /streams/{stream_id}' endpoint by optimizing number
of queries while computing values for group permission settings.

This change does not benefit much currently as we only have one
stream group permission setting, but is important before we add
more stream permission settings.

There are a couple of places left where we can still optimize
the code and that would be done in further commits.
2024-11-18 11:55:19 -08:00
Sahil Batra
2cc0f482e1 streams: Refactor code to compute setting group values.
This commit adds a new function to compute setting group
values for a list of streams, so we can avoid having duplicate
code for computing setting group IDs from streams.
2024-11-18 11:55:19 -08:00