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:
Martin Pepin 2016-09-29 23:04:09 +02:00
commit 7fccc81cdd
3 changed files with 22 additions and 8 deletions

View file

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

View file

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

View file

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