forked from DGNum/gestioCOF
Merge branch 'issue84' into 'k-fet'
Utilisateur partagé K-Fêt - Ajout: création du compte GNR pour l'utilisateur partagé K-Fêt (kfet_genericteam) - Fix #84: plus de consos sur GNR - Fix: plus de transferts possibles avec GNR See merge request !89
This commit is contained in:
commit
7fccc81cdd
3 changed files with 22 additions and 8 deletions
|
@ -30,9 +30,17 @@ class GenericTeamBackend(object):
|
||||||
def authenticate(self, username=None, token=None):
|
def authenticate(self, username=None, token=None):
|
||||||
valid_token = GenericTeamToken.objects.get(token=token)
|
valid_token = GenericTeamToken.objects.get(token=token)
|
||||||
if username == 'kfet_genericteam' and valid_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')
|
perm_is_team = Permission.objects.get(codename='is_team')
|
||||||
user.user_permissions.add(perm_is_team)
|
user.user_permissions.add(perm_is_team)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -280,12 +280,12 @@ class KPsulOperationGroupForm(forms.ModelForm):
|
||||||
is_protected=False, valid_from__lte=timezone.now(),
|
is_protected=False, valid_from__lte=timezone.now(),
|
||||||
valid_to__gte=timezone.now()),
|
valid_to__gte=timezone.now()),
|
||||||
widget = forms.HiddenInput())
|
widget = forms.HiddenInput())
|
||||||
|
on_acc = forms.ModelChoiceField(
|
||||||
|
queryset = Account.objects.exclude(trigramme='GNR'),
|
||||||
|
widget = forms.HiddenInput())
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OperationGroup
|
model = OperationGroup
|
||||||
fields = ['on_acc', 'checkout', 'comment']
|
fields = ['on_acc', 'checkout', 'comment']
|
||||||
widgets = {
|
|
||||||
'on_acc' : forms.HiddenInput(),
|
|
||||||
}
|
|
||||||
|
|
||||||
class KPsulAccountForm(forms.ModelForm):
|
class KPsulAccountForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -418,11 +418,11 @@ class TransferGroupForm(forms.ModelForm):
|
||||||
|
|
||||||
class TransferForm(forms.ModelForm):
|
class TransferForm(forms.ModelForm):
|
||||||
from_acc = forms.ModelChoiceField(
|
from_acc = forms.ModelChoiceField(
|
||||||
queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13']),
|
queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13', 'GNR']),
|
||||||
widget = forms.HiddenInput()
|
widget = forms.HiddenInput()
|
||||||
)
|
)
|
||||||
to_acc = forms.ModelChoiceField(
|
to_acc = forms.ModelChoiceField(
|
||||||
queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13']),
|
queryset = Account.objects.exclude(trigramme__in=['LIQ', '#13', 'GNR']),
|
||||||
widget = forms.HiddenInput()
|
widget = forms.HiddenInput()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -42,16 +42,22 @@ def home(request):
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def login_genericteam(request):
|
def login_genericteam(request):
|
||||||
|
# Check si besoin de déconnecter l'utilisateur de CAS
|
||||||
profile, _ = CofProfile.objects.get_or_create(user=request.user)
|
profile, _ = CofProfile.objects.get_or_create(user=request.user)
|
||||||
logout_cas = ''
|
need_cas_logout = False
|
||||||
if profile.login_clipper:
|
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)
|
logout_cas = django_cas_ng.views.logout(request)
|
||||||
|
|
||||||
|
# Authentification du compte générique
|
||||||
token = GenericTeamToken.objects.create(token=get_random_string(50))
|
token = GenericTeamToken.objects.create(token=get_random_string(50))
|
||||||
user = authenticate(username="kfet_genericteam", token=token.token)
|
user = authenticate(username="kfet_genericteam", token=token.token)
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
|
||||||
if logout_cas:
|
if need_cas_logout:
|
||||||
|
# Vue de déconnexion de CAS
|
||||||
return logout_cas
|
return logout_cas
|
||||||
|
|
||||||
return render(request, "kfet/login_genericteam.html")
|
return render(request, "kfet/login_genericteam.html")
|
||||||
|
|
Loading…
Reference in a new issue