Small fix (le gaulois)

This commit is contained in:
Skia 2016-03-24 11:55:39 +01:00
parent c3fb581f97
commit 7d7652e319
4 changed files with 15 additions and 3 deletions

View File

@ -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")

View File

@ -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()

View File

@ -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'):

View File

@ -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