url preview: Turn Realm.inline_url_embed_preview off by default.

This commit is contained in:
Puneeth Chaganti 2019-05-31 08:15:02 +05:30 committed by Tim Abbott
parent 4d8ee17a98
commit 8c0c9ca7a4
4 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-31 02:33
from __future__ import unicode_literals
from django.db import migrations, models
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def disable_realm_inline_url_embed_preview(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
realms = Realm.objects.filter(inline_url_embed_preview=True)
realms.update(inline_url_embed_preview=False)
class Migration(migrations.Migration):
dependencies = [
('zerver', '0226_archived_submessage_model'),
]
operations = [
migrations.AlterField(
model_name='realm',
name='inline_url_embed_preview',
field=models.BooleanField(default=False),
),
migrations.RunPython(disable_realm_inline_url_embed_preview,
reverse_code=migrations.RunPython.noop)
]

View File

@ -183,7 +183,7 @@ class Realm(models.Model):
# Whether the organization has enabled inline image and URL previews.
inline_image_preview = models.BooleanField(default=True) # type: bool
inline_url_embed_preview = models.BooleanField(default=True) # type: bool
inline_url_embed_preview = models.BooleanField(default=False) # type: bool
# Whether digest emails are enabled for the organization.
digest_emails_enabled = models.BooleanField(default=False) # type: bool

View File

@ -514,6 +514,8 @@ class BugdownTest(ZulipTestCase):
sender_user_profile = self.example_user('othello')
message = copy.deepcopy(Message(sender=sender_user_profile, sending_client=get_client("test")))
realm = message.get_realm()
realm.inline_url_embed_preview = True # off by default
realm.save(update_fields=['inline_url_embed_preview'])
ret = bugdown.url_embed_preview_enabled()
self.assertEqual(ret, False)

View File

@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, Optional
from requests.exceptions import ConnectionError
from django.test import override_settings
from zerver.models import Message
from zerver.models import Message, Realm
from zerver.lib.actions import queue_json_publish
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import MockPythonResponse
@ -170,6 +170,10 @@ class PreviewTestCase(ZulipTestCase):
</html>
"""
def setUp(self) -> None:
super(PreviewTestCase, self).setUp()
Realm.objects.all().update(inline_url_embed_preview=True)
@classmethod
def create_mock_response(cls, url: str, relative_url: bool=False,
headers: Optional[Dict[str, str]]=None) -> Callable[..., MockPythonResponse]: