Bläddra i källkod

HUE-8758 [connector] Auto install example connectors for the Hue admin

Romain 5 år sedan
förälder
incheckning
5e72ac1c30

+ 15 - 4
apps/about/src/about/templates/admin_wizard.mako

@@ -79,7 +79,18 @@ ${ layout.menubar(section='quick_start') }
           <div id="step2" class="stepDetails hide">
             <h3>${ _('Connectors to data services') }</h3>
             % if has_connectors():
-              <a href="${ url('desktop.lib.connectors.views.index') }"><i class="fa fa-exchange"></i> ${ _('Configure') }</a>
+            <ul class="unstyled samples">
+              <li>
+                <a href="${ url('desktop.lib.connectors.views.index') }" title="${ _('Open the connector configuration page') }">
+                  <i class="fa fa-exchange"></i> ${ _('Configuration page') }
+                </a>
+              </li>
+              <li>
+                <a href="${ url('desktop.lib.connectors.views.index') }" title="${ _('Install the connector examples') }">
+                  <i class="fa fa-download"></i> ${ _('Install Examples') }
+                </a>
+              </li>
+            </ul>
             % else:
               <a href="${ url('desktop.views.dump_config') }" target="_blank">${ _('Configuration') }</a>
               <br>
@@ -412,6 +423,6 @@ $(document).ready(function(){
 </script>
 % endif
 
-%if not is_embeddable:
-${ commonfooter(request, messages) | n,unicode }
-%endif
+% if not is_embeddable:
+  ${ commonfooter(request, messages) | n,unicode }
+% endif

+ 35 - 13
desktop/core/src/desktop/lib/connectors/models.py

@@ -85,6 +85,11 @@ else:
 
 
 def _get_installed_connectors(category=None, categories=None, dialect=None, interface=None, user=None):
+  from desktop.auth.backend import is_admin, is_hue_admin
+
+  if not Connector.objects.exists() and user and is_hue_admin(user):
+    _create_connector_examples()
+
   connectors = []
   connector_instances = [
       {
@@ -98,18 +103,6 @@ def _get_installed_connectors(category=None, categories=None, dialect=None, inte
       }
       for connector in Connector.objects.all()
   ]
-  # + [ # TODO move to samples? or auto
-  #     {
-  #       'id': i,
-  #       'nice_name':  CONNECTORS.get()[i].NICE_NAME.get() or i,
-  #       'description': '',
-  #       'dialect': CONNECTORS.get()[i].DIALECT.get(),
-  #       'interface': CONNECTORS.get()[i].INTERFACE.get(),
-  #       'settings': CONNECTORS.get()[i].SETTINGS.get(),
-  #       'is_demo': True,
-  #     }
-  #     for i in CONNECTORS.get()
-  # ]
 
   for connector in connector_instances:
     connector_types = []
@@ -147,8 +140,37 @@ def _get_installed_connectors(category=None, categories=None, dialect=None, inte
     connectors = [connector for connector in connectors if connector['dialect'] == dialect]
   if interface is not None:
     connectors = [connector for connector in connectors if connector['interface'] == interface]
-  if user is not None:
+
+  # Apply Permissions
+  if user is not None and not is_admin(user):
     allowed_connectors = user.get_permissions().values_list('app', flat=True)
     connectors = [connector for connector in connectors if connector['id'] in allowed_connectors]
 
   return connectors
+
+
+def _create_connector_examples():
+  for connector in _get_connector_examples():
+    Connector.objects.create(
+      name=connector['nice_name'],
+      description=connector['description'],
+      dialect=connector['dialect'],
+      settings=json.dumps(connector['settings'])
+    )
+
+  return Connector.objects.all()
+
+
+def _get_connector_examples():
+  return [
+    {
+      'id': i,
+      'nice_name':  CONNECTORS.get()[i].NICE_NAME.get() or i,
+      'description': '',
+      'dialect': CONNECTORS.get()[i].DIALECT.get(),
+      'interface': CONNECTORS.get()[i].INTERFACE.get(),
+      'settings': CONNECTORS.get()[i].SETTINGS.get(),
+      'is_demo': True,
+    }
+    for i in CONNECTORS.get()
+  ]

+ 11 - 9
desktop/core/src/desktop/models.py

@@ -1682,15 +1682,17 @@ class ClusterConfig(object):
 
 
   def get_apps(self):
-    apps = OrderedDict([app for app in [
-      ('editor', self._get_editor()),
-      ('dashboard', self._get_dashboard()),
-      ('catalogs', self._get_catalogs()),
-      ('browser', self._get_browser()),
-      ('scheduler', self._get_scheduler()),
-      ('sdkapps', self._get_sdk_apps()),
-      ('home', self._get_home()),
-    ] if app[1]])
+    apps = OrderedDict([
+      app for app in [
+        ('editor', self._get_editor()),
+        ('dashboard', self._get_dashboard()),
+        ('catalogs', self._get_catalogs()),
+        ('browser', self._get_browser()),
+        ('scheduler', self._get_scheduler()),
+        ('sdkapps', self._get_sdk_apps()),
+        ('home', self._get_home()),
+      ] if app[1]
+    ])
 
     return apps
 

+ 1 - 1
desktop/core/src/desktop/templates/connectors/connectors.mako

@@ -225,7 +225,7 @@ ${ layout.menubar(section='connectors') }
       <div class="span10">
         <div data-bind="dockable: { scrollable: ${ MAIN_SCROLLABLE }, jumpCorrection: 0, topSnap: '${ TOP_SNAP }', triggerAdjust: 0 }">
           <span class="pull-right">
-            <a href="https://gethue.com" target="_blank">
+            <a href="https://docs.gethue.com/administrator/configuration/" target="_blank">
               <i class="fa fa-question-circle"></i> ${ _('Help') }
             </a>
           </span>