1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 23:42:25 +00:00

Update permission fixtures

This commit is contained in:
Yohann D'ANELLO 2020-04-06 10:45:32 +02:00
parent f833f1c46c
commit bd41560f45
6 changed files with 478 additions and 273 deletions

View File

@ -0,0 +1,20 @@
[
{
"model": "activity.activitytype",
"pk": 1,
"fields": {
"name": "Pot",
"can_invite": true,
"guest_entry_fee": 500
}
},
{
"model": "activity.activitytype",
"pk": 2,
"fields": {
"name": "Soir\u00e9e de club",
"can_invite": false,
"guest_entry_fee": 0
}
}
]

View File

@ -389,6 +389,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
club = Club.objects.filter(PermissionBackend.filter_queryset(self.request.user, Club, "view"))\
.get(pk=self.kwargs["club_pk"])
form.fields['credit_amount'].initial = club.membership_fee_paid
form.fields['roles'].initial = Role.objects.filter(name="Membre de club").all()
# If the concerned club is the BDE, then we add the option that Société générale pays the membership.
if club.name != "BDE":

View File

@ -10,7 +10,7 @@ def save_user_note(instance, raw, **_kwargs):
# When provisionning data, do not try to autocreate
return
if instance.profile.registration_valid and instance.is_active:
if (instance.is_superuser or instance.profile.registration_valid) and instance.is_active:
# Create note only when the registration is validated
from note.models import NoteUser
NoteUser.objects.get_or_create(user=instance)

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ class ValidationForm(forms.Form):
join_BDE = forms.BooleanField(
label=_("Join BDE Club"),
required=True,
required=False,
initial=True,
)

View File

@ -12,6 +12,7 @@ from django.utils.http import urlsafe_base64_decode
from django.utils.translation import gettext_lazy as _
from django.views import View
from django.views.generic import CreateView, TemplateView, DetailView, FormView
from django.views.generic.edit import FormMixin
from django_tables2 import SingleTableView
from member.forms import ProfileForm
from member.models import Membership, Club, Role
@ -88,7 +89,7 @@ class UserValidateView(TemplateView):
if user is not None and email_validation_token.check_token(user, token):
self.validlink = True
# The user must wait that someone validates the account before the user can be active and login.
user.is_active = user.profile.registration_valid
user.is_active = user.profile.registration_valid or user.is_superuser
user.profile.email_confirmed = True
user.save()
user.profile.save()
@ -185,7 +186,7 @@ class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVi
return context
class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView, FormView):
class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin, DetailView):
"""
Display information about a pre-registered user, in order to complete the registration.
"""
@ -194,6 +195,14 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView,
context_object_name = "user_object"
template_name = "registration/future_profile_detail.html"
def post(self, request, *args, **kwargs):
form = self.get_form()
self.object = self.get_object()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
def get_queryset(self, **kwargs):
"""
We only display information of a not registered user.
@ -221,7 +230,7 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView,
return form
def form_valid(self, form):
user = self.object = self.get_object()
user = self.get_object()
# Get form data
soge = form.cleaned_data["soge"]
@ -238,6 +247,10 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView,
join_BDE = True
join_Kfet = True
if not join_BDE:
form.add_error('join_BDE', _("You must join the BDE."))
return super().form_invalid(form)
fee = 0
bde = Club.objects.get(name="BDE")
bde_fee = bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid
@ -254,6 +267,8 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView,
credit_amount = fee
bank = "Société générale"
print("OK")
if join_Kfet and not join_BDE:
form.add_error('join_Kfet', _("You must join BDE club before joining Kfet club."))
@ -277,7 +292,7 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView,
# Save the user and finally validate the registration
# Saving the user creates the associated note
ret = super().form_valid(form)
user.is_active = user.profile.email_confirmed
user.is_active = user.profile.email_confirmed or user.is_superuser
user.profile.registration_valid = True
# Store if Société générale paid for next years
user.profile.soge = soge