From c196a645cb791dc92582da92b0c98e9f93c80810 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 2 Jul 2017 23:52:43 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9e=20les=20droits=20si=20ils=20n'existen?= =?UTF-8?q?t=20pas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/users/models.py b/users/models.py index 1c3a9f30..0235ef5b 100644 --- a/users/models.py +++ b/users/models.py @@ -221,15 +221,20 @@ class User(AbstractBaseUser): def has_right(self, right): - return Right.objects.filter(user=self).filter(right=ListRight.objects.get(listright=right)).exists() + try: + list_right = ListRight.objects.get(listright=right) + except: + list_right = ListRight(listright=right, gid=get_fresh_gid()) + list_right.save() + return Right.objects.filter(user=self).filter(right=list_right).exists() @cached_property def is_bureau(self): - return Right.objects.filter(user=self).filter(right=ListRight.objects.get(listright='bureau')).exists() + return self.has_right('bureau') @cached_property def is_bofh(self): - return Right.objects.filter(user=self).filter(right=ListRight.objects.get(listright='bofh')).exists() + return self.has_right('bofh') @cached_property def is_cableur(self): @@ -237,11 +242,11 @@ class User(AbstractBaseUser): @cached_property def is_trez(self): - return Right.objects.filter(user=self).filter(right=ListRight.objects.get(listright='trésorier')).exists() + return self.has_right('trésorier') @cached_property def is_infra(self): - return Right.objects.filter(user=self).filter(right=ListRight.objects.get(listright='infra')).exists() + return self.has_right('infra') @cached_property def end_adhesion(self):