Unverified Commit 59872b33 authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

events: add permission to override organiser

parent c4a2666e
......@@ -72,7 +72,8 @@ 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):
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()
if committees == 0:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-04-03 16:23
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0013_auto_20170215_2148'),
]
operations = [
migrations.AlterModelOptions(
name='event',
options={'ordering': ('-start',), 'permissions': (('override_organiser', 'Can access events as if organizing'),)},
),
]
......@@ -209,6 +209,9 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
class Meta:
ordering = ('-start',)
permissions = (
("override_organiser", "Can access events as if organizing"),
)
class RegistrationInformationField(models.Model, metaclass=ModelTranslateMeta):
......
......@@ -34,6 +34,9 @@ class AdminTest(TestCase):
cls.permission_change_event = Permission.objects.get(
content_type__model='event',
codename='change_event')
cls.permission_override_orga = Permission.objects.get(
content_type__model='event',
codename='override_organiser')
cls.member.user.user_permissions.add(cls.permission_change_event)
cls.member.user.is_superuser = False
cls.member.user.save()
......@@ -45,6 +48,9 @@ class AdminTest(TestCase):
def _remove_event_permission(self):
self.member.user.user_permissions.remove(self.permission_change_event)
def _add_override_organiser_permission(self):
self.member.user.user_permissions.add(self.permission_override_orga)
def test_admin_details_need_change_event_access(self):
"""I need the event.change_event permission to do stuff"""
self._remove_event_permission()
......@@ -72,6 +78,13 @@ class AdminTest(TestCase):
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)
......@@ -89,6 +102,17 @@ class AdminTest(TestCase):
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
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
......
......@@ -24,7 +24,8 @@ 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:
if (not request.user.is_superuser and event.organiser is not None and
not request.user.has_perm('events.override_organiser')):
committees = request.user.member.get_committees().filter(
pk=event.organiser.pk).count()
......
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