2013-03-12 20:58:22 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from django import forms
|
2013-03-12 20:58:22 +01:00
|
|
|
from django.contrib.auth.models import Permission
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.dispatch import receiver
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
from openslides.config.api import ConfigCollection, ConfigVariable
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.signals import config_signal
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.core.signals import post_database_setup
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2013-06-16 12:00:57 +02:00
|
|
|
from .api import create_or_reset_admin_user
|
2013-09-25 10:01:01 +02:00
|
|
|
from .models import Group
|
2013-03-12 20:58:22 +01:00
|
|
|
|
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
@receiver(config_signal, dispatch_uid='setup_participant_config')
|
|
|
|
def setup_participant_config(sender, **kwargs):
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
|
|
|
Participant config variables.
|
|
|
|
"""
|
2013-10-23 23:47:25 +02:00
|
|
|
participant_pdf_welcometitle = ConfigVariable(
|
|
|
|
name='participant_pdf_welcometitle',
|
|
|
|
default_value=_('Welcome to OpenSlides!'),
|
2013-03-01 17:13:12 +01:00
|
|
|
form_field=forms.CharField(
|
2013-10-23 23:47:25 +02:00
|
|
|
widget=forms.Textarea(),
|
2013-03-01 17:13:12 +01:00
|
|
|
required=False,
|
2013-10-23 23:47:25 +02:00
|
|
|
label=ugettext_lazy('Title for access data and welcome PDF')))
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
participant_pdf_welcometext = ConfigVariable(
|
|
|
|
name='participant_pdf_welcometext',
|
2013-10-23 23:47:25 +02:00
|
|
|
default_value=_('[Place for your welcome and help text.]'),
|
2013-03-01 17:13:12 +01:00
|
|
|
form_field=forms.CharField(
|
|
|
|
widget=forms.Textarea(),
|
|
|
|
required=False,
|
2013-10-23 23:47:25 +02:00
|
|
|
label=ugettext_lazy('Help text for access data and welcome PDF')))
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
participant_sort_users_by_first_name = ConfigVariable(
|
|
|
|
name='participant_sort_users_by_first_name',
|
|
|
|
default_value=False,
|
|
|
|
form_field=forms.BooleanField(
|
|
|
|
required=False,
|
2013-04-22 19:59:05 +02:00
|
|
|
label=ugettext_lazy('Sort participants by first name'),
|
|
|
|
help_text=ugettext_lazy('Disable for sorting by last name')))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
return ConfigCollection(title=ugettext_noop('Participant'),
|
|
|
|
url='participant',
|
|
|
|
required_permission='config.can_manage',
|
|
|
|
weight=50,
|
|
|
|
variables=(participant_pdf_welcometitle,
|
|
|
|
participant_pdf_welcometext,
|
|
|
|
participant_sort_users_by_first_name))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
|
|
|
2013-06-16 12:00:57 +02:00
|
|
|
@receiver(post_database_setup, dispatch_uid='participant_create_builtin_groups_and_admin')
|
|
|
|
def create_builtin_groups_and_admin(sender, **kwargs):
|
2013-03-12 20:58:22 +01:00
|
|
|
"""
|
2013-06-16 12:00:57 +02:00
|
|
|
Creates the buildin groups and the admin user.
|
|
|
|
|
2013-03-12 20:58:22 +01:00
|
|
|
Creates the builtin groups: Anonymous, Registered, Delegates and Staff.
|
2013-06-16 12:00:57 +02:00
|
|
|
|
|
|
|
Creates the builtin user: admin.
|
2013-03-12 20:58:22 +01:00
|
|
|
"""
|
2013-04-02 15:50:40 +02:00
|
|
|
# Check whether the group pks 1 to 4 are free
|
2013-06-02 23:12:00 +02:00
|
|
|
if Group.objects.filter(pk__in=range(1, 5)).exists():
|
|
|
|
# Do completely nothing if there are already some of our groups in the database.
|
|
|
|
return
|
2013-04-02 15:50:40 +02:00
|
|
|
|
2013-03-12 20:58:22 +01:00
|
|
|
# Anonymous and Registered
|
|
|
|
ct_projector = ContentType.objects.get(app_label='projector', model='projectorslide')
|
|
|
|
perm_1 = Permission.objects.get(content_type=ct_projector, codename='can_see_projector')
|
|
|
|
perm_2 = Permission.objects.get(content_type=ct_projector, codename='can_see_dashboard')
|
|
|
|
|
|
|
|
ct_agenda = ContentType.objects.get(app_label='agenda', model='item')
|
2013-03-18 12:34:47 +01:00
|
|
|
ct_speaker = ContentType.objects.get(app_label='agenda', model='speaker')
|
2013-03-12 20:58:22 +01:00
|
|
|
perm_3 = Permission.objects.get(content_type=ct_agenda, codename='can_see_agenda')
|
2013-04-02 15:50:40 +02:00
|
|
|
perm_3a = Permission.objects.get(content_type=ct_agenda, codename='can_see_orga_items')
|
2013-03-18 12:34:47 +01:00
|
|
|
can_speak = Permission.objects.get(content_type=ct_speaker, codename='can_be_speaker')
|
2013-03-12 20:58:22 +01:00
|
|
|
|
|
|
|
ct_motion = ContentType.objects.get(app_label='motion', model='motion')
|
|
|
|
perm_4 = Permission.objects.get(content_type=ct_motion, codename='can_see_motion')
|
|
|
|
|
|
|
|
ct_assignment = ContentType.objects.get(app_label='assignment', model='assignment')
|
|
|
|
perm_5 = Permission.objects.get(content_type=ct_assignment, codename='can_see_assignment')
|
|
|
|
|
|
|
|
ct_participant = ContentType.objects.get(app_label='participant', model='user')
|
|
|
|
perm_6 = Permission.objects.get(content_type=ct_participant, codename='can_see_participant')
|
|
|
|
|
2013-02-16 16:19:20 +01:00
|
|
|
ct_mediafile = ContentType.objects.get(app_label='mediafile', model='mediafile')
|
|
|
|
perm_6a = Permission.objects.get(content_type=ct_mediafile, codename='can_see')
|
|
|
|
|
2013-04-02 15:50:40 +02:00
|
|
|
group_anonymous = Group.objects.create(name=ugettext_noop('Anonymous'), pk=1)
|
|
|
|
group_anonymous.permissions.add(perm_1, perm_2, perm_3, perm_3a, perm_4, perm_5, perm_6, perm_6a)
|
|
|
|
group_registered = Group.objects.create(name=ugettext_noop('Registered'), pk=2)
|
2013-03-18 12:34:47 +01:00
|
|
|
group_registered.permissions.add(perm_1, perm_2, perm_3, perm_3a, perm_4, perm_5, perm_6, perm_6a, can_speak)
|
2013-03-12 20:58:22 +01:00
|
|
|
|
|
|
|
# Delegates
|
|
|
|
perm_7 = Permission.objects.get(content_type=ct_motion, codename='can_create_motion')
|
|
|
|
perm_8 = Permission.objects.get(content_type=ct_motion, codename='can_support_motion')
|
|
|
|
perm_9 = Permission.objects.get(content_type=ct_assignment, codename='can_nominate_other')
|
|
|
|
perm_10 = Permission.objects.get(content_type=ct_assignment, codename='can_nominate_self')
|
2013-02-16 16:19:20 +01:00
|
|
|
perm_10a = Permission.objects.get(content_type=ct_mediafile, codename='can_upload')
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2013-04-02 15:50:40 +02:00
|
|
|
group_delegates = Group.objects.create(name=ugettext_noop('Delegates'), pk=3)
|
2013-02-16 16:19:20 +01:00
|
|
|
group_delegates.permissions.add(perm_7, perm_8, perm_9, perm_10, perm_10a)
|
2013-03-12 20:58:22 +01:00
|
|
|
|
|
|
|
# Staff
|
|
|
|
perm_11 = Permission.objects.get(content_type=ct_agenda, codename='can_manage_agenda')
|
|
|
|
perm_12 = Permission.objects.get(content_type=ct_motion, codename='can_manage_motion')
|
|
|
|
perm_13 = Permission.objects.get(content_type=ct_assignment, codename='can_manage_assignment')
|
|
|
|
perm_14 = Permission.objects.get(content_type=ct_participant, codename='can_manage_participant')
|
|
|
|
perm_15 = Permission.objects.get(content_type=ct_projector, codename='can_manage_projector')
|
2013-02-16 16:19:20 +01:00
|
|
|
perm_15a = Permission.objects.get(content_type=ct_mediafile, codename='can_manage')
|
2013-03-12 20:58:22 +01:00
|
|
|
|
|
|
|
ct_config = ContentType.objects.get(app_label='config', model='configstore')
|
2013-03-01 17:13:12 +01:00
|
|
|
perm_16 = Permission.objects.get(content_type=ct_config, codename='can_manage')
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2013-04-02 15:50:40 +02:00
|
|
|
group_staff = Group.objects.create(name=ugettext_noop('Staff'), pk=4)
|
|
|
|
group_staff.permissions.add(perm_7, perm_9, perm_10, perm_10a, perm_11, perm_12, perm_13, perm_14, perm_15, perm_15a, perm_16)
|
2013-12-23 19:14:11 +01:00
|
|
|
group_staff.permissions.add(perm_6) # TODO: Remove this redundancy after cleanup of the permission system
|
2013-06-16 12:00:57 +02:00
|
|
|
|
|
|
|
# Admin user
|
|
|
|
create_or_reset_admin_user()
|