Reapply fix to kfetauth (…) and fix tests

This commit is contained in:
Aurélien Delobelle 2017-10-24 17:56:14 +02:00
parent 1cc51f17a3
commit af3a7cf697
3 changed files with 5 additions and 15 deletions

View file

@ -18,6 +18,8 @@ class GroupForm(forms.ModelForm):
# other_groups = self.instance.permissions.difference(
# self.fields['permissions'].queryset
# )
if self.instance.pk is None:
return kfet_perms
other_perms = self.instance.permissions.exclude(
pk__in=[p.pk for p in self.fields['permissions'].queryset],
)
@ -36,6 +38,8 @@ class UserGroupForm(forms.ModelForm):
def clean_groups(self):
kfet_groups = self.cleaned_data.get('groups')
if self.instance.pk is None:
return kfet_groups
other_groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return list(kfet_groups) + list(other_groups)

View file

@ -18,20 +18,6 @@ from .testcases import ViewTestCaseMixin
from .utils import create_team, create_user, get_perms
class LoginGenericTeamViewTests(ViewTestCaseMixin, TestCase):
url_name = 'kfet.login.genericteam'
url_expected = '/k-fet/login/genericteam'
auth_user = 'team'
auth_forbidden = [None, 'user']
def test_ok(self):
r = self.client.get(self.url)
self.assertEqual(r.status_code, 200)
logged_in = r.wsgi_request.user
self.assertEqual(logged_in.username, 'kfet_genericteam')
class AccountListViewTests(ViewTestCaseMixin, TestCase):
url_name = 'kfet.account'
url_expected = '/k-fet/accounts/'

View file

@ -12,7 +12,7 @@ from django.views.generic.edit import CreateView, UpdateView
from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.models import User, Permission
from django.http import JsonResponse, Http404
from django.forms import formset_factory