Merge pull request #581 from normanjaeckel/Antragsschluss

Inserted a new config variable 'Stop submitting of new motions'
This commit is contained in:
Oskar Hahn 2013-04-09 13:18:50 -07:00
commit fcc0690b8b
8 changed files with 103 additions and 5 deletions

View File

@ -26,6 +26,12 @@ def setup_motion_config_page(sender, **kwargs):
""" """
Motion config variables. Motion config variables.
""" """
motion_stop_submitting = ConfigVariable(
name='motion_stop_submitting',
default_value=False,
form_field=forms.BooleanField(
label=_('Stop submitting new motions by non-staff users'),
required=False))
motion_min_supporters = ConfigVariable( motion_min_supporters = ConfigVariable(
name='motion_min_supporters', name='motion_min_supporters',
default_value=0, default_value=0,
@ -106,7 +112,8 @@ def setup_motion_config_page(sender, **kwargs):
url='motion', url='motion',
required_permission='config.can_manage', required_permission='config.can_manage',
weight=30, weight=30,
variables=(motion_min_supporters, variables=(motion_stop_submitting,
motion_min_supporters,
motion_preamble, motion_preamble,
motion_pdf_ballot_papers_selection, motion_pdf_ballot_papers_selection,
motion_pdf_ballot_papers_number, motion_pdf_ballot_papers_number,

View File

@ -10,7 +10,9 @@
{% trans "Motions" %} {% trans "Motions" %}
<small class="pull-right"> <small class="pull-right">
{% if perms.motion.can_create_motion %} {% if perms.motion.can_create_motion %}
<a href="{% url 'motion_new' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New motion' %}"><i class="icon-plus icon-white"></i> {% trans 'New' %}</a> {% if not 'motion_stop_submitting'|get_config or perms.motion.can_manage_motion %}
<a href="{% url 'motion_new' %}" class="btn btn-mini btn-primary" rel="tooltip" data-original-title="{% trans 'New motion' %}"><i class="icon-plus icon-white"></i> {% trans 'New' %}</a>
{% endif %}
{% endif %} {% endif %}
{% if perms.motion.can_manage_motion %} {% if perms.motion.can_manage_motion %}
<a href="{% url 'motion_category_list' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'New motion' %}"><i class="icon-th-large"></i> {% trans 'Category' %}</a> <a href="{% url 'motion_category_list' %}" class="btn btn-mini" rel="tooltip" data-original-title="{% trans 'New motion' %}"><i class="icon-th-large"></i> {% trans 'Category' %}</a>

View File

@ -152,9 +152,20 @@ class MotionMixin(object):
class MotionCreateView(MotionMixin, CreateView): class MotionCreateView(MotionMixin, CreateView):
"""View to create a motion.""" """View to create a motion."""
permission_required = 'motion.can_create_motion'
model = Motion model = Motion
def has_permission(self, request, *args, **kwargs):
"""
Checks whether the requesting user can submit a new motion. He needs
at least the permission 'motion.can_create_motion'. If the submitting
of new motions by non-staff users is stopped via config variable
'motion_stop_submitting', the requesting user needs also to have
'motion.can_manage_motion'.
"""
if request.user.has_perm('motion.can_create_motion'):
return not config['motion_stop_submitting'] or request.user.has_perm('motion.can_manage_motion')
return False
def form_valid(self, form): def form_valid(self, form):
"""Write a log message, if the form is valid.""" """Write a log message, if the form is valid."""
value = super(MotionCreateView, self).form_valid(form) value = super(MotionCreateView, self).form_valid(form)

View File

@ -22,6 +22,11 @@ def get_config(key):
return config[key] return config[key]
@register.filter
def get_config(key):
return config[key]
@register.simple_tag @register.simple_tag
def active(request, pattern): def active(request, pattern):
if request.path.startswith(pattern): if request.path.startswith(pattern):

View File

@ -4,7 +4,7 @@
Tests for openslides.motion.models Tests for openslides.motion.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS. :copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
@ -136,3 +136,8 @@ class ModelTest(TestCase):
with self.assertRaises(WorkflowError): with self.assertRaises(WorkflowError):
state_1.next_states.add(state_2) state_1.next_states.add(state_2)
state_1.save() state_1.save()
class ConfigTest(TestCase):
def test_stop_submitting(self):
self.assertFalse(config['motion_stop_submitting'])

View File

@ -4,12 +4,13 @@
Tests for openslides.motion.models Tests for openslides.motion.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS. :copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
from django.test.client import Client from django.test.client import Client
from openslides.config.api import config
from openslides.utils.test import TestCase from openslides.utils.test import TestCase
from openslides.participant.models import User, Group from openslides.participant.models import User, Group
from openslides.motion.models import Motion from openslides.motion.models import Motion
@ -22,6 +23,14 @@ class MotionViewTestCase(TestCase):
self.admin_client = Client() self.admin_client = Client()
self.admin_client.login(username='admin', password='admin') self.admin_client.login(username='admin', password='admin')
# Staff
self.staff = User.objects.create_user('staff', 'staff@user.user', 'staff')
staff_group = Group.objects.get(name='Staff')
self.staff.groups.add(staff_group)
self.staff.save()
self.staff_client = Client()
self.staff_client.login(username='staff', password='staff')
# Delegate # Delegate
self.delegate = User.objects.create_user('delegate', 'delegate@user.user', 'delegate') self.delegate = User.objects.create_user('delegate', 'delegate@user.user', 'delegate')
delegate_group = Group.objects.get(name='Delegates') delegate_group = Group.objects.get(name='Delegates')
@ -90,6 +99,26 @@ class TestMotionCreateView(MotionViewTestCase):
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
self.assertFalse(Motion.objects.filter(versions__title='registered motion').exists()) self.assertFalse(Motion.objects.filter(versions__title='registered motion').exists())
def test_delegate_after_stop_submitting_new_motions(self):
config['motion_stop_submitting'] = True
response = self.delegate_client.get(self.url)
self.assertEqual(response.status_code, 403)
def test_delegate_after_stop_submitting_new_motions_overview(self):
config['motion_stop_submitting'] = True
response = self.delegate_client.get('/motion/')
self.assertNotContains(response, 'href="/motion/new/"', status_code=200)
def test_staff_after_stop_submitting_new_motions(self):
config['motion_stop_submitting'] = True
response = self.staff_client.get(self.url)
self.assertEqual(response.status_code, 200)
def test_staff_after_stop_submitting_new_motions_overview(self):
config['motion_stop_submitting'] = True
response = self.staff_client.get('/motion/')
self.assertContains(response, 'href="/motion/new/"', status_code=200)
class TestMotionUpdateView(MotionViewTestCase): class TestMotionUpdateView(MotionViewTestCase):
url = '/motion/1/edit/' url = '/motion/1/edit/'

0
tests/utils/__init__.py Normal file
View File

View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for openslides.utils.templatetags.tags
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.template import Template, Context
from openslides.utils.test import TestCase
from openslides.config.api import config
class ConfigTagAndFilter(TestCase):
def test_config_tag(self):
config['taiNg3reQuooGha4'] = 'iWoor0caThieK7yi'
template = Template("{% load tags %} The config var is {% get_config 'taiNg3reQuooGha4' %}.")
self.assertTrue('The config var is iWoor0caThieK7yi.' in template.render(Context({})))
def test_config_filter(self):
config['fkjTze56ncuejWqs'] = 'REG56Hnmfk9TdfsD'
template = Template("{% load tags %} The config var is {{ 'fkjTze56ncuejWqs'|get_config }}.")
self.assertTrue('The config var is REG56Hnmfk9TdfsD.' in template.render(Context({})))
def test_both_in_one(self):
config['jfhsnezfh452w6Fg'] = True
config['sdmvldkfgj4534gk'] = 'FdgfkR04jtg9f8bq'
template_code = """{% load tags %}
{% if 'jfhsnezfh452w6Fg'|get_config %}
{% get_config 'sdmvldkfgj4534gk' %}
{% else %}
bad_e0fvkfHFD
{% endif %}"""
template = Template(template_code)
self.assertTrue('FdgfkR04jtg9f8bq' in template.render(Context({})))
self.assertFalse('bad_e0fvkfHFD' in template.render(Context({})))