Inserted a new config variable 'Stop submitting of new motions'
Normal delegates can not submit a new motion when this is set to true. Inserted also a new template filter to relate to config variables in if-clauses.
This commit is contained in:
parent
dc65f5e349
commit
82c804e2d6
@ -26,6 +26,12 @@ def setup_motion_config_page(sender, **kwargs):
|
||||
"""
|
||||
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(
|
||||
name='motion_min_supporters',
|
||||
default_value=0,
|
||||
@ -106,7 +112,8 @@ def setup_motion_config_page(sender, **kwargs):
|
||||
url='motion',
|
||||
required_permission='config.can_manage',
|
||||
weight=30,
|
||||
variables=(motion_min_supporters,
|
||||
variables=(motion_stop_submitting,
|
||||
motion_min_supporters,
|
||||
motion_preamble,
|
||||
motion_pdf_ballot_papers_selection,
|
||||
motion_pdf_ballot_papers_number,
|
||||
|
@ -10,7 +10,9 @@
|
||||
{% trans "Motions" %}
|
||||
<small class="pull-right">
|
||||
{% 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 %}
|
||||
{% 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>
|
||||
|
@ -152,9 +152,20 @@ class MotionMixin(object):
|
||||
|
||||
class MotionCreateView(MotionMixin, CreateView):
|
||||
"""View to create a motion."""
|
||||
permission_required = 'motion.can_create_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):
|
||||
"""Write a log message, if the form is valid."""
|
||||
value = super(MotionCreateView, self).form_valid(form)
|
||||
|
@ -22,6 +22,11 @@ def get_config(key):
|
||||
return config[key]
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_config(key):
|
||||
return config[key]
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def active(request, pattern):
|
||||
if request.path.startswith(pattern):
|
||||
|
@ -4,7 +4,7 @@
|
||||
Tests for openslides.motion.models
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
||||
:copyright: 2011–2013 by OpenSlides team, see AUTHORS.
|
||||
:license: GNU GPL, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
@ -136,3 +136,8 @@ class ModelTest(TestCase):
|
||||
with self.assertRaises(WorkflowError):
|
||||
state_1.next_states.add(state_2)
|
||||
state_1.save()
|
||||
|
||||
|
||||
class ConfigTest(TestCase):
|
||||
def test_stop_submitting(self):
|
||||
self.assertFalse(config['motion_stop_submitting'])
|
||||
|
@ -4,12 +4,13 @@
|
||||
Tests for openslides.motion.models
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
||||
:copyright: 2011–2013 by OpenSlides team, see AUTHORS.
|
||||
:license: GNU GPL, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from django.test.client import Client
|
||||
|
||||
from openslides.config.api import config
|
||||
from openslides.utils.test import TestCase
|
||||
from openslides.participant.models import User, Group
|
||||
from openslides.motion.models import Motion
|
||||
@ -22,6 +23,14 @@ class MotionViewTestCase(TestCase):
|
||||
self.admin_client = Client()
|
||||
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
|
||||
self.delegate = User.objects.create_user('delegate', 'delegate@user.user', 'delegate')
|
||||
delegate_group = Group.objects.get(name='Delegates')
|
||||
@ -90,6 +99,26 @@ class TestMotionCreateView(MotionViewTestCase):
|
||||
self.assertEqual(response.status_code, 403)
|
||||
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):
|
||||
url = '/motion/1/edit/'
|
||||
|
0
tests/utils/__init__.py
Normal file
0
tests/utils/__init__.py
Normal file
39
tests/utils/test_template_tags_filters.py
Normal file
39
tests/utils/test_template_tags_filters.py
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for openslides.utils.templatetags.tags
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
:copyright: 2011–2013 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({})))
|
Loading…
Reference in New Issue
Block a user