From f39e1a653ee15555900dda7a0d6fafd9821cfd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 29 Sep 2016 21:36:17 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20account=20pour=20compte=20g=C3=A9n?= =?UTF-8?q?=C3=A9rique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lors de la connexion avec l'utilisateur kfet standard, un Account avec le trigramme GNR est créé pour cet utilisateur + Clean et comment --- kfet/backends.py | 10 +++++++++- kfet/views.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/kfet/backends.py b/kfet/backends.py index 3729f1bd..ba3bce9d 100644 --- a/kfet/backends.py +++ b/kfet/backends.py @@ -30,9 +30,17 @@ class GenericTeamBackend(object): def authenticate(self, username=None, token=None): valid_token = GenericTeamToken.objects.get(token=token) if username == 'kfet_genericteam' and valid_token: - user, created = User.objects.get_or_create(username='kfet_genericteam') + # Création du user s'il n'existe pas déjà + user, _ = User.objects.get_or_create(username='kfet_genericteam') + profile, _ = CofProfile.objects.get_or_create(user=user) + account, _ = Account.objects.get_or_create( + cofprofile=profile, + trigramme='GNR') + + # Ajoute la permission kfet.is_team à ce user perm_is_team = Permission.objects.get(codename='is_team') user.user_permissions.add(perm_is_team) + return user return None diff --git a/kfet/views.py b/kfet/views.py index 3f1e1f4d..f95fb2c6 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -42,16 +42,22 @@ def home(request): @teamkfet_required def login_genericteam(request): + # Check si besoin de déconnecter l'utilisateur de CAS profile, _ = CofProfile.objects.get_or_create(user=request.user) - logout_cas = '' + need_cas_logout = False if profile.login_clipper: + need_cas_logout = True + # Récupèration de la vue de déconnexion de CAS + # Ici, car request sera modifié après logout_cas = django_cas_ng.views.logout(request) + # Authentification du compte générique token = GenericTeamToken.objects.create(token=get_random_string(50)) user = authenticate(username="kfet_genericteam", token=token.token) login(request, user) - if logout_cas: + if need_cas_logout: + # Vue de déconnexion de CAS return logout_cas return render(request, "kfet/login_genericteam.html") From 8349388ab3a195d32368239c1b192cbba16041e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 29 Sep 2016 21:47:37 +0200 Subject: [PATCH 2/2] Fix avaiable actions on genericteam acount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Empêche de rentrer des opérations et des transferts sur GNR (compte équipe K-Fêt partagé) Fix 84 --- kfet/forms.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index 54c0dd38..0c563b04 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -280,12 +280,12 @@ class KPsulOperationGroupForm(forms.ModelForm): is_protected=False, valid_from__lte=timezone.now(), valid_to__gte=timezone.now()), widget = forms.HiddenInput()) + on_acc = forms.ModelChoiceField( + queryset = Account.objects.exclude(trigramme='GNR'), + widget = forms.HiddenInput()) class Meta: model = OperationGroup fields = ['on_acc', 'checkout', 'comment'] - widgets = { - 'on_acc' : forms.HiddenInput(), - } class KPsulAccountForm(forms.ModelForm): class Meta: @@ -418,11 +418,11 @@ class TransferGroupForm(forms.ModelForm): class TransferForm(forms.ModelForm): from_acc = forms.ModelChoiceField( - queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13']), + queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13', 'GNR']), widget = forms.HiddenInput() ) to_acc = forms.ModelChoiceField( - queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13']), + queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13', 'GNR']), widget = forms.HiddenInput() )