summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/menus.py9
-rw-r--r--ishtar_common/tests.py43
-rw-r--r--ishtar_common/urls.py2
3 files changed, 45 insertions, 9 deletions
diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py
index 74ef714eb..6d51323ab 100644
--- a/ishtar_common/menus.py
+++ b/ishtar_common/menus.py
@@ -21,6 +21,7 @@
Menus
"""
+from copy import deepcopy
import datetime
from django.conf import settings
@@ -55,7 +56,7 @@ for section_item in __section_items:
class Menu:
- childs = _section_items
+ ref_childs = _section_items
def __init__(self, user, current_action=None, session=None):
self.user = user
@@ -129,10 +130,10 @@ class Menu:
self.set_menu_updated_key(cache_key, user_id)
self.items = {}
self.items_by_idx = {}
- childs = self.childs[:]
- for idx, main_menu in enumerate(reversed(self.childs)):
+ childs = deepcopy(self.ref_childs)
+ for idx, main_menu in enumerate(reversed(childs)):
if not main_menu.can_be_available(self.user, self.session):
- childs.pop(len(self.childs) - idx - 1)
+ childs.pop(len(self.ref_childs) - idx - 1)
continue
self.items_by_idx[main_menu.idx] = main_menu
sub_childs = main_menu.childs[:]
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 8d85e3cba..defc3a0c3 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -376,7 +376,12 @@ class WizardTest(object):
class CacheTest(TestCase):
- def testAdd(self):
+ fixtures = [settings.ROOT_PATH +
+ '../fixtures/initial_data-auth-fr.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data-fr.json',]
+
+ def test_add(self):
models.OrganizationType.refresh_cache()
cached = models.OrganizationType.get_cache('test')
self.assertEqual(cached, None)
@@ -389,7 +394,7 @@ class CacheTest(TestCase):
cached = models.OrganizationType.get_cache('testy')
self.assertEqual(cached.pk, orga.pk)
- def testList(self):
+ def test_list(self):
models.OrganizationType.refresh_cache()
types = models.OrganizationType.get_types()
# only empty
@@ -404,6 +409,36 @@ class CacheTest(TestCase):
unicode(lbl) for idx, lbl in models.OrganizationType.get_types()]
self.assertFalse('testy' in types)
+ def test_menu_cache(self):
+ admin_username = 'username4277'
+ admin_password = 'dcbqj756456!@%'
+ User.objects.create_superuser(admin_username, "nomail@nomail.com",
+ admin_password)
+ readonly_user = 'username4456'
+ readonly_password = 'xshqu744456!@%'
+ user = User.objects.create_user(readonly_user, "nomail@nomail.com",
+ readonly_password)
+ ishtuser = models.IshtarUser.objects.get(user_ptr=user)
+ models.UserProfile.objects.get_or_create(
+ current=True, person=ishtuser.person,
+ profile_type=models.ProfileType.objects.get(
+ txt_idx='reader_access'))
+
+ c = Client()
+ c.login(username=admin_username, password=admin_password)
+ response = c.get("/operation_search/general-operation_search")
+ self.assertIn('href="/operation_modification/', response.content)
+
+ # the cache menu must be updated...
+ c2 = Client()
+ c2.login(username=readonly_user, password=readonly_password)
+ response = c2.get("/operation_search/general-operation_search")
+ self.assertNotIn('href="/operation_modification/', response.content)
+
+ # ... only on a session basis
+ response = c.get("/operation_search/general-operation_search")
+ self.assertIn('href="/operation_modification/', response.content)
+
class AccessControlTest(TestCase):
def test_administrator(self):
@@ -1339,7 +1374,7 @@ class IshtarSiteProfileTest(TestCase):
self.assertTrue(profile)
self.assertEqual(models.IshtarSiteProfile.objects.count(), 1)
- def testMenuFiltering(self):
+ def test_menu_filtering(self):
cache.set('default-ishtarsiteprofile-is-current-profile', None,
settings.CACHE_TIMEOUT)
username = 'username4277'
@@ -1349,7 +1384,7 @@ class IshtarSiteProfileTest(TestCase):
c = Client()
c.login(username=username, password=password)
response = c.get(reverse('start'))
- self.assertFalse("section-file_management" in response.content)
+ self.assertNotIn('href="/file_search/"', response.content)
profile = models.get_current_profile()
profile.files = True
profile.save()
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index f9f342ce3..4ba551857 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -129,7 +129,7 @@ urlpatterns = [
menu = Menu(None)
menu.init()
actions = []
-for section in menu.childs:
+for section in menu.ref_childs:
for menu_item in section.childs:
if hasattr(menu_item, 'childs'):
for menu_subitem in menu_item.childs: