Commit Graph

1301 Commits

Author SHA1 Message Date
Alex Vandiver
1e943ae7df python: Elide type=str from argparse arguments. 2025-10-17 15:34:34 -07:00
Alex Vandiver
fdcfafd13d send_custom_email: Add a flag for sending release announcements. 2025-10-09 12:10:15 -07:00
Anders Kaseorg
9ca788cbbc update_subscriber_counts: Fix annotate usage.
Commit 7f3bb4523c (#36160) broke this.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-10-03 00:01:44 -07:00
Alex Vandiver
0ffc0e810c export_search: Switch to using orjson_stream. 2025-10-01 11:21:34 -07:00
Anders Kaseorg
7f3bb4523c update_subscriber_counts: Fix union typing.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-30 16:47:54 -07:00
Anders Kaseorg
f24a0a6b81 ruff: Fix RUF059 Unpacked variable is never used.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-09-30 16:47:54 -07:00
Alex Vandiver
8c37e9c7a6 update_subscriber_counts: Fix calling without any flags. 2025-09-12 12:59:46 -07:00
Alex Vandiver
f915498e48 update_subscriber_counts: Add tool to re-sync subscriber counts. 2025-09-10 12:07:42 -07:00
Alex Vandiver
169daa31a0 settings: Derive RUNNING_INSIDE_TORNADO based on sys.argv.
This allows it to be used at application startup time.
2025-09-10 10:21:16 -07:00
Alex Vandiver
d15f2fb831 export-search: Use background workers to download attachments. 2025-08-27 10:24:21 -07:00
Alex Vandiver
7714ca3ff9 export-search: Add explicit usermessage message_id range filters. 2025-08-27 10:24:21 -07:00
Alex Vandiver
b9216c768d export-search: Use chunked regions by id range. 2025-08-27 10:24:21 -07:00
Alex Vandiver
e703f65198 export-search: Joins to usermessages may require adding a distinct. 2025-08-27 10:24:21 -07:00
Alex Vandiver
e9c6856d02 export-search: Limit to only the fields we need. 2025-08-27 10:24:21 -07:00
Alex Vandiver
ae090d9ff3 export-search: Prefetch message sender.
This avoids O(n) extra queries.
2025-08-27 10:24:21 -07:00
Saubhagya Patel
bb5c87e306 bots: Add a setting to customize the Welcome Bot message.
This commit includes the following changes:
- Add an administrator setting to customize the Welcome Bot
message when sending an invitation.
- Add an API endpoint to test the customized Welcome Bot message
by sending a copy of the message to the administrator.

Fixes #27663.

Co-authored-by: Akarsh Jain <akarsh.jain.790@gmail.com>
2025-08-08 18:59:37 -07:00
Alex Vandiver
2909d4917c send_zulip_update_announcements: Log updates in the post-deploy hook. 2025-08-06 09:52:45 -07:00
Mateusz Mandera
40b1f6eb4e confirmation: Replace RealmCreationKey - use Confirmation instead.
Fixes #20028.

There's no reason to have a special `RealmCreationKey` class - the
`Confirmation` system already does this job.

This is somewhat complicated by the need to write a migration for
`RealmCreationKey`->`Confirmation` for pre-existing, valid objects, to
avoid breaking realm creation links that haven't been used yet.
2025-08-04 18:41:15 -07:00
Anders Kaseorg
b404ca1a02 makemessages: Remove vestigial custom JavaScript extraction.
Commit d8a36d0702 (#18075) should have
removed this.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-07-28 17:44:23 -07:00
Alex Vandiver
4c2cf4dca8 compilemessages: Weblate's Language-Team uses <>. 2025-07-18 04:33:52 +00:00
Alex Vandiver
d1995687c9 i18n: Remove mobile.json-related codepaths. 2025-07-16 19:59:20 -07:00
Alex Vandiver
a5a5791794 management: Skip hourly crons during deploys.
This is most important for `send_zulip_update_announcements`, which
can race with the version run as a post-deploy hook.  However, all of
these crons can tolerate being slightly delayed, and there's little
benefit to them taking CPU or possibly hitting odd borderline race
conditions when the deploy is in progress.

For safety, we only trust the deploy lockfile if it was created
within the last hour -- deploys should not take more than an hour, and
failing to ever run hourly crons is much worse than perhaps running
them during a real very-long deploy.
2025-07-15 09:07:36 -07:00
Alex Vandiver
de67d37884 thumbnail: Add flag for when thumbnail files are missing. 2025-06-28 10:32:45 -07:00
Lauryn Menard
c797c481b3 demo-orgs: Delete expired demo orgs in archive_messages cron job.
Adds delete_expired_demo_organizations to the archive_messages
management command, which is run as a cron job.

Adds "demo_expired" as a `RealmDeactivationReasonType` to be
used for this specific case of calling do_deactivate_realm.

The function loops through non-deactivated realms that have a
demo organization scheduled deletion datetime set that is less
than the current datetime.
2025-06-07 22:53:01 -07:00
Mohammad Reza Kianifar
30d2d82d02 export_search: Support --dm option for 1:1 DMs using DM group.
Previously, the export_search command only supported the legacy
Personal recipient type for 1:1 direct messages. With this change,
the command first checks for a DirectMessageGroup for the two users
and uses it if present. If not, we fall back to the legacy logic. This
keeps compatibility as we migrate 1:1 DMs to use DirectMessageGroup.
2025-06-05 17:01:45 -07:00
Alex Vandiver
5828bfe8ce i18n: Trim {% trans %} sections by default.
This pulls in changes from the latest django-jinja[^1]
`makemessages.py` monkey-patching.  Specifically, it adds support for
`trimmed`, `notrimmed`, and the `ext.i18n.trimmed` policy.  We enable
that, which removes unsightly and unnecessary whitespace inside of
`{% trans %}` blocks.

[^1]: aac828ca63/django_jinja/management/commands/makemessages.py
2025-05-29 11:58:57 -07:00
Alex Vandiver
01e08f0e32 email_server: Attempt to reject unauth'd destinations at RCPT TO time.
This is done in a best-effort way -- we rely on the final ACL check
happening when the message is sent.  However, by then we will be in
the `email_mirror` worker, with no way to convey to the original SMTP
client that the sending failed; giving the client the information will
allow them to provide it back to the end-user, instead of merely being
swallowed up in the worker.
2025-05-19 16:39:44 -07:00
Alex Vandiver
c6e0f0b436 email-mirror: Remove HTTP interface. 2025-05-19 16:39:44 -07:00
Alex Vandiver
1f0cfd4662 email-mirror: Add a standalone server that processes incoming email.
Using postfix to handle the incoming email gateway complicates things
a great deal:

- It cannot verify that incoming email addresses exist in Zulip before
  accepting them; it thus accepts mail at the `RCPT TO` stage which it
  cannot handle, and thus must reject after the `DATA`.

- It is built to handle both incoming and outgoing email, which
  results in subtle errors (1c17583ad5, 79931051bd, a53092687e,
  #18600).

- Rate-limiting happens much too late to avoid denial of
  service (#12501).

- Mis-configurations of the HTTP endpoint can break incoming
  mail (#18105).

Provide a replacement SMTP server which accepts incoming email on port
25, verifies that Zulip can accept the address, and that no
rate-limits are being broken, and then adds it directly to the
relevant queue.

Removes an incorrect comment which implied that missed-message
addresses were only usable once.  We leave rate-limiting to only
channel email addresses, since missed-message addresses are unlikely
to be placed into automated systems, as channel email addresses are.

Also simplifies #7814 somewhat.
2025-05-19 16:39:44 -07:00
Alex Vandiver
49d2c1010a thumbnail: Add a tool to re-thumbnail spinners, or process old images. 2025-04-23 17:41:51 -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
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
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
Alex Vandiver
bee3c6eb59 runtusd: Respect application_server.nginx_listen_port.
In deploys `nginx_listen_port` set, tusd would fail to send its hook
requests, as it assumed that nginx would always be listening on
127.0.0.1:80.

Set the `nginx_listen_port` on the hook URL, if necessary.
2025-04-01 09:28:18 -07:00
Mateusz Mandera
716ead8f4e export: Also add guardrail to the management command. 2025-03-28 17:44:58 -07:00
Mateusz Mandera
9a49b6a62c export: Plumb consented_user_ids to export_usermessage_batch in a file.
This allows us to get rid of the call to `get_consented_user_ids` in
`fetch_usermessages`. Now it's only called at the beginning of the
export, eliminating the redundant db query and also resolving the
potential for data consistency issues, if some users change their
consent setting after the export starts.

Now the full export process operates with a single snapshot of these
consenting user ids.

These ids need to be plumbed through via a file rather than normal arg
passing, because this is a separate management command, run in
subprocesses during the export.
2025-03-28 17:44:28 -07:00
Alex Vandiver
9c043c6c14 tusd: Attempt to derive S3 region.
We already do this in computed_settings.py, but only if the
S3 (secret) key is set.  Those aren't required to be set, and tusd
_requires_ a region, so we try again to suss it out here.
2025-03-28 09:41:43 -07:00
Alex Vandiver
794588629d tusd: Support running without explicit AWS keys.
Fixes: #34102.
2025-03-28 09:41:43 -07:00
Alex Vandiver
d978363a75 topic: Enforce is_channel_message=True on topic queries. 2025-03-18 09:34:11 -07:00
Vector73
c049259d07 user: Remove is_billing_admin user property.
Removed `is_billing_admin` user property as it is no longer used since
billing permissions are now determined by `can_manage_billing_group`
realm setting.
2025-03-10 09:36:30 -07:00
Alex Vandiver
c5200e8b05 deliver_scheduled_emails: Use a queue, instead of infinite retries.
`deliver_scheduled_emails` tries to deliver the email synchronously,
and if it fails, it retries after 10 seconds.  Since it does not track
retries, and always tries the earliest-scheduled-but-due message
first, the worker will not make forward progress if there is a
persistent failure with that message, and will retry indefinitely.
This can result in excessive network or email delivery charges from
the remote SMTP server.

Switch to delivering emails via a new queue worker.  The
`deliver_scheduled_emails` job now serves only to pull deferred jobs
out of the table once they are due, insert them into RabbitMQ, and
then delete them.  This limits the potential for head-of-queue
failures to failures inserting into RabbitMQ, which is more reasonable
than failures speaking to a complex external system we do not control.
Retries and any connections to the SMTP server are left to the
RabbitMQ consumer.

We build a new RabbitMQ queue, rather than use the existing
`email_senders` queue, because that queue is expected to be reasonably
low-latency, for things like missed message notifications.  The
`send_future_email` codepath which inserts into ScheduledEmails is
also (ab)used to digest emails, which are extremely bursty in their
frequency -- and a large burst could significantly delay emails behind
it in the queue.

The new queue is explicitly only for messages which were not initiated
by user actions (e.g., invitation reminders, digests, new account
follow-ups) which are thus not latency-sensitive.

Fixes: #32463.
2025-03-04 16:09:25 -08:00
Anders Kaseorg
72f5df2e09 install: Remove --cacert and CUSTOM_CA_CERTIFICATES.
This has been broken for many years and nobody’s complained.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-02-24 22:29:24 -08:00
apoorvapendse
18976dd321 zerver: Remove unnecessary tusd logs during run-dev startup.
Previously, tusd printed unnecessary logs on startup while running
the tools/run-dev script. This commit resolves the issue by setting
the verbose flag to false, which defaults to true if not specified.

The required PR adding this flag was introduced in
https://github.com/tus/tusd/pull/1218.

Fixes #32301.
2025-02-23 10:57:53 -08:00
Mateusz Mandera
517538a296 management: Don't silence send_server_data_to_push_bouncer exceptions.
When these exceptions are thrown from the request-to-bouncer functions
inside of manage.py register_server/update_analytics_counts, they
shouldn't be silenced, merely calling maybe_mark_pushes_disabled in the
background.
This results in the occurrence of the error not being shown to the
user. Failure to upload analytics data when running these commands
should result in a loud, obvious error.

Failure of running register_server before this change:
```
./manage.py register_server
This command registers your server for the Mobile Push Notifications Service.
Doing so will share basic metadata with the service's maintainers:

* This server's configured hostname: zulipdev.com:9991
* This server's configured contact email address: desdemona+admin@zulip.com
* Metadata about each organization hosted by the server; see:

    <https://zulip.com/doc-permalinks/basic-metadata>

Use of this service is governed by the Zulip Terms of Service:

    <https://zulip.com/policies/terms>

Do you want to agree to the Zulip Terms of Service and proceed? [Y/n]

Mobile Push Notification Service registration successfully updated!
```

The occurrence of the error is not revealed to the user. Same concern
applies to the update_analytics_counts command.

After this change:
```
./manage.py register_server
This command registers your server for the Mobile Push Notifications Service.
Doing so will share basic metadata with the service's maintainers:
    <...>
Do you want to agree to the Zulip Terms of Service and proceed? [Y/n]

Traceback (most recent call last):
  File "/srv/zulip/./manage.py", line 150, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/zulip/./manage.py", line 115, in execute_from_command_line
    utility.execute()
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/zulip/zerver/lib/management.py", line 97, in execute
    super().execute(*args, **options)
  File "/srv/zulip-venv-cache/bb36fc1fcb6d8c70a9a0bcb7bac45d78623a9ff4/zulip-py3-venv/lib/python3.10/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
  File "/srv/zulip/zerver/management/commands/register_server.py", line 137, in handle
    send_server_data_to_push_bouncer(consider_usage_statistics=False, raise_on_error=True)
  File "/srv/zulip/zerver/lib/remote_server.py", line 453, in send_server_data_to_push_bouncer
    response = send_to_push_bouncer(
  File "/srv/zulip/zerver/lib/remote_server.py", line 233, in send_to_push_bouncer
    raise JsonableError(msg)
zerver.lib.exceptions.JsonableError: Duplicate registration detected.
```
2025-02-19 17:11:35 -08:00
Mateusz Mandera
367d193639 register_server: Rename flag to --agree-to-terms-of-service.
That's a better style than the underscores.
2025-02-13 11:03:44 -08:00
Mateusz Mandera
a8fbf6d5d5 docs: Remove HostnameAlreadyInUseBouncerError.docs_url.
Now that we introduced an URL for serving permalinks redirecting to
docs in #33444, the docs_url mechanism is no longer needed, as we can
have a URL that's safe to hard-code in register_server.py.

The HostnameAlreadyInUseBouncerError.docs_url has been merged in main
briefly enough, that this should be safe to remove.
2025-02-13 09:49:28 -08:00
Mateusz Mandera
ac0af8d5ff install: Replace RTD links with our new permalinks. 2025-02-12 09:50:52 -08:00