Merge branch 'Buro_rights_by_BDS' into 'master'

Added basic buro right handling while updating member

See merge request klub-dev-ens/gestioCOF!482
This commit is contained in:
Martin Pepin 2021-01-30 15:06:52 +01:00
commit ef64f9ce5c
3 changed files with 16 additions and 1 deletions

View file

@ -31,7 +31,10 @@ adhérents ni des cotisations.
### BDS
- Le buro peut exporter la liste de membres avec email au format CSV depuis la page d'acceuil.
- Le burô peut maintenant accorder ou révoquer le statut de membre du Burô
en modifiant le profil d'un membre du BDS.
- Le burô peut exporter la liste de ses membres avec email au format CSV depuis
la page d'accueil.
### K-Fêt

View file

@ -1,6 +1,7 @@
from django import forms
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import gettext_lazy as _
from bds.models import BDSProfile
@ -8,6 +9,8 @@ User = get_user_model()
class UserForm(forms.ModelForm):
is_buro = forms.BooleanField(label=_("Membre du Burô"), required=False)
class Meta:
model = User
fields = ["email", "first_name", "last_name"]

View file

@ -3,6 +3,7 @@ import csv
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import Permission
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse, reverse_lazy
@ -40,6 +41,9 @@ class UserUpdateView(StaffRequiredMixin, MultipleFormView):
"profile": ProfileForm,
}
def get_user_initial(self):
return {"is_buro": self.get_user_instance().has_perm("bds.is_team")}
def dispatch(self, request, *args, **kwargs):
self.user = get_object_or_404(User, pk=self.kwargs["pk"])
return super().dispatch(request, *args, **kwargs)
@ -56,6 +60,11 @@ class UserUpdateView(StaffRequiredMixin, MultipleFormView):
def form_valid(self, forms):
user = forms["user"].save()
profile = forms["profile"].save(commit=False)
perm = Permission.objects.get(content_type__app_label="bds", codename="is_team")
if forms["user"].cleaned_data["is_buro"]:
user.user_permissions.add(perm)
else:
user.user_permissions.remove(perm)
profile.user = user
profile.save()
messages.success(self.request, _("Profil mis à jour avec succès !"))