Commit ae728405 authored by Joost Rijneveld's avatar Joost Rijneveld

Merge branch '馃搮' into 'master'

Make Event.organiser NOT NULL

Closes #379

See merge request !443
parents 517a91b7 8726ad82
......@@ -72,7 +72,6 @@ class EventAdmin(DoNextModelAdmin):
def has_change_permission(self, request, event=None):
try:
if (not request.user.is_superuser and event is not None and
event.organiser is not None and
not request.user.has_perm('events.override_organiser')):
committees = request.user.member.get_committees().filter(
Q(pk=event.organiser.pk)).count()
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-05 17:04
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0014_auto_20170403_1823'),
]
operations = [
migrations.AlterField(
model_name='event',
name='organiser',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='activemembers.Committee', verbose_name='organiser'),
preserve_default=False,
),
]
......@@ -41,8 +41,7 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
organiser = models.ForeignKey(
'activemembers.Committee',
models.SET_NULL,
null=True,
models.PROTECT,
verbose_name=_("organiser")
)
......
......@@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError
from django.test import TestCase
from django.utils import timezone
from activemembers.models import Committee
from events.models import Event, Registration
from members.models import Member
......@@ -11,13 +12,14 @@ from members.models import Member
class EventTest(TestCase):
"""Tests events"""
fixtures = ['members.json']
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
title_nl='testevene',
title_en='testevent',
organiser=Committee.objects.get(pk=1),
description_en='desc',
description_nl='besch',
start=(timezone.now() + datetime.timedelta(hours=1)),
......@@ -159,13 +161,14 @@ class EventTest(TestCase):
class RegistrationTest(TestCase):
"""Tests event registrations"""
fixtures = ['members.json']
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
title_nl='testevene',
title_en='testevent',
organiser=Committee.objects.get(pk=1),
description_en='desc',
description_nl='besch',
start=timezone.now(),
......
......@@ -16,8 +16,10 @@ class AdminTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.committee = Committee.objects.get(pk=1)
cls.event = Event.objects.create(
pk=1,
organiser=cls.committee,
title_nl='testevenement',
title_en='testevent',
description_en='desc',
......@@ -40,7 +42,6 @@ class AdminTest(TestCase):
cls.member.user.user_permissions.add(cls.permission_change_event)
cls.member.user.is_superuser = False
cls.member.user.save()
cls.committee = Committee.objects.get(pk=1)
def setUp(self):
self.client.force_login(self.member.user)
......@@ -58,95 +59,64 @@ class AdminTest(TestCase):
self.assertEqual(302, response.status_code)
self.assertTrue(response.url.startswith('/login/'))
def test_admin_details_no_organiser_allowed_access(self):
"""If an event has no organiser, then I should be allowed access"""
response = self.client.get('/events/admin/1/')
self.assertEqual(200, response.status_code)
def test_admin_details_organiser_denied(self):
self.event.organiser = self.committee
self.event.save()
response = self.client.get('/events/admin/1/')
self.assertEqual(403, response.status_code)
def test_admin_details_organiser_allowed(self):
self.event.organiser = self.committee
CommitteeMembership.objects.create(
member=self.member,
committee=self.committee)
self.event.save()
response = self.client.get('/events/admin/1/')
self.assertEqual(200, response.status_code)
def test_admin_details_override_organiser_allowed(self):
self._add_override_organiser_permission()
self.event.organiser = self.committee
self.event.save()
response = self.client.get('/events/admin/1/')
self.assertEqual(200, response.status_code)
def test_modeladmin_change_no_organiser_allowed(self):
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(200, response.status_code)
def test_modeladmin_change_organiser_allowed(self):
"""Test the ModelAdmin change page
"""Change event as an organiser
If I'm an organiser I should be allowed access
"""
self.event.organiser = self.committee
CommitteeMembership.objects.create(
member=self.member,
committee=self.committee)
self.event.save()
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(200, response.status_code)
def test_modeladmin_change_override_organiser_allowed(self):
"""Test the ModelAdmin change page
"""Test the override organiser permission for changing events
If I'm allowed to override organiser restrictions..
"""
self._add_override_organiser_permission()
self.event.organiser = self.committee
self.event.save()
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(200, response.status_code)
def test_modeladmin_change_organiser_no_permissions_denied(self):
"""Test the ModelAdmin change page
"""Committee members without change permissions are banned
If I'm an organiser, but don't have perms I should not
be allowed access
"""
self._remove_event_permission()
self.event.organiser = self.committee
CommitteeMembership.objects.create(
member=self.member,
committee=self.committee)
self.event.save()
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(403, response.status_code)
def test_modeladmin_change_superuser_allowed(self):
"""Test the ModelAdmin change page
If I'm an organiser I should be allowed access
"""
self.event.organiser = self.committee
self.event.save()
"""Superuser should be allowed access always"""
self.member.user.is_superuser = True
self.member.user.save()
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(200, response.status_code)
def test_modeladmin_change_organiser_denied(self):
"""Test the ModelAdmin change page
If I'm not an organiser I should not be allowed access
"""
self.event.organiser = self.committee
self.event.save()
"""If I'm not an organiser I should not be allowed access"""
response = self.client.get('/admin/events/event/1/change/')
self.assertEqual(403, response.status_code)
......@@ -154,12 +124,13 @@ class AdminTest(TestCase):
class RegistrationTest(TestCase):
"""Tests for registration view"""
fixtures = ['members.json']
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
pk=1,
organiser=Committee.objects.get(pk=1),
title_nl='testevene',
title_en='testevent',
description_en='desc',
......
......@@ -24,7 +24,7 @@ from .models import Event, Registration, RegistrationInformationField
def admin_details(request, event_id):
event = get_object_or_404(Event, pk=event_id)
if (not request.user.is_superuser and event.organiser is not None and
if (not request.user.is_superuser and
not request.user.has_perm('events.override_organiser')):
committees = request.user.member.get_committees().filter(
pk=event.organiser.pk).count()
......
Markdown is supported
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