From 58dccb1cdf436f84827e20c40c96296a3778621d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 14 Dec 2015 18:58:00 +0100 Subject: Adapt menus and urls for right management - check_rights_condition for filtering wizard steps --- ishtar_common/wizards.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ishtar_common/wizards.py') diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index cc6107928..23469c659 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -21,7 +21,6 @@ import datetime # from functools import wraps from django.conf import settings -from django.contrib.formtools.wizard.storage import get_storage from django.contrib.formtools.wizard.views import NamedUrlWizardView, \ normalize_name, get_storage, StepsHelper from django.contrib.sites.models import Site @@ -77,6 +76,23 @@ def check_rights(rights=[], redirect_url='/'): return decorator +def check_rights_condition(rights): + """ + To be used to check in wizard condition_dict + """ + def func(self): + request = self.request + if request.user.ishtaruser.has_right('administrator', request.session): + return True + for right in rights: + print(right) + if request.user.ishtaruser.has_right(right, request.session): + return True + print('hop') + return False + return func + + class Wizard(NamedUrlWizardView): model = None label = '' @@ -126,7 +142,8 @@ class Wizard(NamedUrlWizardView): self.request = request self.session = request.session self.prefix = self.get_prefix(*args, **kwargs) - self.storage = get_storage(self.storage_name, self.prefix, request, + self.storage = get_storage( + self.storage_name, self.prefix, request, getattr(self, 'file_storage', None)) self.steps = StepsHelper(self) -- cgit v1.2.3