Prechádzať zdrojové kódy

[notebook] Refactor check permission decorator to explicit name (#1306)

Romain 5 rokov pred
rodič
commit
56b448d115

+ 4 - 2
desktop/libs/notebook/src/notebook/conf.py

@@ -39,10 +39,12 @@ SHOW_NOTEBOOKS = Config(
     default=True
 )
 
+
 def _remove_duplications(a_list):
   return list(OrderedDict.fromkeys(a_list))
 
-def check_permissions(user, interpreter, user_apps=None):
+
+def check_has_missing_permission(user, interpreter, user_apps=None):
   # TODO: port to cluster config
   if user_apps is None:
     user_apps = appmanager.get_apps_dict(user)  # Expensive method
@@ -82,7 +84,7 @@ def get_ordered_interpreters(user=None):
     user_apps = appmanager.get_apps_dict(user)
     user_interpreters = []
     for interpreter in interpreters:
-      if check_permissions(user, interpreter, user_apps=user_apps):
+      if check_has_missing_permission(user, interpreter, user_apps=user_apps):
         pass  # Not allowed
       else:
         user_interpreters.append(interpreter)

+ 3 - 3
desktop/libs/notebook/src/notebook/decorators.py

@@ -33,8 +33,8 @@ from desktop.lib.i18n import smart_unicode
 from desktop.lib.rest.http_client import RestException
 from desktop.models import Document2, Document, FilesystemException
 
-from notebook.conf import check_permissions
-from notebook.connectors.base import QueryExpired, QueryError, SessionExpired, AuthenticationRequired, OperationTimeout,\
+from notebook.conf import check_has_missing_permission
+from notebook.connectors.base import QueryExpired, QueryError, SessionExpired, AuthenticationRequired, OperationTimeout, \
   OperationNotSupported
 from notebook.models import _get_editor_type
 
@@ -58,7 +58,7 @@ def check_editor_access_permission():
           except Document2.DoesNotExist:
             raise PopupException(_('Query id %s can not be found, please open a new editor') % editor_id)
 
-        if check_permissions(request.user, editor_type):
+        if check_has_missing_permission(request.user, editor_type):
           raise PopupException(_('Missing permission to access the %s Editor' % editor_type), error_code=401)
 
       return view_func(request, *args, **kwargs)