Commit Graph

19867 Commits

Author SHA1 Message Date
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
Prakhar Pratyush
ccc82976dc unread_data: Ensure deterministic ordering of unread message rows.
Earlier, in `get_raw_unread_data` the ordering was applied inside
the CTE.

Once we leave the CTE scope and do a join, SQL makes no promise
about preserving the row order unless we re-specify ORDER BY in
the outer query.

Since, there was no ORDER BY clause in the outer query it was
resulting in a random ordering of the entries. This bug was caught
by `test_unreads_case_insensitive_topics` failing in a flaky way.

This commit fixes the bug.
2025-04-22 10:36:59 -07:00
Alex Vandiver
6b3143d7fc send_email: Add a flag to force all emails through the queue.
Sending emails synchronously is useful because it reports
configuration errors -- but it also means that occasional failures can
result in ugly 500's, since those don't retry.

Add a setting which forces all email to go through the `emil_senders`
queue, so it can be retried as needed.
2025-04-22 10:26:25 -07:00
Lauryn Menard
19f60b203d api-docs: Add note about realm being present in fetch_event_types.
Adds "Present if realm is present in fetch_event_types" to the
fields in the POST /register response that are added to the state
data via fetch_initial_state_data in the if block for "realm".
2025-04-21 14:58:26 -07:00
Prakhar Pratyush
bf95e9bcae test_push_notifications: Split HandlePushNotificationTest to a new file.
This commit moves `HandlePushNotificationTest` to a new
`test_handle_push_notification.py` file.

It helps in making it easier to work with `test_push_notifications.py`
which was 4000+ lines of code.
2025-04-17 10:55:05 -07:00
Prakhar Pratyush
f98c36210a test_push_notifications: Move PushNotificationTest to test_classes.py.
This is a prep commit which moves the `PushNotificationTest` class
from `test_push_notifications.py` to `test_classes.py` as we plan to
import it and reuse it in other files.

This commit also renames `PushNotificationTest` to
`PushNotificationTestCase` to align with our naming convention
in `test_classes.py` to name classes, which act as a parent class
with helper methods and no actual test within itself, with a
"TestCase" suffix.
2025-04-17 10:55:05 -07:00
Prakhar Pratyush
644efeaa14 test_push_notifications: Rename TestPushApi and it's test methods.
`TestPushApi` was not a great name to reflect what it specifically
tests.

Renamed it to `TestAddRemoveDeviceTokenAPI`. It's test methods
are also renamed for clarity.
2025-04-17 10:55:05 -07:00
Prakhar Pratyush
393423c3a0 test_push_notifications: Split AnalyticsBouncerTest to a separate file.
This commit moves `AnalyticsBouncerTest` to a new
`test_zilencer_analytics.py` file.

It helps in making it easier to work with `test_push_notifications.py`
which was 5000+ lines of code.
2025-04-17 10:55:05 -07:00
Niloth P
22c80117f5 integrations: Add OpenSearch incoming webhook integration.
Co-authored-by: merlinz01 <158784988+merlinz01@users.noreply.github.com>
2025-04-16 14:05:29 -07:00
Kislay Verma
e2e0603689 message_edit: Check previous message content to prevent races.
Similar to group based setting values, we expect
the client to send the previous content alongwith
the edited content to the edit message endpoint.
We reject the request incase the previous content
doesn't match the current message content, which
could happen in case two users simultaneously edit
a message - which will be implemented in #33051.
2025-04-16 14:05:12 -07:00
Kislay Verma
5b5be39b19 exceptions: Create base class ExpectationMismatchError.
This class will be inherited by all errors related to
some sort of mismatch from the expected value.

This is a prep commit for #33051, as a part of which we
add a new exception class for message content mismatch.
2025-04-16 14:05:12 -07:00
Karl Stolley
3278fc36ca variables: Correct instances of misspelled 'message'. 2025-04-16 13:17:19 -07:00
Sahil Batra
d34bdf8af5 users: Fix comment for base_bulk_get_user_queryset.
We no longer fetch can_access_all_users_group using
select_related after #34356.
2025-04-16 09:02:45 -07:00
Mateusz Mandera
57d77e0a55 realm_creation: Disable open realm creation if no password backend. 2025-04-15 18:28:16 -07:00
Mateusz Mandera
c4bb6509dd signup: Prevent unauthorized signup for realms without EmailAuthBackend.
Zulip supports a configuration where account creation is limited solely
by being able to authenticate with a single-sign on authentication
backend, such as Google Authentication, SAML, or LDAP (i.e., the
organization places no restrictions on email address domains or
invitations being required to join, but has disabled the
EmailAuthBackend that is used for email/password authentication).

A bug in the Zulip server meant that Zulip allowed users to create an
account in such organizations by confirming their email address, without
having an account with the SSO authentication backend.

Co-authored-by: Tim Abbott <tabbott@zulip.com>
2025-04-15 18:28:16 -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
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
opmkumar
8482a9480b email: Apply message content visibility settings to digest too.
Fixes #33190.
2025-04-15 16:24:59 -07:00
opmkumar
8c556cafbb email: Update "Log in" string in digest emails. 2025-04-15 16:24:59 -07:00
opmkumar
5530981db9 email: Update message content disabled wording for missed messages.
This commit updates the wording used in missed messages emails
when message content is disabled.
The corresonding help URL included in the email has also
been updated.
2025-04-15 16:24:59 -07:00
opmkumar
ec81c027fc digest: Pass length of hot_conversations to enough_traffic function.
Previously, `hot_conversations` was incorrectly passed as a string to the
`enough_traffic` function. This commit fixes the issue by passing the length
of `hot_conversations` as a parameter instead.
2025-04-15 16:24:59 -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
Sahil Batra
7e77100433 users: Remove unused variable in get_user_dicts_in_realm. 2025-04-11 17:37:06 -07:00
Sahil Batra
7ebea853be user_groups: Refactor user_has_permission_for_group_setting.
This commit refactors user_has_permission_for_group_setting
to accept setting group ID instead of UserGroup object.

We only need ID in checking the permission and this helps in
further commit to avoid prefetching can_access_all_users_group
setting.
2025-04-11 17:37:06 -07:00
Prakhar Pratyush
68b7deac72 messages: Clarify comment on zerver_message_edit_history_id idx.
This commit removes a misleading comment regarding
'zerver_message_edit_history_id' index.

We added the index in 0679 to use in 0680 but later the 0680 migration
was reworked resulting in the index not being used in 0680.

We didn't drop the index as we expect it to be helpful for other
things.

The comment was misleading hence removed.
2025-04-11 12:38:11 -07:00
Alex Vandiver
e1aa8b1cb0 tusd: Use GCS upload backend when the endpoint matches.
This works around tus/tusd#322, which in turn is caused by
aws/aws-sdk-go-v2#1816.  This requires separate authentication via
service account key.

Fixes: #34186.
2025-04-11 12:16:03 -07:00
Alex Vandiver
cf51013bb7 tusd: Reject tusd terminations after we insert them into our database.
The tusd protocol allows DELETE requests ("terminations") at any
point, including after a file has successfully been uploaded.  This
can allow tusd to remove a file from the bucket, out from under Zulip.

We use the new-in-2.7.0 pre-terminate hook to look up the file which
the client is requesting to terminate, and reject the termination if
it is a file that the Zulip database is already aware of.
2025-04-11 12:13:07 -07:00
Sanchit Sharma
d5c83e02c3 streams: Return archived web-public channels. 2025-04-11 08:12:53 -07:00
Anders Kaseorg
ad31ef22f2 narrow: Fix get_base_query_for_search access restrictions.
The type_id is the id of a UserProfile, Stream, or DirectMessageGroup,
not the id of a type.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-04-10 15:26:57 -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
Alex Vandiver
aeed907c50 s3: Support non-AWS S3 providers which do not support request checksums. 2025-04-10 11:11:25 -07:00
Alex Vandiver
33339f89c3 tusd: Use default already set in computed_settings.
Having an additional fallback here is not necessary.
2025-04-10 10:13:11 -07:00
Shubham Padia
98950314ba user_groups: Realm admins should be allowed moderator permissions.
For `check_user_has_permission_by_role`, we were using
`user.is_moderator` by default to check whether the user had those
priviliges. But that specific function returns false if the user is an
admin or an owner. So we check `is_realm_admin` too in that case.
2025-04-09 15:30:05 -07:00
theofficialvedantjoshi
194dfbc84d integrations: Add common framework for webhook signature verification.
Fixes: #19774
2025-04-09 15:05:57 -07:00
Tim Abbott
ab068389ff api: Increment API feature level to 378. 2025-04-08 12:45:53 -07:00
Sahil Batra
7c470f0161 streams: Fix events send when archiving and unarchiving streams. 2025-04-08 12:41:09 -07:00
Sahil Batra
ae579aa25a register: Include archived channels in "streams" field. 2025-04-08 12:41:09 -07:00
Sahil Batra
a6cc33f478 events: Do not compute first_message_id unnecessarily.
"first_message_id" field for subscription objects needs
to be updated when archiving a stream as we send a
notification message, but first_message_id will only
change if the stream did not have any messages previously.

This commit updates the code to update first_message_id
only when required.
2025-04-08 12:41:09 -07:00
Sahil Batra
1b35ad3094 message: Use set instead of list when checking DM permission.
When checking DM permissions, instead of using list of
users, we now use set of users to check if any user is
in direct_message_permission_group because there can be
case when sender can also be one of the recipients.
2025-04-08 12:32:33 -07:00
Anders Kaseorg
e8faa4a029 worker: Check if Sentry is initialized before calling add_breadcrumb.
Otherwise we get spammed with “Dropped breadcrumb because no client
bound” log messages.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-04-08 10:17:49 -07:00
Ethan Mayer
c12b94aea4 models: Refactor corporate/models.py into models package.
Fixes #34318.

Seperated models file into a package with component files.
2025-04-08 10:16:35 -07:00
Ritwik
9feba0f16f emoji: Remap ':smile' emoji and update the settings UI.
This commit remaps the ':smile' emoji to 😄 and
introduces ':slight_smile' which maps to `🙂`.

Fixes #32712
2025-04-07 17:34:52 -07:00
Sahil Batra
f29166dbba settings: Do not pre-fetch DM permission group settings.
This commit updates code to not pre-fetch DM permission
group settings using select_related and instead just
fetch the required data from DB when checking permission.

This will increase one query but will help in pre-fetching
the settings for all users and for all type of messages.

Fixes part of #33677.
2025-04-07 15:34:30 -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
Varun-Kolanu
59d5d29ed8 integrations: Add support for GitLab design comments.
Fixes #26199.

Co-authored-by: Barış <barisunsalhn@users.noreply.github.com>
Co-authored-by: Satyam Bansal <sbansal1999@gmail.com>
2025-04-07 11:54:37 -07:00
Varun-Kolanu
aaa2db4079 webhooks: Support no_previews argument for markdown messages.
This commit enables skipping inline image previews
by passing the no_previews field to check_send_webhook_message.
2025-04-07 11:53:19 -07:00
Shubham Padia
12afeee277 test_classes: Mention actual and expected count in assert_length. 2025-04-07 10:19:57 -07:00