Browse Source

HUE-8530 [organization] Hide ini location when user not a Hue admin

Romain 5 năm trước cách đây
mục cha
commit
ca258d9418

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

@@ -187,11 +187,13 @@ ${ layout.menubar(section='quick_start') }
             <div class="margin-top-30">
               <h3>${ _('Anonymous usage analytics') }</h3>
               <label class="checkbox">
-                <input class="updatePreferences" type="checkbox" name="collect_usage" style="margin-right: 10px" title="${ _('Check to enable usage analytics') }" ${ collect_usage and 'checked' or '' }/>
+                <input class="updatePreferences" type="checkbox" name="collect_usage" style="margin-right: 10px"
+                  title="${ _('Check to enable usage analytics') }" ${ collect_usage and 'checked' or '' }/>
                 ${ _('Help improve Hue with anonymous usage analytics.') }
-                <a href="javascript:void(0)" style="display: inline" data-trigger="hover" data-toggle="popover" data-placement="right" rel="popover"
-                   title="${ _('How does it work?') }"
-                   data-content="${ _('We are using Google Analytics to see how many times an application or specific section of an application is used, nothing more.') }">
+                <a href="javascript:void(0)" style="display: inline" data-trigger="hover" data-toggle="popover"
+                  data-placement="right" rel="popover"
+                  title="${ _('How does it work?') }"
+                  data-content="${ _('Hue is using Google Analytics to see how many times an application or specific section of an application is used, nothing more.') }">
                    <i class="fa fa-question-circle"></i>
                 </a>
               </label>

+ 8 - 0
desktop/core/src/desktop/auth/backend.py

@@ -110,6 +110,12 @@ def is_admin(user):
   """
   Admin of the Organization. Typically can edit users, connectors.
   To rename to is_org_admin at some point.
+
+  If ENABLE_ORGANIZATIONS is false:
+    - Hue superusers are automaticall also admin
+
+  If ENABLE_ORGANIZATIONS is true:
+    - Hue superusers might not be admin of the organization
   """
   is_admin = False
   if hasattr(user, 'is_superuser') and not ENABLE_ORGANIZATIONS.get():
@@ -127,6 +133,8 @@ def is_admin(user):
 def is_hue_admin(user):
   """
   Hue service super user. Can manage global settings of the services used by all the organization.
+
+  Independent of ENABLE_ORGANIZATIONS.
   """
   return hasattr(user, 'is_superuser') and user.is_superuser
 

+ 12 - 1
desktop/core/src/desktop/auth/decorators.py

@@ -22,7 +22,8 @@ import logging
 from django.utils.functional import wraps
 from django.utils.translation import ugettext as _
 
-from desktop.auth.backend import is_admin
+from desktop.auth.backend import is_admin, is_hue_admin
+from desktop.conf import ENABLE_ORGANIZATIONS
 from desktop.lib.exceptions_renderable import PopupException
 
 
@@ -37,3 +38,13 @@ def admin_required(f):
 
     return f(request, *args, **kwargs)
   return wrapper
+
+
+def hue_admin_required(f):
+  @wraps(f)
+  def wrapper(request, *args, **kwargs):
+    if not is_hue_admin(request.user):
+      raise PopupException(_("You must be a Hue admin."), error_code=401)
+
+    return f(request, *args, **kwargs)
+  return wrapper

+ 17 - 5
desktop/core/src/desktop/auth/decorators_tests.py

@@ -21,7 +21,7 @@ import unittest
 
 from nose.tools import assert_equal, assert_true, assert_false, assert_raises
 
-from desktop.auth.decorators import admin_required
+from desktop.auth.decorators import admin_required, hue_admin_required
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.exceptions_renderable import PopupException
 
@@ -42,14 +42,26 @@ class TestDecorator(unittest.TestCase):
     cls.client2 = make_logged_in_client(username='joe', recreate=True, is_superuser=False)
 
 
-  def test_user_group(self):
+  def test_admin_required(self):
     request = Mock(user=User.objects.get(username='admin'))
-    hello(request)
+    hello_admin(request)
 
     request = Mock(user=User.objects.get(username='joe'))
-    assert_raises(PopupException, hello, request)
+    assert_raises(PopupException, hello_admin, request)
 
 
+  def test_hue_admin_required(self):
+    request = Mock(user=User.objects.get(username='admin'))
+    hello_hue_admin(request)
+
+    request = Mock(user=User.objects.get(username='joe'))
+    assert_raises(PopupException, hello_hue_admin, request)
+
+
+@admin_required
+def hello_admin(request, *args, **kwargs):
+  return 'Hello'
+
 @admin_required
-def hello(request, *args, **kwargs):
+def hello_hue_admin(request, *args, **kwargs):
   return 'Hello'

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

@@ -18,10 +18,10 @@
 from django.utils.translation import ugettext as _
 
 from desktop.conf import has_connectors
-from desktop.auth.backend import is_admin
+from desktop.auth.backend import is_hue_admin
 %>
 
-% if is_admin(user):
+% if is_hue_admin(user):
   ${ _('Configuration files located in') } <code style="color: #0B7FAD">${ conf_dir }</code>
 % endif