2018-08-22 22:00:08 +02:00
|
|
|
from typing import Set
|
2017-08-24 12:26:55 +02:00
|
|
|
|
2017-02-21 09:34:24 +01:00
|
|
|
from django.apps import apps
|
2016-06-02 12:47:01 +02:00
|
|
|
from django.utils.translation import ugettext_noop
|
2013-03-11 21:32:09 +01:00
|
|
|
|
2017-04-10 16:28:38 +02:00
|
|
|
from ..utils.auth import has_perm
|
|
|
|
from ..utils.collection import Collection
|
|
|
|
from .models import Motion, State, Workflow
|
2013-01-26 16:33:55 +01:00
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
2013-03-11 21:32:09 +01:00
|
|
|
def create_builtin_workflows(sender, **kwargs):
|
|
|
|
"""
|
2014-11-13 22:23:16 +01:00
|
|
|
Receiver function to create a simple and a complex workflow. It is
|
2016-09-03 21:43:11 +02:00
|
|
|
connected to the signal django.db.models.signals.post_migrate during
|
|
|
|
app loading.
|
2013-03-11 21:32:09 +01:00
|
|
|
"""
|
2015-01-16 14:18:34 +01:00
|
|
|
if Workflow.objects.exists():
|
|
|
|
# If there is at least one workflow, then do nothing.
|
|
|
|
return
|
2013-03-11 21:32:09 +01:00
|
|
|
|
2016-01-22 20:46:20 +01:00
|
|
|
workflow_1 = Workflow.objects.create(name='Simple Workflow')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_1_1 = State.objects.create(name=ugettext_noop('submitted'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_1,
|
|
|
|
allow_create_poll=True,
|
|
|
|
allow_support=True,
|
|
|
|
allow_submitter_edit=True)
|
2016-02-09 00:11:48 +01:00
|
|
|
state_1_2 = State.objects.create(name=ugettext_noop('accepted'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_1,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Accept',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Acceptance',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='success')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_1_3 = State.objects.create(name=ugettext_noop('rejected'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_1,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Reject',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Rejection',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='danger')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_1_4 = State.objects.create(name=ugettext_noop('not decided'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_1,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Do not decide',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='No decision',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2015-01-16 14:18:34 +01:00
|
|
|
state_1_1.next_states.add(state_1_2, state_1_3, state_1_4)
|
|
|
|
workflow_1.first_state = state_1_1
|
|
|
|
workflow_1.save()
|
|
|
|
|
2016-01-22 20:46:20 +01:00
|
|
|
workflow_2 = Workflow.objects.create(name='Complex Workflow')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_1 = State.objects.create(name=ugettext_noop('published'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
allow_support=True,
|
|
|
|
allow_submitter_edit=True,
|
|
|
|
dont_set_identifier=True)
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_2 = State.objects.create(name=ugettext_noop('permitted'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Permit',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Permission',
|
2015-01-16 14:18:34 +01:00
|
|
|
allow_create_poll=True,
|
2018-08-31 15:33:41 +02:00
|
|
|
allow_submitter_edit=True)
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_3 = State.objects.create(name=ugettext_noop('accepted'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Accept',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Acceptance',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='success')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_4 = State.objects.create(name=ugettext_noop('rejected'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Reject',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Rejection',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='danger')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_5 = State.objects.create(name=ugettext_noop('withdrawed'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Withdraw',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_6 = State.objects.create(name=ugettext_noop('adjourned'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Adjourn',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Adjournment',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_7 = State.objects.create(name=ugettext_noop('not concerned'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Do not concern',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='No concernment',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2016-09-03 21:43:11 +02:00
|
|
|
state_2_8 = State.objects.create(name=ugettext_noop('refered to committee'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-09-03 21:43:11 +02:00
|
|
|
action_word='Refer to committee',
|
|
|
|
recommendation_label='Referral to committee',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_9 = State.objects.create(name=ugettext_noop('needs review'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Needs review',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2016-02-09 00:11:48 +01:00
|
|
|
state_2_10 = State.objects.create(name=ugettext_noop('rejected (not authorized)'),
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow=workflow_2,
|
2016-01-22 20:46:20 +01:00
|
|
|
action_word='Reject (not authorized)',
|
2016-09-03 21:43:11 +02:00
|
|
|
recommendation_label='Rejection (not authorized)',
|
2015-11-03 21:38:53 +01:00
|
|
|
css_class='default')
|
2015-01-16 14:18:34 +01:00
|
|
|
state_2_1.next_states.add(state_2_2, state_2_5, state_2_10)
|
|
|
|
state_2_2.next_states.add(state_2_3, state_2_4, state_2_5, state_2_6, state_2_7, state_2_8, state_2_9)
|
|
|
|
workflow_2.first_state = state_2_1
|
|
|
|
workflow_2.save()
|
2017-02-21 09:34:24 +01:00
|
|
|
|
|
|
|
|
2017-03-06 16:34:20 +01:00
|
|
|
def get_permission_change_data(sender, permissions, **kwargs):
|
2017-02-21 09:34:24 +01:00
|
|
|
"""
|
2017-03-06 16:34:20 +01:00
|
|
|
Yields all necessary collections if 'motions.can_see' permission changes.
|
2017-02-21 09:34:24 +01:00
|
|
|
"""
|
2017-03-06 16:34:20 +01:00
|
|
|
motions_app = apps.get_app_config(app_label='motions')
|
2017-02-21 09:34:24 +01:00
|
|
|
for permission in permissions:
|
2017-03-06 16:34:20 +01:00
|
|
|
# There could be only one 'motions.can_see' and then we want to return data.
|
|
|
|
if permission.content_type.app_label == motions_app.label and permission.codename == 'can_see':
|
|
|
|
yield from motions_app.get_startup_elements()
|
2017-04-10 16:28:38 +02:00
|
|
|
|
|
|
|
|
2017-05-22 16:08:52 +02:00
|
|
|
def required_users(sender, request_user, **kwargs):
|
2017-04-10 16:28:38 +02:00
|
|
|
"""
|
2017-05-01 23:12:42 +02:00
|
|
|
Returns all user ids that are displayed as as submitter or supporter in
|
|
|
|
any motion if request_user can see motions. This function may return an
|
|
|
|
empty set.
|
2017-04-10 16:28:38 +02:00
|
|
|
"""
|
2018-08-22 22:00:08 +02:00
|
|
|
submitters_supporters: Set[int] = set()
|
2017-04-10 16:28:38 +02:00
|
|
|
if has_perm(request_user, 'motions.can_see'):
|
|
|
|
for motion_collection_element in Collection(Motion.get_collection_string()).element_generator():
|
|
|
|
full_data = motion_collection_element.get_full_data()
|
2018-06-12 14:17:02 +02:00
|
|
|
submitters_supporters.update(
|
|
|
|
[submitter['user_id'] for submitter in full_data['submitters']])
|
2017-05-01 23:12:42 +02:00
|
|
|
submitters_supporters.update(full_data['supporters_id'])
|
|
|
|
return submitters_supporters
|