Browse Source

HUE-9185 [api] Enable gist and link sharing

Romain 5 years ago
parent
commit
71560acdb2

+ 2 - 2
desktop/conf.dist/hue.ini

@@ -297,14 +297,14 @@
   ## enable_prometheus=false
 
   # Turn on the Gist snippet sharing.
-  ## enable_gist=false
+  ## enable_gist=true
 
   # Add public description so that the link can be unfurled in a preview by websites like Slack.
   # Only enabled automatically in private setups.
   ## enable_gist_preview=true
 
   # Turn on the direct link sharing of saved document.
-  ## enable_link_sharing=false
+  ## enable_link_sharing=true
 
   # Administrators
   # ----------------

+ 2 - 2
desktop/conf/pseudo-distributed.ini.tmpl

@@ -301,14 +301,14 @@
   ## enable_prometheus=false
 
   # Turn on the Gist snippet sharing.
-  ## enable_gist=false
+  ## enable_gist=true
 
   # Add public description so that the link can be unfurled in a preview by websites like Slack.
   # Only enabled automatically in private setups.
   ## enable_gist_preview=true
 
   # Turn on the direct link sharing of saved document.
-  ## enable_link_sharing=false
+  ## enable_link_sharing=true
 
   # Administrators
   # ----------------

+ 2 - 1
desktop/core/src/desktop/api2.py

@@ -941,6 +941,7 @@ def gist_create(request):
 
 
 @login_notrequired
+@api_error_handler
 def gist_get(request):
   gist_uuid = request.GET.get('uuid')
 
@@ -952,7 +953,7 @@ def gist_get(request):
       'unfurl_link.mako',
       request, {
         'title': _('SQL gist from %s') % (gist_doc.owner.get_full_name() or gist_doc.owner.username),
-        'description': statement if len(statement) < 30 else (statement[:70] + '...'),
+        'description': statement if len(statement) < 150 else (statement[:150] + '...'),
         'image_link': None
       }
     )

+ 19 - 13
desktop/core/src/desktop/api2_tests.py

@@ -621,6 +621,7 @@ class TestDocumentGist(object):
   def _get_gist(self, uuid, client=None, is_crawler_bot=False):
     if client is None:
       client = self.client
+
     if is_crawler_bot:
       headers = {'HTTP_USER_AGENT': 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)'}
     else:
@@ -684,21 +685,26 @@ class TestDocumentGist(object):
 
   def test_get_unfurl(self):
     # Unfurling on
-    response = self._create_gist(
-        statement='SELECT 1',
-        doc_type='hive-query',
-        name='test_gist_get',
-    )
-    gist = json.loads(response.content)
+    f = ENABLE_GIST_PREVIEW.set_for_testing(True)
 
-    response = self._get_gist(
-      uuid=gist['uuid'],
-      is_crawler_bot=True
-    )
+    try:
+      response = self._create_gist(
+          statement='SELECT 1',
+          doc_type='hive-query',
+          name='test_gist_get',
+      )
+      gist = json.loads(response.content)
+
+      response = self._get_gist(
+        uuid=gist['uuid'],
+        is_crawler_bot=True
+      )
 
-    assert_equal(200, response.status_code)
-    assert_true(b'<meta name="twitter:card" content="summary">' in response.content, response.content)
-    assert_true(b'<meta property="og:description" content="SELECT 1"/>' in response.content, response.content)
+      assert_equal(200, response.status_code)
+      assert_true(b'<meta name="twitter:card" content="summary">' in response.content, response.content)
+      assert_true(b'<meta property="og:description" content="SELECT 1"/>' in response.content, response.content)
+    finally:
+      f()
 
     # Unfurling off
     f = ENABLE_GIST_PREVIEW.set_for_testing(False)

+ 2 - 2
desktop/core/src/desktop/conf.py

@@ -1875,7 +1875,7 @@ CLUSTERS = UnspecifiedConfigSection(
 
 ENABLE_GIST = Config(
   key='enable_gist',
-  default=False,
+  default=True,
   type=coerce_bool,
   help=_('Turn on the Gist snippet sharing.')
 )
@@ -1893,7 +1893,7 @@ ENABLE_GIST_PREVIEW = Config(
 
 ENABLE_LINK_SHARING = Config(
   key='enable_link_sharing',
-  default=False,
+  default=True,
   type=coerce_bool,
   help=_('Turn on the direct link sharing of saved document.')
 )