summaryrefslogtreecommitdiff
path: root/ishtar/ishtar_base/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-10-11 20:40:01 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-10-11 20:40:01 +0200
commit1970ab3e774d912a73ffd343e506156ba34772b2 (patch)
tree5b6673e61cd00871718cc6e1d4859d75b7433484 /ishtar/ishtar_base/forms.py
parent968d59a2de5918353df998fcd90283da76a18f95 (diff)
downloadIshtar-1970ab3e774d912a73ffd343e506156ba34772b2.tar.bz2
Ishtar-1970ab3e774d912a73ffd343e506156ba34772b2.zip
More precise right managements (closes #644)
- wizard filtered with right managements - better admin for rights related to person types
Diffstat (limited to 'ishtar/ishtar_base/forms.py')
-rw-r--r--ishtar/ishtar_base/forms.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/ishtar/ishtar_base/forms.py b/ishtar/ishtar_base/forms.py
index 608e54739..d947b43ae 100644
--- a/ishtar/ishtar_base/forms.py
+++ b/ishtar/ishtar_base/forms.py
@@ -107,6 +107,32 @@ class Wizard(NamedUrlSessionFormWizard):
model = None
modification = None # True when the wizard modify an item
+ @staticmethod
+ def _check_right(step, condition=True):
+ '''Return a method to check the right for a specific step'''
+ def check_right(self, request, storage):
+ cond = condition
+ if callable(condition):
+ cond = condition(self, request, storage)
+ if not cond:
+ return False
+ person_type = request.user.ishtaruser.person.person_type
+ if person_type.txt_idx == 'administrator':
+ return True
+ if person_type.rights.filter(url_name=step).count():
+ return True
+ return check_right
+
+ def __init__(self, *args, **kwargs):
+ """Check right for each step of the wizard"""
+ super(Wizard, self).__init__(*args, **kwargs)
+ for form_key in self.form_list.keys()[:-1]:
+ condition = True
+ if form_key in self.condition_list:
+ condition = self.condition_list.get(form_key, True)
+ cond = self._check_right(form_key, condition)
+ self.condition_list[form_key] = cond
+
def get_wizard_name(self):
"""As the class name can interfere when reused, use the url_name"""
return self.url_name