Commit Graph

18730 Commits

Author SHA1 Message Date
Anders Kaseorg 27b0618704 data_import: Fix IdMapper typing.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-17 15:56:00 -07:00
Anders Kaseorg 1fd3f983a5 data_import: Remove int detection from IdMapper.
This seems to have been used only for HipChat.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-17 15:56:00 -07:00
Alex Vandiver ab6b6639e6 migrations: Derive emoji content-type from the bytes. 2024-07-17 11:39:04 -07:00
Sahil Batra cf14d8f611 users: Change bot owner only if needed.
This is a small optimization to avoid DB queries if the bot owner
is not changed.

This also helps in avoiding showing the error message in UI if
anything other than the owner is updated for a deactivated bot.
Ideally if the bot owner is not changed, the bot_owner_id field
should not be passed in the request, but we would handle that
later given this is anyways a small nice optimization and we
follow this pattern at other places as well in the API.
2024-07-17 10:07:51 -07:00
Lauryn Menard b9c33ce5f1 api-docs: Add changes section in construct a narrow article.
Adds a header to the section of changes notes about new and
deprecated narrow filters, so that it's easier to directly
link to the relevant content in the construct a narrow article
from the main API changelog and endpoint documentation.
2024-07-16 23:40:45 -07:00
Vector73 7a80fcf042 events: Send `delete_message` event to user who deleted the message.
Fixes #29826.

Co-authored-by: Mukul Goyal <goyal.mukul7689@gmail.com>
Co-authored-by: Aman Agrawal <amanagr@zulip.com>
2024-07-16 23:29:02 -07:00
Niloth P 56aa72af90 integration-docs: Update Trello for new doc format.
Part of zulip#29592.
2024-07-16 17:02:55 -07:00
Niloth P c8781b4de7 integration-docs: Update TeamCity for new doc format.
Part of zulip#29592.
2024-07-16 17:02:55 -07:00
Alex Vandiver 9983dc761f migrations: Further fix emoji re-thumbnailing.
90701978d9 was an incomplete fix.
2024-07-16 15:38:22 -07:00
Niloth P f663544353 integration-docs: Update Slack incoming-webhook for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Niloth P 32177a9a1c integration-docs: Update Sonarqube for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Niloth P a546fa719a integration-docs: Update Sonarr for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Niloth P 1ddf92a98c integration-docs: Update Splunk for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Niloth P 8549a6dc8a integration-docs: Update Statuspage for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Niloth P c0ab89ec52 integration-docs: Update Stripe for new doc format.
Part of zulip#29592.
2024-07-16 14:55:56 -07:00
Alex Vandiver e8a049ea57 migrations: Handle missing emoji/images/still/ directory. 2024-07-16 14:55:45 -07:00
Niloth P a17a54b077 integration-docs: Update Zabbix for new doc format.
Part of zulip#29592.
2024-07-16 14:55:27 -07:00
Niloth P c271cdb113 integration-docs: Update WordPress for new doc format.
Part of zulip#29592.

Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-07-16 14:55:02 -07:00
Lauryn Menard 3e100d872a integrations: Remove HookPress events from WordPress webhook.
The HookPress plugin has been unavailable since July 2019, so it
doesn't make sense to continue supporting these events in the
WordPress webhook integration.
2024-07-16 14:55:02 -07:00
Niloth P 1e327cc054 integration-docs: Update Wekan for new doc format.
Part of zulip#29592.
2024-07-16 14:55:02 -07:00
Anders Kaseorg dd0d482d76 narrow: Migrate legacy SQLAlchemy select syntax.
Fixes “sqlalchemy.exc.RemovedIn20Warning: Deprecated API features
detected! These feature(s) are not compatible with SQLAlchemy 2.0.”
with warnings enabled.

https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#change-5284

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-16 14:50:30 -07:00
Sahil Batra a0efc0ee76 settings: Refetch realm and user profile objects.
This is a temporary solution to make sure stale objects from
cache are not used when previous request updated multiple settings.
2024-07-16 14:04:19 -07:00
Sahil Batra 83c4c27b18 settings: Do not allow invalid combinations for information density settings. 2024-07-16 14:04:19 -07:00
Sahil Batra 17541ddacb settings: Toggle dense mode if font and line height values are changed. 2024-07-16 14:04:19 -07:00
Anders Kaseorg ad9837911e runtornado: Remove explicit AsyncIOMainLoop installation.
Tornado ≥ 5 uses AsyncIOLoop and AsyncIOMainLoop automatically when
appropriate.  Fixes “DeprecationWarning: make_current is deprecated;
start the event loop first” with warnings enabled.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-16 14:01:32 -07:00
Prakhar Pratyush df7ed437c2 compose: Show banner to explain interleaved view messages fading.
In an interleaved view when composing a message we fade messages
which the user is not replying to, to reduce the chance they send
a message to a recipient they didn't intend to.
Also, it reduces the visual/cognitive processing required
to figure out where their message is going to go.

But, it's not necessarily clear to users that what the
fading means, so this commit adds a one-time compose banner
to explain what's going on the first time this comes up.

Fixes part of #29076.
2024-07-16 13:52:30 -07:00
Prakhar Pratyush 35380b095f compose: Show banner to explain non interleaved view messages fading.
In a non interleaved view when composing a message to another
conversation we fade messages which the user is not replying to,
to reduce the chance they send a message to a recipient they didn't
intend to. Also, it reduces the visual/cognitive processing required
to figure out where their message is going to go.

But, it's not necessarily clear to users that what the
fading means, so this commit adds a one-time compose banner
to explain what's going on the first time this comes up.

Fixes part of #29076.
2024-07-16 13:52:29 -07:00
Alex Vandiver 556b92810b thumbnail: Advertize the thumbnail formats at client registration. 2024-07-16 13:22:15 -07:00
Alex Vandiver 6c624805ce upload: Return the closest-rendered thumbnail. 2024-07-16 13:22:15 -07:00
Alex Vandiver d121a80b78 upload: Serve thumbnailed images. 2024-07-16 13:22:15 -07:00
Alex Vandiver 2e38f426f4 upload: Generate thumbnails when images are uploaded.
A new table is created to track which path_id attachments are images,
and for those their metadata, and which thumbnails have been created.
Using path_id as the effective primary key lets us ignore if the
attachment is archived or not, saving some foreign key messes.

A new worker is added to observe events when rows are added to this
table, and to generate and store thumbnails for those images in
differing sizes and formats.
2024-07-16 13:22:15 -07:00
Alex Vandiver 7aa5bb233d tests: Clarify tests in test_thumbnail.py. 2024-07-16 13:22:15 -07:00
Alex Vandiver 63dbf67120 tests: Ensure we start with a local storage backend. 2024-07-16 13:22:15 -07:00
Alex Vandiver 229dcd0218 upload: Clean up empty directories in local storage. 2024-07-16 13:22:15 -07:00
Alex Vandiver 5f25fae0fa upload: Batch deleting old attachments.
delete_message_attachments() is faster than calling
delete_message_attachment() one-by-one.
2024-07-16 13:22:15 -07:00
Anders Kaseorg 8843f9f62a tests: Remove deprecated SHA1PasswordHasher.
SHA1PasswordHasher will be removed in Django 5.1.  MD5PasswordHasher
will remain for the purpose of speeding up tests.

Followup to commit ac5161f439 (#29620).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-16 13:06:31 -07:00
Alex Vandiver 90701978d9 migrations: Fix emoji re-thumbnailing for imports.
Imports (including conversions from Slack, Hipchat, etc) do not write
the `.original` of the file (nor the still versions, for animations),
only the thumbnailed (and possibly animated) version.  Looking for
`.original` would thus fail, and overwrite the (working) emoji with
the "?" and disable it.

In the event that we do not find the `.original`, fall back to the
bytes from the non-`.original`, to handle these import cases.
2024-07-16 12:57:49 -07:00
Alex Vandiver 1745d87f2e migrations: Add enough information to logs to reverse bad emoji "fixes." 2024-07-16 12:57:49 -07:00
Niloth P 6afed1432c integration-docs: Update Travis CI for new doc format.
Part of zulip#29592.
2024-07-16 09:40:45 -07:00
Niloth P 5db83f87e2 integration-docs: Update Transifex for new doc format.
Part of zulip#29592.
2024-07-16 09:40:45 -07:00
Niloth P 1f4310f893 integration-docs: Update Thinkst for new doc format.
Part of zulip#29592.
2024-07-16 09:40:45 -07:00
Niloth P 0f7b1ba401 integration-docs: Update Taiga for new doc format.
Part of zulip#29592.
2024-07-16 09:40:45 -07:00
Prakhar Pratyush 0de9f7f5cf import_realm: Add support to import 'OnboardingUserMessage' table. 2024-07-16 09:36:02 -07:00
Prakhar Pratyush 762b1c0f5b import_realm: Improve assert statements verifying table name.
This commit improves the assert statements to verify
that the table name is not "usermessage' instead of
verifying that table name doesn't include a substring
"usermessage".

This prep commit will help to avoid assertion error when
importing "onboardingusermessage" table.
2024-07-16 09:36:02 -07:00
Prakhar Pratyush 7d379e00b0 export: Fix 'OnboardingUserMessage' table not being exported.
Earlier, the export tool was logging a warning:
"??? NO DATA EXPORTED FOR TABLE zerver_onboardingusermessage!!!"

This bug was due to not configuring a Config object for
'OnboardingUserMessage' in 'get_realm_config()'.

This commit fixes the bug to export the table properly.
2024-07-16 09:36:02 -07:00
Kenneth Rodrigues 246df3c884 realm: Migrate smaller files to typed_endpoint.
Migrate `realm_domains.py`, `realm_emoji.py`,
`realm_linkifiers.py`, `realm_logo.py`, `realm_playgrounds.py`
to typed_endpoint.
2024-07-15 16:49:32 -07:00
Kenneth Rodrigues ba79d759f1 realm: Migrate to typed_endpoint. 2024-07-15 16:49:32 -07:00
Kenneth Rodrigues a7da24a36f validators: Use cleaner syntax for AfterValidator.
Created a function that returns an `AfterValidator` for `check_int_in`
and `check_string_in` instead of having to use a
`lambda` wraper everytime.
2024-07-15 16:49:32 -07:00
Niloth P 0ec4b0285e integration-docs: Update Zendesk for new doc format.
Part of zulip #29592.

Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-07-15 16:42:22 -07:00
Niloth P 2c2f530fe0 integration-docs: Update Zapier for new doc format.
Part of zulip #29592.

Co-authored-by: Lauryn Menard <lauryn@zulip.com>
2024-07-15 16:42:22 -07:00
Mateusz Mandera d89ab2694f register_server: Call crudini with --inplace when rotating secret key.
This is needed for the command to work in docker-zulip, where the zulip
user may not have write permissions to the parent directory of the
secrets file. By default, crudini creates a temporary file, which makes
the command fail under those conditions.
With --inplace, the secret file gets written to directly without
creation of temporary files.
2024-07-15 13:24:14 -07:00
Vector73 d21ee6fa23 api: Deprecate uri and add url parameter in "/user_uploads" endpoint. 2024-07-14 22:32:36 -07:00
Vector73 a07ebba860 zerver: Replace uri with url in local variables and comments. 2024-07-14 22:30:28 -07:00
Anders Kaseorg fe71eaa8f0 ruff: Fix FURB148 `enumerate` index or value is unused.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:54:32 -07:00
Anders Kaseorg 80d3e60df8 ruff: Fix FURB180 Use of `metaclass=abc.ABCMeta`.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:53:40 -07:00
Anders Kaseorg e3a191b99b ruff: Fix FURB154 Use of repeated consecutive `global`, `nonlocal`.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:53:18 -07:00
Anders Kaseorg 6412c2d630 ruff: Fix FURB142 Use of set.add() in a for loop.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:52:59 -07:00
Anders Kaseorg 1e9b6445a9 ruff: Fix PLR6104 Use `+=` to perform an augmented assignment directly.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:49:51 -07:00
Anders Kaseorg b96feb34f6 ruff: Fix SIM117 Use a single `with` statement with multiple contexts.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-14 13:48:32 -07:00
Tim Abbott b0f144327d narrow: Update new function for modern Python typing syntax.
I apparently needed to be more careful rebasing the typing syntax
modernization work.
2024-07-13 23:06:47 -07:00
Anders Kaseorg 48202389b8 ruff: Bump target-version from py38 to py310.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg 3f29bc42b1 ruff: Fix B905 `zip()` without an explicit `strict=` parameter.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg 1464009fae ruff: Fix UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg 0fa5e7f629 ruff: Fix UP035 Import from `collections.abc`, `typing` instead.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg 531b34cb4c ruff: Fix UP007 Use `X | Y` for type annotations.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg e08a24e47f ruff: Fix UP006 Use `list` instead of `List` for type annotation.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg c2214b3904 test_typed_endpoint: Inline pointless type variable.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg f04e7fc625 test_openapi: Make get_standardized_argument_type understand X | Y.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Anders Kaseorg a2fad74a28 typed_endpoint: Make is_optional understand T | None.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-07-13 22:28:22 -07:00
Aman Agrawal 70be9e8c51 narrow: Implement rendering of `with` narrow operators.
Adds server and web app support for processing the new `with`
search operator.

Fixes part of #21505.

Co-authored-by: roanster007 <rohan.gudimetla07@gmail.com>
Co-authored-by: Tim Abbott <tabbott@zulip.com>
2024-07-13 07:18:24 -07:00
bedo bfd54e27b1 custom_profile_fields: Bulk fetch of UserProfile.
bulk fetch query of UserPfrofile against which
user_ids are validated, instead of looping
over user_ids and fetchingeach UserPfrofile resulting
in O(n) queries.
2024-07-13 07:05:13 -07:00
Alya Abbott bd04a30bbc updates: Add update message (level=6). 2024-07-12 16:40:41 -07:00
Alex Vandiver 4df9b03451 migrations: Re-thumbnail and rename existing emoji. 2024-07-12 13:26:47 -07:00
Alex Vandiver 0385e5bab9 emoji: Store in S3 with a long public cache-control. 2024-07-12 13:26:47 -07:00
Alex Vandiver 0442e95276 emoji: Use a non-predictable filename.
We use a truncated SHA256 of the id and a server-side secret to make
emoji have non-guessable filenames, while also making collisions
unlikely.

We also adjust the Slack import to use the same SHA-based name,
instead of taking the same name as it had in Slack.
2024-07-12 13:26:47 -07:00
Alex Vandiver 262689da76 thumbnail: Fix MAX_EMOJI_GIF_FILE_SIZE_BYTES check to be post-resize.
This check was intended to check the post-resized image size, not the
pre-resized image.
2024-07-12 13:26:47 -07:00
Alex Vandiver 544d3df057 thumbnail: Stop applying MAX_EMOJI_GIF_FILE_SIZE_BYTES before resizing.
b14a33c659 attempted to make the 128k limit apply _after_ resizing,
but left this check, which examines the pre-resized image size.
2024-07-12 13:26:47 -07:00
Alex Vandiver 54f2fabac0 thumbnail: Still emoji are always pngs. 2024-07-12 13:26:47 -07:00
Alex Vandiver 6110ac7339 emoji: Use a transaction, rather than create and delete-on-fail. 2024-07-12 13:26:47 -07:00
Alex Vandiver 2b3da0e70f fixup! thumbnail: Fix MAX_EMOJI_GIF_FILE_SIZE_BYTES check to be post-resize. 2024-07-12 13:26:47 -07:00
Alex Vandiver f6b99171ce emoji: Derive the file extension from a limited set of content-types.
We thumbnail and serve emoji with the same format as they were
uploaded.  However, we preserved the original extension, which might
mismatch with the provided content-type.

Limit the content-type to a subset which is both (a) an image format
we can thumbnail, and (b) a media format which is widely-enough
supported that we are willing to provide it to all browsers.  This
prevents uploading a `.tiff` emoji, for instance.

Based on this limited content-type, we then reverse to find the
reasonable extension to use when storing it.  This is particularly
important because the local file storage uses the file extension to
choose what content-type to re-serve the emoji as.

This does nothing for existing emoji, which may have odd or missing
file extensions.
2024-07-12 13:26:47 -07:00
Alex Vandiver 62a0611ddb emoji: Pass down content-type, rather than guessing from extension. 2024-07-12 13:26:47 -07:00
Alex Vandiver f3473defe1 transfer: Log when local emoji files are missing. 2024-07-12 13:26:47 -07:00
Alex Vandiver fa28e3aa0f tests: Split up test_upload.EmojiTest into test_thumbnail. 2024-07-12 13:26:47 -07:00
PieterCK f5a834c2d6 integration-docs: Update Jotform for new doc format.
Part of #29592.
2024-07-12 13:21:07 -07:00
PieterCK e034a715cb integration-docs: Update JSON formatter for new doc format.
Part of #29592.
2024-07-12 13:21:07 -07:00
PieterCK ecbbf53c0e integration-docs: Update Greenhouse recruitment for new doc format.
Part of #29592.
2024-07-12 13:21:07 -07:00
PieterCK 0e967e4633 integration-docs: Update Harbor for new doc format.
Aside from updating the doc structure, this commit
also rephrases step 4 to make it read better. The
list of supported events in step 5 is also removed.

Part of #29592.
2024-07-12 13:21:07 -07:00
Sahil Batra ffb7744974 settings: Allow settings to be set to system groups only in production.
We use the already existing server level setting to only allow
settings to be set to system groups, not a named user defined
group as well, in production. But we allow to settings to be set
to any named or anonymous user group in tests and development server.

"can_mention_group" setting can be set to user defined groups
because some of the realms already do that in production.

The existing server level setting is also renamed to make it clear
that both user defined groups and anonymous groups are not allowed
if that setting is set to False.

This commit also changes the error message to be consistent for the
case when a setting cannot be set to user defined groups as per
server level and setting and when a particular setting cannot be set
to user defined groups due to the configuration of that particular
setting. For this we add a new class SystemGroupRequiredError in
exceptions.py so that we need not re-write the error message in
multiple places.
2024-07-12 09:51:49 -07:00
Niklas Fiekas af3a2500df
email_mirror: Also strip "AW:" from subject.
Besides "RE:" and "FWD:", "AW:" (from German "Antwort" for answer) is
another common prefix in email subjects. Let email_mirror automatically
remove it as well.
2024-07-11 11:16:24 -07:00
Alex Vandiver d5a4941691 django: Switch to .alias() instead .annotate() where possible.
When using the sub-expression purely for filtering, and not for
accessing the value in the resultset, .alias() is potentially faster
since it does not pull the value in as well.
2024-07-11 09:26:23 -07:00
Alex Vandiver e1a9473bd6 thumbnail: Log and revert to gravatar on migration failure.
This is preferable to leaving the user with a broken avatar image.
2024-07-11 07:31:39 -07:00
Alex Vandiver 536cf0abc8 thumbnail: Be slightly more specific about our exception catches. 2024-07-11 07:31:39 -07:00
Alex Vandiver b53a33a5bc thumbnail: Properly re-derive Content-Disposition for original uploads. 2024-07-11 07:31:39 -07:00
Alex Vandiver 1f9925b1e3 thumbnail: Skip avatars which have already been migrated. 2024-07-11 07:31:39 -07:00
Alex Vandiver a4981c13f7 thumbnail: Skip avatars whose old versions are missing. 2024-07-11 07:31:39 -07:00
Alex Vandiver 4d3d3efcf1 thumbnail: Newly-thumbnailed avatars are all image/png. 2024-07-11 07:31:39 -07:00
Alex Vandiver a9d1adadb7 thumbnail: Add or move progress earlier in loop.
This makes the counts correct and consistent.
2024-07-11 07:31:39 -07:00
Alex Vandiver 382cb5bb13 thumbnail: Lock down which formats we parse. 2024-07-11 07:31:39 -07:00
Alex Vandiver 4bc563128e thumbnail: Use a consistent set of supported image types. 2024-07-11 07:31:39 -07:00