Selaa lähdekoodia

HUE-8758 [connectors] Ordered intrepreter is not valid anymore with connectors

Romain 6 vuotta sitten
vanhempi
commit
3ea767b31b

+ 0 - 2
desktop/libs/notebook/src/notebook/api.py

@@ -39,9 +39,7 @@ from indexer.file_format import HiveFormat
 from indexer.fields import Field
 
 from notebook.connectors.base import Notebook, QueryExpired, SessionExpired, QueryError, _get_snippet_name
-from notebook.connectors.dataeng import DataEngApi
 from notebook.connectors.hiveserver2 import HS2Api
-from notebook.connectors.oozie_batch import OozieApi
 from notebook.decorators import api_error_handler, check_document_access_permission, check_document_modify_permission
 from notebook.models import escape_rows, make_notebook, upgrade_session_properties, get_api
 

+ 23 - 21
desktop/libs/notebook/src/notebook/conf.py

@@ -47,27 +47,9 @@ def check_permissions(user, interpreter, user_apps=None):
 
 
 def get_ordered_interpreters(user=None):
-  if not INTERPRETERS.get():
-    _default_interpreters(user)
-
-  interpreters = INTERPRETERS.get()
-  interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())
-
-  user_apps = appmanager.get_apps_dict(user)
-  user_interpreters = []
-  for interpreter in interpreters:
-    if check_permissions(user, interpreter, user_apps=user_apps):
-      pass # Not allowed
-    else:
-      user_interpreters.append(interpreter)
-
-  unknown_interpreters = set(interpreters_shown_on_wheel) - set(user_interpreters)
-  if unknown_interpreters:
-    raise ValueError("Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s" % unknown_interpreters)
-
   if has_connectors():
     from desktop.lib.connectors.api import _get_installed_connectors
-    reordered_interpreters = [{
+    interpreters = [{
         'name': connector['nice_name'],
         'type': connector['name'],
         'dialect': connector['dialect'],
@@ -77,9 +59,29 @@ def get_ordered_interpreters(user=None):
         'options': {setting['name']: setting['value'] for setting in connector['settings']}
       } for connector in _get_installed_connectors(categories=['editor', 'catalogs'])
     ]
+    # No connector permission currently
   else:
+    if not INTERPRETERS.get():
+      _default_interpreters(user)
+    interpreters = INTERPRETERS.get()
+
+    user_apps = appmanager.get_apps_dict(user)
+    user_interpreters = []
+    for interpreter in interpreters:
+      if check_permissions(user, interpreter, user_apps=user_apps):
+        pass # Not allowed
+      else:
+        user_interpreters.append(interpreter)
+
+    interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())
+    unknown_interpreters = set(interpreters_shown_on_wheel) - set(user_interpreters)
+    if unknown_interpreters:
+      # Just filtering it out might be better than failing for this user
+      raise ValueError("Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s" % unknown_interpreters)
+
     reordered_interpreters = interpreters_shown_on_wheel + [i for i in user_interpreters if i not in interpreters_shown_on_wheel]
-    reordered_interpreters = [{
+
+    interpreters = [{
         'name': interpreters[i].NAME.get(),
         'type': i,
         'interface': interpreters[i].INTERFACE.get(),
@@ -97,7 +99,7 @@ def get_ordered_interpreters(user=None):
       "is_sql": i.get('is_sql') or i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy"],
       "is_catalog": i['interface'] in ["hms",],
     }
-    for i in reordered_interpreters
+    for i in interpreters
   ]
 
 # cf. admin wizard too

+ 1 - 0
desktop/libs/notebook/src/notebook/tasks.py

@@ -154,6 +154,7 @@ def run_sync_query(doc_id, user):
   if type(user) is str:
     lookup = {'email' if ENABLE_ORGANIZATIONS.get() else 'username': user}
     user = User.objects.get(**lookup)
+    user = rewrite_user(user)
 
   query_document = Document2.objects.get_by_uuid(user=user, uuid=doc_id)
   notebook = Notebook(document=query_document).get_data()