From 7d7652e319942d657314408379914069c7430e1c Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 24 Mar 2016 11:55:39 +0100 Subject: [PATCH] Small fix (le gaulois) --- club/views.py | 7 +++++-- core/management/commands/populate.py | 6 ++++++ core/views/__init__.py | 1 - sith/settings.py | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/club/views.py b/club/views.py index 1a5c1da8..5cfd7c3f 100644 --- a/club/views.py +++ b/club/views.py @@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin from club.models import Club, Membership -from sith.settings import AE_GROUPS +from sith.settings import AE_GROUPS, MAXIMUM_FREE_ROLE class ClubListView(CanViewMixin, ListView): """ @@ -42,7 +42,10 @@ 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']) or self._user.is_in_group(AE_GROUPS['board']['name']) or self._user.is_superuser: + if (self.cleaned_data['role'] <= MAXIMUM_FREE_ROLE or + (ms is not None and ms.role >= self.cleaned_data['role']) or + self._user.is_in_group(AE_GROUPS['board']['name']) or + self._user.is_superuser): return ret raise ValidationError("You do not have the permission to do that") diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index c29748f5..c3132de4 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -47,6 +47,8 @@ Welcome to the wiki page! date_of_birth="1942-06-12") s.set_password("plop") s.save() + s.view_groups=[settings.AE_GROUPS['members']['id']] + s.save() # Adding user Guy u = User(username='guy', last_name="Carlier", first_name="Guy", email="guy@git.an", @@ -54,12 +56,16 @@ Welcome to the wiki page! is_superuser=False, is_staff=False) u.set_password("plop") u.save() + u.view_groups=[settings.AE_GROUPS['members']['id']] + u.save() # Adding user Richard Batsbak r = User(username='rbatsbak', last_name="Batsbak", first_name="Richard", email="richard@git.an", date_of_birth="1982-06-12") r.set_password("plop") r.save() + r.view_groups=[settings.AE_GROUPS['members']['id']] + r.save() # Adding syntax help page p = Page(name='Aide_sur_la_syntaxe') p.save() diff --git a/core/views/__init__.py b/core/views/__init__.py index 6f7525c8..ff19e750 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -72,7 +72,6 @@ class CanViewMixin(View): """ def dispatch(self, request, *arg, **kwargs): res = super(CanViewMixin, self).dispatch(request, *arg, **kwargs) - print("GUYGUYGUYGUYGUY") if hasattr(self, 'object'): obj = self.object elif hasattr(self, 'object_list'): diff --git a/sith/settings.py b/sith/settings.py index 55c899e0..7a6d200e 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -243,3 +243,7 @@ CLUB_ROLES = { 1: 'Membre actif', 0: 'Curieux', } + +# This corresponds to the maximum role a user can freely subscribe to +# In this case, MAXIMUM_FREE_ROLE=1 means that a user can set himself as "Membre actif" or "Curieux", but not higher +MAXIMUM_FREE_ROLE=1