Commit c8252b33 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'cherry-pick-84ce8916' into 'release/1.12'

Merge branch 'fix/wikilogin' into 'master'

See merge request !674
parents e7da84a6 89b676ac
......@@ -4,6 +4,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.test import TestCase, override_settings
from members.models import Profile
from thaliawebsite.templatetags import bleach_tags
......@@ -56,6 +57,26 @@ class WikiLoginTestCase(TestCase):
'name': 'first last_name',
'status': 'ok'})
@override_settings(WIKI_API_KEY='key')
def test_login_with_profile(self):
Profile.objects.create(
user=self.user,
student_number='s1234567'
)
response = self.client.post('/api/wikilogin',
{'apikey': 'key',
'user': 'testuser',
'password': 'top secret'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'admin': False,
'committees': [],
'msg': 'Logged in',
'mail': 'foo@bar.com',
'name': 'first last_name',
'status': 'ok'})
@override_settings(WIKI_API_KEY='key')
def test_board_permission(self):
self.user.user_permissions.add(
......
import os.path
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from django.http import (HttpResponseBadRequest, Http404,
HttpResponseForbidden, JsonResponse)
from django.shortcuts import render
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.decorators.debug import (sensitive_variables,
sensitive_post_parameters)
from django.views.decorators.http import require_POST
from sendfile import sendfile
from members.models import Profile
@login_required
def styleguide(request):
......@@ -42,14 +39,11 @@ def wiki_login(request):
user = authenticate(username=user, password=password)
if user is not None:
try:
memberships = [cmm.committee.wiki_namespace for cmm in
user.profile.committeemembership_set.exclude(
until__lt=timezone.now().date())
memberships = [cmm.committee.wiki_namespace for cmm in
user.committeemembership_set
.exclude(until__lt=timezone.now().date())
.select_related('committee')
if cmm.committee.wiki_namespace is not None]
except Profile.DoesNotExist:
memberships = []
if cmm.committee.wiki_namespace is not None]
if user.has_perm('activemembers.board_wiki'):
memberships.append('bestuur')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment