thumbnails: Add setting THUMBNAIL_IMAGES.

This setting splits away part of responsibility from THUMBOR_URL.
Now on, this setting will be responsible for controlling whether
we thumbnail images or not by asking bugdown to render image links
to hit our /thumbnail endpoint. This is irrespective of what
THUMBOR_URL is set to though ideally THUMBOR_URL should be set
to point to a running thumbor instance.
This commit is contained in:
Aditya Bansal 2019-01-04 20:52:04 +05:30 committed by Tim Abbott
parent 9e9bd2456f
commit 3ee69f3da9
7 changed files with 14 additions and 6 deletions

View File

@ -28,7 +28,7 @@ Thumbor is responsible for a few things in Zulip:
Thumbor handles a lot of details for us, varying from signing of
thumbnailing URLs, to caching for DoS prevention.
It is configured via the `THUMBOR_URL` setting in
It is configured via the `THUMBOR_URL` and `THUMBNAIL_IMAGES` settings in
`/etc/zulip/settings.py`; you can host Thumbor on the same machine as
the Zulip server, or a remote server (which is better for isolation,
since security bugs in image-processing libraries have in the past

View File

@ -35,7 +35,7 @@ from zerver.lib.emoji import translate_emoticons, emoticon_regex
from zerver.lib.mention import possible_mentions, \
possible_user_group_mentions, extract_user_group
from zerver.lib.url_encoding import encode_stream
from zerver.lib.thumbnail import is_thumbor_enabled, user_uploads_or_external
from zerver.lib.thumbnail import user_uploads_or_external
from zerver.lib.timeout import timeout, TimeoutExpired
from zerver.lib.cache import cache_with_key, NotFoundInCache
from zerver.lib.url_preview import preview as link_preview
@ -309,7 +309,7 @@ def add_a(
if data_id is not None:
a.set("data-id", data_id)
img = markdown.util.etree.SubElement(a, "img")
if is_thumbor_enabled() and (not already_thumbnailed) and user_uploads_or_external(url):
if settings.THUMBNAIL_IMAGES and (not already_thumbnailed) and user_uploads_or_external(url):
# See docs/thumbnailing.md for some high-level documentation.
#
# We strip leading '/' from relative URLs here to ensure

View File

@ -379,7 +379,7 @@ class BugdownTest(ZulipTestCase):
msg = 'https://www.google.com/images/srpr/logo4w.png'
thumbnail_img = '<div class="message_inline_image"><a href="https://www.google.com/images/srpr/logo4w.png" target="_blank" title="https://www.google.com/images/srpr/logo4w.png"><img src="https://www.google.com/images/srpr/logo4w.png"></a></div>'
with self.settings(THUMBOR_URL=''):
with self.settings(THUMBNAIL_IMAGES=False):
converted = bugdown_convert(msg)
self.assertIn(thumbnail_img, converted)

View File

@ -120,6 +120,7 @@ if FAKE_LDAP_MODE:
AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipLDAPAuthBackend',) # type: ignore # tuple hackery
THUMBOR_URL = 'http://127.0.0.1:9995'
THUMBNAIL_IMAGES = True
SEARCH_PILLS_ENABLED = os.getenv('SEARCH_PILLS_ENABLED', False)

View File

@ -516,9 +516,14 @@ CAMO_URI = '/external_content/'
# By default, Zulip connects to the thumbor (the thumbnailing software
# we use) service running locally on the machine. If you're running
# thumbor on a different server, you can configure that by setting
# THUMBOR_URL here. Setting THUMBOR_URL='' will disable
# thumbnailing in Zulip.
# THUMBOR_URL here. Setting THUMBOR_URL='' will let Zulip server know that
# thumbor is not running or configured.
#THUMBOR_URL = 'http://127.0.0.1:9995'
#
# This setting controls whether images shown in Zulip's inline image
# previews should be thumbnailed by thumbor, which saves bandwidth but
# can modify the image's appearance.
#THUMBNAIL_IMAGES = True
# Controls the Jitsi video call integration. By default, the
# integration uses the SaaS meet.jit.si server. You can specify

View File

@ -209,6 +209,7 @@ DEFAULT_SETTINGS = {
'REMOTE_POSTGRES_HOST': '',
'REMOTE_POSTGRES_SSLMODE': '',
'THUMBOR_URL': '',
'THUMBNAIL_IMAGES': False,
'SENDFILE_BACKEND': None,
# ToS/Privacy templates

View File

@ -159,6 +159,7 @@ PUSH_NOTIFICATION_BOUNCER_URL = None
SLOW_QUERY_LOGS_STREAM = None
THUMBOR_URL = 'http://127.0.0.1:9995'
THUMBNAIL_IMAGES = True
# Logging the emails while running the tests adds them
# to /emails page.