Hide apps and sys icons if user is not an admin

This commit is contained in:
Rahul De 2017-03-23 16:14:52 +05:30 committed by Sunil Mohan Adapa
parent 018324a6fc
commit 3248c2573d
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 10 additions and 2 deletions

View File

@ -23,6 +23,7 @@ from django.utils.translation import ugettext as _, ugettext_noop
import re
from plinth import cfg
from plinth.utils import is_user_admin
def common(request):
@ -41,5 +42,6 @@ def common(request):
'cfg': cfg,
'submenu': cfg.main_menu.active_item(request),
'active_menu_urls': active_menu_urls,
'box_name': _(cfg.box_name)
'box_name': _(cfg.box_name),
'user_is_admin': is_user_admin(request.user)
}

View File

@ -96,7 +96,7 @@
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
{% if user.is_authenticated %}
{% if user.is_authenticated and user_is_admin %}
<li>
<a href="{% url 'index' %}" title="{% trans "Home" %}">
{% trans "Home" %}

View File

@ -18,7 +18,9 @@
"""
Test module for Plinth's custom context processors.
"""
from unittest.mock import Mock
from django.contrib.auth.models import User
from django.http import HttpRequest
from django.test import TestCase
@ -35,6 +37,8 @@ class ContextProcessorsTestCase(TestCase):
request = HttpRequest()
request.path = '/aaa/bbb/ccc/'
request.user = Mock()
request.user.groups.filter().exists = Mock(return_value=True)
response = cp.common(request)
self.assertIsNotNone(response)
@ -55,6 +59,8 @@ class ContextProcessorsTestCase(TestCase):
"""Verify that the common() function works for border conditions."""
request = HttpRequest()
request.path = ''
request.user = Mock()
request.user.groups.filter().exists = Mock(return_value=True)
response = cp.common(request)
self.assertEqual([], response['active_menu_urls'])