zulip/zerver
Mateusz Mandera da4443f392 thumbnail: Make thumbnailing work with data import.
We didn't have thumbnailing for images coming from data import and this
commit adds the functionality.

There are a few fundamental issues that the implementation needs to
solve.

1. The images come from an untrusted source and therefore we don't want
   to just pass them through to thumbnailing without checking. For that
   reason, we cannot just import ImageAttachment rows from the export
   data, even for zulip=>zulip imports.
   The right way to process images is to pass them to maybe_thumbail(),
   which runs libvips_check_image() on them to verify we're okay with
   thumbnailing, creates ImageAttachment rows for them and sends them
   to the thumbnailing queue worker. This approach lets us handle both
   zulip=>zulip and 3rd party=>zulip imports in the same way,

2. There is a somewhat circular dependency between the Message,
   Attachment and ImageAttachment import process:

- ImageAttachments would ideally be created after importing
  Attachments, but they need to already exist at the time of Message
  import. Otherwise, the markdown processor doesn't know it has to add
  HTML for image previews to messages that reference images. This would
  mean that messages imported from 3rd party tools don't get image
  previews.
- Attachments only get created after Message import however, due to the
  many-to-many relationship between Message and Attachment.

This is solved by fixing up some data of Attachments pre-emptively, such
as the path_ids. This gives us the necessary information for creating
ImageAttachments before importing Messages.

While we generate ImageAttachment rows synchronously, the actual
thumbnailing job is sent to the queue worker. Theoretically, the worker
could be very backlogged and not process the thumbnails anytime soon.
This is fine - if the app is loaded and tries to display a message with
such a not-yet-generated thumbnail, the code in `serve_file` will
generate the thumbnails synchronously on the fly and the user will see
the image preview displayed normally. See:

1b47134d0d/zerver/views/upload.py (L333-L342)
2024-10-24 10:32:51 -07:00
..
actions update_user_backend: Allow authorized org owners to change user emails. 2024-10-22 16:36:38 -07:00
data_import rocketchat: Validate custom emoji before larger data sets. 2024-10-17 12:25:18 -07:00
integration_fixtures/nagios
lib thumbnail: Make thumbnailing work with data import. 2024-10-24 10:32:51 -07:00
management update_user_backend: Allow authorized org owners to change user emails. 2024-10-22 16:36:38 -07:00
migrations update_user_backend: Allow authorized org owners to change user emails. 2024-10-22 16:36:38 -07:00
models update_user_backend: Allow authorized org owners to change user emails. 2024-10-22 16:36:38 -07:00
openapi users: Add API endpoint to update_user_backend by real email. 2024-10-22 16:36:38 -07:00
tests thumbnail: Make thumbnailing work with data import. 2024-10-24 10:32:51 -07:00
tornado django_api: Rename 'send_event' to 'send_event_rollback_unsafe'. 2024-09-20 15:20:18 -07:00
transaction_tests user_groups: Add add_can_members_group to user group. 2024-10-11 16:31:18 -07:00
views users: Add API endpoint to update_user_backend by real email. 2024-10-22 16:36:38 -07:00
webhooks docs: Update existing links to use "channel" operator. 2024-10-11 17:00:23 -07:00
worker worker: Address sentry_sdk deprecations. 2024-10-22 10:05:01 -07:00
__init__.py
apps.py ruff: Fix UP007 Use `X | Y` for type annotations. 2024-07-13 22:28:22 -07:00
context_processors.py ruff: Fix UP035 Import from `collections.abc`, `typing` instead. 2024-07-13 22:28:22 -07:00
decorator.py upload: Use tusd for resumable, larger uploads. 2024-09-19 11:37:29 -07:00
filters.py ruff: Fix UP007 Use `X | Y` for type annotations. 2024-07-13 22:28:22 -07:00
forms.py auth: Fix invalid credentials message in login form. 2024-10-24 08:23:16 -07:00
logging_handlers.py ruff: Fix UP007 Use `X | Y` for type annotations. 2024-07-13 22:28:22 -07:00
middleware.py ruff: Fix UP035 Import from `collections.abc`, `typing` instead. 2024-07-13 22:28:22 -07:00
signals.py ruff: Bump target-version from py38 to py310. 2024-07-13 22:28:22 -07:00