From fe8f5bb2e3d9366b212d368e16ef010e85079ba6 Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 15 Mar 2016 18:26:03 +0100 Subject: [PATCH] Fix club rights --- club/models.py | 4 +--- club/views.py | 2 +- core/models.py | 4 ++++ core/views/__init__.py | 3 --- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/club/models.py b/club/models.py index 839d9094..0447d992 100644 --- a/club/models.py +++ b/club/models.py @@ -58,7 +58,7 @@ class Club(models.Model): """ Method to see if that object can be super edited by the given user """ - if user.groups.filter(name=settings.AE_GROUPS['board']['name']).exists(): + if user.is_in_group(settings.AE_GROUPS['board']['name']): return True return False @@ -117,5 +117,3 @@ class Membership(models.Model): def get_absolute_url(self): return reverse('club:club_members', kwargs={'club_id': self.club.id}) - - diff --git a/club/views.py b/club/views.py index b59e7d5c..0a944b10 100644 --- a/club/views.py +++ b/club/views.py @@ -42,7 +42,7 @@ class ClubMemberForm(forms.ModelForm): """ ret = super(ClubMemberForm, self).clean() ms = self.instance.club.get_membership_for(self._user) - if ms is not None and ms.role >= self.cleaned_data['role']: + if (ms is not None and ms.role >= self.cleaned_data['role']) or self._user.is_superuser: return ret raise ValidationError("You do not have the permission to do that") diff --git a/core/models.py b/core/models.py index 387e4022..96681eff 100644 --- a/core/models.py +++ b/core/models.py @@ -96,6 +96,10 @@ class User(AbstractBaseUser, PermissionsMixin): def to_dict(self): return self.__dict__ + def is_in_group(self, group_name): + """If the user is in the group passed in argument (as string)""" + return self.groups.filter(name=group_name).exists() + def get_profile(self): return { "last_name": self.last_name, diff --git a/core/views/__init__.py b/core/views/__init__.py index 20552eb8..ff19e750 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -72,9 +72,6 @@ class CanViewMixin(View): """ def dispatch(self, request, *arg, **kwargs): res = super(CanViewMixin, self).dispatch(request, *arg, **kwargs) - import traceback - traceback.print_stack(limit=10) - print(self.__dict__) if hasattr(self, 'object'): obj = self.object elif hasattr(self, 'object_list'):