Преглед изворни кода

[core] Hide configuration tabs application to non-superusers

Romain Rigaux пре 12 година
родитељ
комит
bbed14dc21

+ 16 - 13
apps/about/src/about/templates/index.mako

@@ -17,21 +17,24 @@
 from desktop.views import commonheader, commonfooter
 from desktop.views import commonheader, commonfooter
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
 %>
 %>
+
 ${ commonheader(_('About Hue'), "about", user, "100px") | n,unicode }
 ${ commonheader(_('About Hue'), "about", user, "100px") | n,unicode }
 
 
-	<div class="subnav subnav-fixed">
-		<div class="container-fluid">
-		<ul class="nav nav-pills">
-			<li><a href="${url("desktop.views.dump_config")}">${_('Configuration')}</a></li>
-			<li><a href="${url("desktop.views.check_config")}">${_('Check for misconfiguration')}</a></li>
-			<li><a href="${url("desktop.views.log_view")}">${_('Server Logs')}</a></li>
-		</ul>
-		</div>
-	</div>
+% if user.is_superuser:
+<div class="subnav subnav-fixed">
+  <div class="container-fluid">
+    <ul class="nav nav-pills">
+      <li><a href="${url("desktop.views.dump_config")}">${_('Configuration')}</a></li>
+      <li><a href="${url("desktop.views.check_config")}">${_('Check for misconfiguration')}</a></li>
+      <li><a href="${url("desktop.views.log_view")}">${_('Server Logs')}</a></li>
+    </ul>
+  </div>
+</div>
+% endif
 
 
-	<div class="container-fluid">
-		<img src="/static/art/hue-login-logo.png" />
-		<p>Hue ${version}</p>
-	</div>
+<div class="container-fluid">
+  <img src="/static/art/hue-login-logo.png" />
+  <p>Hue ${version}</p>
+</div>
 
 
 ${ commonfooter(messages) | n,unicode }
 ${ commonfooter(messages) | n,unicode }

+ 19 - 8
desktop/core/src/desktop/tests.py

@@ -15,25 +15,29 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
-from desktop.lib import django_mako
+
+import desktop
+import desktop.urls
+import desktop.conf
+import logging
+import time
+
+import desktop.views as views
+import proxy.conf
 
 
 from nose.tools import assert_true, assert_equal, assert_not_equal
 from nose.tools import assert_true, assert_equal, assert_not_equal
 from django.conf.urls.defaults import patterns, url
 from django.conf.urls.defaults import patterns, url
 from django.core.urlresolvers import reverse
 from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.http import HttpResponse
 from django.db.models import query, CharField, SmallIntegerField
 from django.db.models import query, CharField, SmallIntegerField
+
+from desktop.lib import django_mako
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.paginator import Paginator
 from desktop.lib.paginator import Paginator
 from desktop.lib.conf import validate_path
 from desktop.lib.conf import validate_path
-import desktop
-import desktop.urls
-import desktop.conf
-import logging
-import time
 from desktop.lib.django_util import TruncatingModel
 from desktop.lib.django_util import TruncatingModel
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
-import desktop.views as views
-import proxy.conf
+from desktop.lib.test_utils import grant_access
 
 
 
 
 def setup_test_environment():
 def setup_test_environment():
@@ -126,6 +130,13 @@ def test_dump_config():
 
 
   clear()
   clear()
 
 
+  # Login as someone else
+  client_not_me = make_logged_in_client(username='not_me', is_superuser=False, groupname='test')
+  grant_access("not_me", "test", "desktop")
+
+  response = client_not_me.get('/dump_config')
+  assert_equal("You must be a superuser.", response.content)
+
 
 
 def test_prefs():
 def test_prefs():
   c = make_logged_in_client()
   c = make_logged_in_client()

+ 6 - 0
desktop/core/src/desktop/views.py

@@ -49,6 +49,9 @@ def log_view(request):
   If it is attached to the root logger, this view will display that history,
   If it is attached to the root logger, this view will display that history,
   otherwise it will report that it can't be found.
   otherwise it will report that it can't be found.
   """
   """
+  if not request.user.is_superuser:
+    return HttpResponse(_("You must be a superuser."))
+
   l = logging.getLogger()
   l = logging.getLogger()
   for h in l.handlers:
   for h in l.handlers:
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):
@@ -61,6 +64,9 @@ def download_log_view(request):
   """
   """
   Zip up the log buffer and then return as a file attachment.
   Zip up the log buffer and then return as a file attachment.
   """
   """
+  if not request.user.is_superuser:
+    return HttpResponse(_("You must be a superuser."))
+
   l = logging.getLogger()
   l = logging.getLogger()
   for h in l.handlers:
   for h in l.handlers:
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):
     if isinstance(h, desktop.log.log_buffer.FixedBufferHandler):