Forráskód Böngészése

HUE-8758 [connector] Check admin permission for connector updates

Romain 5 éve
szülő
commit
02ca81558c

+ 3 - 2
desktop/core/src/desktop/lib/connectors/api.py

@@ -22,6 +22,7 @@ from django.utils.translation import ugettext as _
 
 from useradmin.models import update_app_permissions
 
+from desktop.auth.decorators import admin_required
 from desktop.lib.django_util import JsonResponse, render
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.connectors.models import _get_installed_connectors, get_connectors_types, Connector
@@ -69,7 +70,7 @@ def get_connector(request, id):
   })
 
 
-# TODO: check if has perm
+@admin_required
 def update_connector(request):
   connector = json.loads(request.POST.get('connector', '{}'))
   saved_as = False
@@ -96,7 +97,7 @@ def update_connector(request):
   return JsonResponse({'connector': connector, 'saved_as': saved_as})
 
 
-# TODO: check if has perm
+@admin_required
 def delete_connector(request):
   connector = json.loads(request.POST.get('connector', '{}'))
 

+ 7 - 2
desktop/core/src/desktop/lib/connectors/tests.py

@@ -52,6 +52,12 @@ class TestConnectors(object):
 
     assert_equal(200, response.status_code)
 
+  def test_create_connector_perm(self):
+    response = self.client.post("/desktop/connectors/api/instance/update/")
+    assert_equal(401, response.status_code)
+
+    response = self.client.post("/desktop/connectors/api/instance/delete/")
+    assert_equal(401, response.status_code)
 
 
 class TestConnectorListing(unittest.TestCase):
@@ -92,7 +98,6 @@ class TestConnectorListing(unittest.TestCase):
     update_app_permissions()
 
 
-  @patch('desktop.lib.connectors.models.CONNECTOR_INSTANCES', None)
   def test_get_installed_editor_connectors(self):
 
     with patch('desktop.lib.connectors.models.CONNECTORS.get') as CONNECTORS:
@@ -111,7 +116,7 @@ class TestConnectorListing(unittest.TestCase):
       assert_true(editor_category, connectors)
       assert_equal(1, len(editor_category), editor_category)
 
-  @patch('desktop.lib.connectors.models.CONNECTOR_INSTANCES', None)
+
   def test_get_connectors_for_user(self):
 
     with patch('desktop.lib.connectors.models.CONNECTORS.get') as CONNECTORS:

+ 6 - 7
desktop/core/src/desktop/middleware.py

@@ -314,13 +314,12 @@ class LoginAndPermissionMiddleware(object):
 
       app_accessed = request._desktop_app
       app_libs_whitelist = ("desktop", "home", "home2", "about", "hue", "editor", "notebook", "indexer", "404", "500", "403")
-      if not ENABLE_CONNECTORS.get():
-        # Accessing an app can access an underlying other app.
-        # e.g. impala or spark uses code from beeswax and so accessing impala shows up as beeswax here.
-        # Here we trust the URL to be the real app we need to check the perms.
-        ui_app_accessed = get_app_name(request)
-        if app_accessed != ui_app_accessed and ui_app_accessed not in ('logs', 'accounts', 'login'):
-          app_accessed = ui_app_accessed
+      # Accessing an app can access an underlying other app.
+      # e.g. impala or spark uses code from beeswax and so accessing impala shows up as beeswax here.
+      # Here we trust the URL to be the real app we need to check the perms.
+      ui_app_accessed = get_app_name(request)
+      if app_accessed != ui_app_accessed and ui_app_accessed not in ('logs', 'accounts', 'login'):
+        app_accessed = ui_app_accessed
 
       if app_accessed and \
           app_accessed not in app_libs_whitelist and \