Commit Graph

51951 Commits

Author SHA1 Message Date
Anders Kaseorg
3325f2ef06 ruff: Fix UP032 Use f-string instead of format call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit bca5564c1e)
2023-08-23 02:28:06 +00:00
Lauryn Menard
920c73a64e markdown-processor: Update insertion_index check for multiple classes.
Updates find_proper_insertion_index to check for the inline image
classes as matching at least one of the classes in the element's
attrib["class"] so that cases where an inline preview image has
multiple classes, like YouTube video previews, will have the
correct insertion index.

Fixes #26186.

(cherry picked from commit d84fd73db4)
2023-08-23 01:47:45 +00:00
Aman Agrawal
9c272d6ca7 portico_signin: Fix back to login button alignment.
(cherry picked from commit eda91378ec)
2023-08-23 01:41:09 +00:00
Alex Vandiver
7482a7e61f middleware: Allow HTTP from localhost, not through a reverse proxy.
In servers with `application_server.http_only = true` and
`loadbalancer.ips` set, the DetectProxyMisconfiguration middleware
prevents access over HTTP from IP addresses other than the
loadbalancer.

However, this misses the case of access from localhost over HTTP,
which is safe and expected -- for instance, the `email-mirror-postfix`
script used in the email gateway[^1] will post to `http://localhost/`
by default in such configurations.  With the
DetectProxyMisconfiguration installed, this will result in a 403
response.

Make an exception for requests from `127.0.0.1` and `::1` from
proxy-misconfiguration rejections.

[^1]: https://zulip.readthedocs.io/en/latest/production/email-gateway.html

(cherry picked from commit 5368d1bd4c)
2023-08-17 15:11:43 -04:00
Daniil Fadeev
4c4ec78a3a emails: Fix the issues with image width overflow.
Images in the follow-up day 2 email were overflowing the main email
layout. To prevent that, we created a separate class to handle this.

(cherry picked from commit 673e98e982)
2023-08-15 17:09:35 +00:00
Daniil Fadeev
62b1652b3a emails: Fix the image source for the follow-up day 2 email.
Copied the image from the `/help` directory to the `/emails` directory
 to use it with the `email_images_base_url` variable.

(cherry picked from commit 20dc70d395)
2023-08-15 17:09:35 +00:00
Alex Vandiver
931d989f53 i18n: Update translation data from Transifex. 2023-08-15 01:14:44 +00:00
Alex Vandiver
dbd0457f6e docs: Fix link to "Uprading PostgreSQL" section.
(cherry picked from commit ae3458a294)
2023-08-14 22:58:31 +00:00
David Rosa
1ae5194619 docs: Update .html links pointing to "Upgrade Zulip" or "Modify Zulip".
Follow-up to #24089.

(cherry picked from commit d205850d54)
2023-08-14 22:06:10 +00:00
Alex Vandiver
4331114329 topic: Set a max batch_size on bulk_upate call.
The number of affected objects may be quite high, and they are
selected by `id IN (...)` query, and updated with a giant `CASE`.
This turns out to be quadratic, and can cause large queries to take
hours, in a state where they cannot be terminated, when PostgreSQL >11
tries to JIT the query.

Set a batch_size as a stopgap performance fix before moving to
`.update()` as a real fix.

(cherry picked from commit 570ff08fde)
2023-08-14 22:02:42 +00:00
Lauryn Menard
f907102842 docs: Add multiple-organizations.md to production section of TOC.
Adds the existing article about hosting multiple Zulip organizations
to the production section of the table of contents.
2023-08-11 11:12:20 -07:00
Anders Kaseorg
1338cc32b4 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 29bdaaf5b5)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
3f265b257a profile_request: Support only synchronous responses for now.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 32a8151ce8)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
a715e6aa33 pyproject: Remove mypy exemption for coverage.
coverage added type annotations in 7.2.0.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit ff6cf54716)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
291cf12c45 name_restrictions: Update disposable_email_domains usage.
‘blocklist’ was added in 0.0.35 (with backwards compatibility for the
old name), and type annotations were added in 0.0.91 (with only the
new name).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 195efb3802)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
948171a839 ruff: Fix B034 re.split, re.sub should pass keyword arguments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit d87eea1a67)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
8fdcadb08a ruff: Fix UP032 Use f-string instead of format call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 50e6cba1af)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
2e9544a9a5 ruff: Fix RUF015 Prefer next(iter(…)) over list(…)[0].
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 0efc662eab)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
a8d6c44db4 openapi: Switch to new openapi_core validation API.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 9bb3d15a79)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
406f9f7852 logging_util: Remove dependence on get_current_request.
Pass the HttpRequest explicitly through the two webhooks that log to
the webhook loggers.

get_current_request is now unused, so remove it (in the same commit
for test coverage reasons).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 63be67af80)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
cc21dc8ec7 sentry: Remove dependence on get_current_request.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit f66e2c3112)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
775d9a889c requirements: Upgrade Python requirements.
(cherry picked from commit 784622ee5d)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
89a3a627be codespell: Correct “requestor” to “requester”.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit c09e7d6407)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
a03ea9dc08 django_api: Extract send_event_on_commit helper.
django-stubs 4.2.1 gives transaction.on_commit a more accurate type
annotation, but this exposed that mypy can’t handle the lambda default
parameters that we use to recapture loop variables such as

    for stream_id in public_stream_ids:
        peer_user_ids = …
        event = …

        transaction.on_commit(
            lambda event=event, peer_user_ids=peer_user_ids: send_event(
                realm, event, peer_user_ids
            )
        )

https://github.com/python/mypy/issues/15459

A workaround that mypy accepts is

        transaction.on_commit(
            (
                lambda event, peer_user_ids: lambda: send_event(
                    realm, event, peer_user_ids
                )
            )(event, peer_user_ids)
        )

But that’s kind of ugly and potentially error-prone, so let’s make a
helper function for this very common pattern.

        send_event_on_commit(realm, event, peer_user_ids)

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 7657cb4a0f)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
252254db69 middleware: Do not consume StreamingHttpResponse.streaming_content.
streaming_content is an iterator. Consuming it within middleware
prevents it from being sent to the browser.

https://docs.djangoproject.com/en/4.2/ref/request-response/#streaminghttpresponse-objects

“The StreamingHttpResponse … has no content attribute. Instead, it has
a streaming_content attribute. This can be used in middleware to wrap
the response iterable, but should not be consumed.”

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 98310f269b)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
8a6ebeda87 tests: Remove assert_streaming_content helper in favor of getvalue.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 92c83c1df4)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
7bb554d58b openapi: Convert deprecated Spec.create to Spec.from_dict.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 85681546ce)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
1a4214a488 ruff: Fix PLC0208 Use a sequence type when iterating over values.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit b7909db987)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
ba2a359e3f ruff: Fix more of RUF010 Use conversion in f-string.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit b907ad0dcb)
2023-08-10 17:01:52 -05:00
Anders Kaseorg
201cab601a test_helpers: Convert TypedDict from queries_captured to dataclass.
An implicit coercion from an untyped dict to the TypedDict was hiding
a type error: CapturedQuery.sql was really str, not bytes.  We should
always prefer dataclass over TypedDict to prevent such errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 92db6eba78)
2023-08-10 17:01:52 -05:00
Alex Vandiver
9628cc9278 retention: Prevent deletion of partially-archived messages.
Previously, this code:
```python3
old_archived_attachments = ArchivedAttachment.objects.annotate(
    has_other_messages=Exists(
        Attachment.objects.filter(id=OuterRef("id"))
        .exclude(messages=None)
        .exclude(scheduled_messages=None)
    )
).filter(messages=None, create_time__lt=delta_weeks_ago, has_other_messages=False)
```

...protected from removal any ArchivedAttachment objects where there
was an Attachment which had _both_ a message _and_ a scheduled
message, instead of _either_ a message _or_ a scheduled message.
Since files are removed from disk when the ArchivedAttachment rows are
deleted, this meant that if an upload was referenced in two messages,
and one was deleted, the file was permanently deleted when the
ArchivedMessage and ArchivedAttachment were cleaned up, despite being
still referenced in live Messages and Attachments.

Switch from `.exclude(messages=None).exclude(scheduled_messages=None)`
to `.exclude(messages=None, scheduled_messages=None)` which "OR"s
those conditions appropriately.

Pull the relevant test into its own file, and expand it significantly
to cover this, and other, corner cases.

(cherry picked from commit b67108c8c6)
2023-08-09 22:41:20 +00:00
Alex Vandiver
97d4f71f0f retention: Do not archive attachments with scheduled messages.
(cherry picked from commit 0f918d9071)
2023-08-09 22:23:17 +00:00
Anders Kaseorg
a8675741a0 error_notify: Remove custom email error reporting handler.
Restore the default django.utils.log.AdminEmailHandler when
ERROR_REPORTING is enabled.  Those with more sophisticated needs can
turn it off and use Sentry or a Sentry-compatible system.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit b285813beb)
2023-07-21 06:55:56 -07:00
Alex Vandiver
290b54a82d upgrade: Check PostgreSQL versions after venv setup.
The claim in the comment from c8ec3dfcf6, that we can and should use
the current deploy's venv, misses one key case -- when upgrading the
operating system, the current deploy's venv is unworkable, since it
was configured for a previous version of Python.  As such, any attempt
to load Django to verify the version of PostgreSQL it is talking to
must happen after the venv is configured.

Move the database version check into
`scripts/lib/check-database-compatibility`, which also moves it after
the new venv is configured.

Because we no longer reliably know, at `apt-get upgrade` time, what
version of PostgreSQL is installed, we hold all versions of the
pgroonga packages.

(cherry picked from commit 1accc6929e)
2023-07-19 18:02:27 -04:00
Akshat
7a448010e2 message_view_header: Fix bad rendering of stream links in description.
This bad rendering was the result of unwanted css applied
in the stream description. In message view header, the stream
link (title) we have defined has css defined but the markdown
rendered stream link in stream description had the same class
resulting in unwanted css applied to it.

Fixes: #25961.

Signed-off-by: Akshat <akshat25iiit@gmail.com>
(cherry picked from commit d302ac4a18)
2023-07-19 18:02:27 -04:00
Alex Vandiver
8f1db3b5c5 export: Skip crossrealm bots, if they are in the exported realm.
This prevents them from being duplicated in the crossrealm users.

(cherry picked from commit 54395612c7)
2023-07-19 18:02:27 -04:00
Alex Vandiver
0e26371c4b import: Merge mirrordummy users _before_ recipients are stripped out.
`remove_denormalized_recipient_column_from_data` removes the
`recipient` data from `zerver_userprofile`, but did not remove it from
`zerver_userprofile_mirrordummy`, which was later appended to the list
of `zerver_userprofile` objects.  This led to failure when inserting,
as the mirrordummy objects still tried to reference their previous
`recipient_id`s.

Move the merging of the two sets earlier, before we call
`remove_denormalized_recipient_column_from_data`.

(cherry picked from commit 207cfe49cf)
2023-07-19 18:02:27 -04:00
Alex Vandiver
fa6f2f1776 export: Include huddles subscription from mirrordummy users.
If there are two huddles, with users A + B + C + D and A + B + C, and
user D is deleted, it is replaced with a mirrordummy user.  If
mirrordummy subscriptions are not included in exports, then the two
huddles have duplicate member sets, and will not be able to be
imported successfully.

Include huddle subscriptions for mirrordummy users in exports.

(cherry picked from commit cfda414277)
2023-07-19 18:02:27 -04:00
Alex Vandiver
56c770987f management: Add a reactivate-stream command.
Fixes #601.

(cherry picked from commit b188e6fa04)
2023-07-19 18:02:27 -04:00
Alex Vandiver
fc472b7b1c puppet: Update dependencies.
(cherry picked from commit 0c44db5325)
2023-07-19 17:34:04 -04:00
Alex Vandiver
eb6d5346fa docs: Mention the PostgreSQL upgrade in the release upgrade section.
Users can, quite understandably, assume that upgrading Zulip upgraded
the underlying PostgreSQL version.  Though it is mentioned at the top
of the page, mentioning it here clarifies that it is an additional
step.

(cherry picked from commit a7b9e67c06)
2023-07-19 17:33:21 -04:00
Alex Vandiver
3349c596d5 release: Release 8.0-prereleases from main.
(cherry picked from commit 23fd05494d)
2023-07-19 17:32:06 -04:00
Alex Vandiver
5a58adf62a release: Link to the changelog in the Github Release.
Release notes in GitHub have significant-newlines, which makes our
canonical `changelog.md` content look not-great -- and the relative
links are also broken, as they have the wrong relative path.

Switch to linking to the canonical release notes on ReadTheDocs, now
that those have proper anchors.

(cherry picked from commit c1008b5b12)
2023-07-19 17:32:06 -04:00
Alex Vandiver
bf68d676c0 changelog: Retitle sections, to allow section anchors.
(cherry picked from commit 9bd340957f)
2023-07-19 17:32:03 -04:00
Alex Vandiver
2dcabec005 docs: Reference PostgreSQL version in "Restoring backups" section.
This extends 8ede54fb1b, in the specific backups section, rather
than just in the overview.

(cherry picked from commit e18d0e3331)
2023-07-19 17:29:46 -04:00
Satyam Bansal
ec46497507 tools: Copy "assets" subdirectory of bots to "static/generated/bots/".
Previously, the "assets" subdirectory of various bots was not
being copied to the "static/generated/bots/" folder, which
resulted in the documentation on some pages not loading at all.

(cherry picked from commit 605e9065a2)
2023-07-19 17:29:14 -04:00
Mateusz Mandera
6c18abddb6 docs: Update SCIM doc to not mention add_scim_client.
add_scim_client was removed in 55342efd33.

(cherry picked from commit 8c530f30e3)
2023-07-19 17:28:22 -04:00
Alex Vandiver
8d9e51a067 docs: Fix a typo in the 7.2 release changelog. 2023-07-05 20:29:34 +00:00
Alex Vandiver
76d1c70f7a version: Update version after 7.2 release. 2023-07-05 20:21:06 +00:00
Alex Vandiver
4174047f64 Release Zulip Server 7.2. 7.2 2023-07-05 19:57:28 +00:00