mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	open graph: Display realm description as open graph description.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							a653fcca93
						
					
				
				
					commit
					2d9c5b3575
				
			@@ -17,7 +17,7 @@ from zerver.decorator import get_client_name
 | 
			
		||||
from zerver.lib.send_email import FromAddress
 | 
			
		||||
from zerver.lib.subdomains import get_subdomain
 | 
			
		||||
from zerver.lib.realm_icon import get_realm_icon_url
 | 
			
		||||
from zerver.lib.realm_description import get_realm_rendered_description
 | 
			
		||||
from zerver.lib.realm_description import get_realm_rendered_description, get_realm_text_description
 | 
			
		||||
 | 
			
		||||
from version import ZULIP_VERSION, LATEST_RELEASE_VERSION, LATEST_MAJOR_VERSION, \
 | 
			
		||||
    LATEST_RELEASE_ANNOUNCEMENT
 | 
			
		||||
@@ -154,6 +154,10 @@ def login_context(request: HttpRequest) -> Dict[str, Any]:
 | 
			
		||||
        'two_factor_authentication_enabled': settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
 | 
			
		||||
    }  # type: Dict[str, Any]
 | 
			
		||||
 | 
			
		||||
    if realm is not None and realm.description:
 | 
			
		||||
        context['OPEN_GRAPH_TITLE'] = realm.name
 | 
			
		||||
        context['OPEN_GRAPH_DESCRIPTION'] = get_realm_text_description(realm)
 | 
			
		||||
 | 
			
		||||
    # Add the keys for our standard authentication backends.
 | 
			
		||||
    no_auth_enabled = True
 | 
			
		||||
    social_backends = []
 | 
			
		||||
 
 | 
			
		||||
@@ -446,6 +446,9 @@ def realm_alert_words_automaton_cache_key(realm: 'Realm') -> str:
 | 
			
		||||
def realm_rendered_description_cache_key(realm: 'Realm') -> str:
 | 
			
		||||
    return "realm_rendered_description:%s" % (realm.string_id,)
 | 
			
		||||
 | 
			
		||||
def realm_text_description_cache_key(realm: 'Realm') -> str:
 | 
			
		||||
    return "realm_text_description:%s" % (realm.string_id,)
 | 
			
		||||
 | 
			
		||||
# Called by models.py to flush the stream cache whenever we save a stream
 | 
			
		||||
# object.
 | 
			
		||||
def flush_stream(sender: Any, **kwargs: Any) -> None:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,16 @@
 | 
			
		||||
from zerver.models import Realm
 | 
			
		||||
from zerver.lib.cache import cache_with_key, realm_rendered_description_cache_key
 | 
			
		||||
from zerver.lib.cache import cache_with_key, realm_rendered_description_cache_key, \
 | 
			
		||||
    realm_text_description_cache_key
 | 
			
		||||
from zerver.lib.bugdown import convert as bugdown_convert
 | 
			
		||||
from zerver.lib.html_to_text import html_to_text
 | 
			
		||||
 | 
			
		||||
@cache_with_key(realm_rendered_description_cache_key, timeout=3600*24*7)
 | 
			
		||||
def get_realm_rendered_description(realm: Realm) -> str:
 | 
			
		||||
    realm_description_raw = realm.description or "The coolest place in the universe."
 | 
			
		||||
    return bugdown_convert(realm_description_raw, message_realm=realm,
 | 
			
		||||
                           no_previews=True)
 | 
			
		||||
 | 
			
		||||
@cache_with_key(realm_text_description_cache_key, timeout=3600*24*7)
 | 
			
		||||
def get_realm_text_description(realm: Realm) -> str:
 | 
			
		||||
    html_description = get_realm_rendered_description(realm)
 | 
			
		||||
    return html_to_text(html_description)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,7 @@ from bs4 import BeautifulSoup
 | 
			
		||||
from django.test import override_settings
 | 
			
		||||
from unittest.mock import Mock, patch
 | 
			
		||||
from zerver.lib.test_classes import ZulipTestCase
 | 
			
		||||
from zerver.middleware import is_slow_query
 | 
			
		||||
from zerver.middleware import write_log_line
 | 
			
		||||
from zerver.middleware import is_slow_query, write_log_line
 | 
			
		||||
 | 
			
		||||
class SlowQueryTest(ZulipTestCase):
 | 
			
		||||
    SLOW_QUERY_TIME = 10
 | 
			
		||||
@@ -139,3 +138,13 @@ class OpenGraphTest(ZulipTestCase):
 | 
			
		||||
            [],
 | 
			
		||||
            # Test that our open graph logic doesn't throw a 500
 | 
			
		||||
            404)
 | 
			
		||||
 | 
			
		||||
    def test_login_page_simple_description(self) -> None:
 | 
			
		||||
        name = 'Zulip Dev'
 | 
			
		||||
        description = "The Zulip development environment default organization. It's great for testing!"
 | 
			
		||||
 | 
			
		||||
        self.check_title_and_description(
 | 
			
		||||
            '/login/',
 | 
			
		||||
            name,
 | 
			
		||||
            [description],
 | 
			
		||||
            [])
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user