Ver Fonte

HUE-8530 [organization] Prepare split of is_admin and is_hue_admin

Romain há 5 anos atrás
pai
commit
0f8656875a

+ 1 - 0
apps/useradmin/src/useradmin/models2.py

@@ -94,6 +94,7 @@ if ENABLE_ORGANIZATIONS.get():
         verbose_name=_t('permissions'),
         blank=True,
     )
+    # Could also have a set of Roles at some point.
 
     objects = OrganizationGroupManager()
 

+ 13 - 5
desktop/core/src/desktop/auth/backend.py

@@ -107,20 +107,28 @@ def rewrite_user(user):
 
 
 def is_admin(user):
+  """
+  Admin of the Organization. Typically can edit users, connectors.
+  To rename to is_org_admin at some point.
+  """
   is_admin = False
-  if hasattr(user, 'is_superuser'):
+  if hasattr(user, 'is_superuser') and not ENABLE_ORGANIZATIONS.get():
     is_admin = user.is_superuser
-  if not is_admin and user.is_authenticated() and not ENABLE_ORGANIZATIONS.get():  # Admin group not activated in organization mode.
+  if not is_admin and user.is_authenticated():
     try:
       user = rewrite_user(user)
-      is_admin = user.has_hue_permission(action="superuser", app="useradmin")
+        # Either via flag or Admin group
+      is_admin = user.is_admin if ENABLE_ORGANIZATIONS.get() else user.has_hue_permission(action="superuser", app="useradmin")
     except Exception:
       LOG.exception("Could not validate if %s is a superuser, assuming False." % user)
   return is_admin
 
 
-def is_org_admin(user):
-  return hasattr(user, 'is_admin') and user.is_admin
+def is_hue_admin(user):
+  """
+  Hue service super user. Can manage global settings of the services used by all the organization.
+  """
+  return hasattr(user, 'is_superuser') and user.is_superuser
 
 
 class DefaultUserAugmentor(object):

+ 1 - 1
desktop/core/src/desktop/js/ko/components/ko.sidebar.js

@@ -281,7 +281,7 @@ class Sidebar {
       );
     }
 
-    if (window.USER_IS_ADMIN || window.USER_IS_ORG_ADMIN) {
+    if (window.USER_IS_ADMIN || window.USER_IS_HUE_ADMIN) {
       userChildren.push(
         new SidebarItem({ url: '/useradmin/users/', displayName: I18n('Manage Users') })
       );

+ 3 - 3
desktop/core/src/desktop/templates/about_layout.mako

@@ -17,7 +17,7 @@
 <%!
 from django.utils.translation import ugettext as _
 
-from desktop.auth.backend import is_admin, is_org_admin
+from desktop.auth.backend import is_admin, is_hue_admin
 from desktop.conf import METRICS, has_connectors, ANALYTICS
 
 def is_selected(section, matcher):
@@ -39,7 +39,7 @@ def is_selected(section, matcher):
                   ${ _('About Hue') }
                 </a>
               </li>
-              % if is_admin(user) or is_org_admin(user):
+              % if is_admin(user) or is_hue_admin(user):
                 <li class="${is_selected(section, 'quick_start')}">
                   <a href="${ url('about:admin_wizard') }">${_('Quick start')}</a>
                 </li>
@@ -49,7 +49,7 @@ def is_selected(section, matcher):
                   <a href="${ url('desktop.views.dump_config') }">${_('Configuration')}</a>
                 </li>
               % endif
-              % if has_connectors() and (is_admin(user) or is_org_admin(user)):
+              % if has_connectors() and (is_admin(user) or is_hue_admin(user)):
                 <li class="${is_selected(section, 'connectors')}">
                   <a href="${ url('desktop.lib.connectors.views.index') }">${_('Connectors')}</a>
                 </li>

+ 2 - 2
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -18,7 +18,7 @@
   from django.utils.translation import ugettext as _
 
   from desktop import conf
-  from desktop.auth.backend import is_admin, is_org_admin
+  from desktop.auth.backend import is_admin, is_hue_admin
   from desktop.conf import APP_SWITCHER_ALTUS_BASE_URL, APP_SWITCHER_MOW_BASE_URL, CUSTOM_DASHBOARD_URL, \
       DISPLAY_APP_SWITCHER, IS_K8S_ONLY, IS_MULTICLUSTER_ONLY, USE_DEFAULT_CONFIGURATION, USE_NEW_SIDE_PANELS, \
       VCS, ENABLE_GIST, ENABLE_LINK_SHARING
@@ -642,7 +642,7 @@
 
   window.USER_VIEW_EDIT_USER_ENABLED = '${ user.has_hue_permission(action="access_view:useradmin:edit_user", app="useradmin") or is_admin(user) }' === 'True';
   window.USER_IS_ADMIN = '${ is_admin(user) }' === 'True';
-  window.USER_IS_ORG_ADMIN = '${ is_org_admin(user) }' === 'True';
+  window.USER_IS_HUE_ADMIN = '${ is_hue_admin(user) }' === 'True';
   window.DJANGO_DEBUG_MODE = '${ conf.DJANGO_DEBUG_MODE.get() }' === 'True';
   window.IS_LDAP_SETUP = '${ 'desktop.auth.backend.LdapBackend' in conf.AUTH.BACKEND.get() }' === 'True';
   window.LOGGED_USERNAME = '${ user.username }';