2013-03-01 17:13:12 +01:00
|
|
|
from django import forms
|
2015-02-18 15:58:12 +01:00
|
|
|
from django.db.models import Q
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2014-01-31 00:55:18 +01:00
|
|
|
from openslides.config.api import ConfigGroup, ConfigGroupedCollection, ConfigVariable
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2015-02-12 20:57:05 +01:00
|
|
|
from .models import Group, Permission, User
|
|
|
|
|
2013-03-12 20:58:22 +01:00
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
def setup_users_config(sender, **kwargs):
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
2014-11-13 22:23:16 +01:00
|
|
|
Receiver function to setup all users config variables. It is connected
|
|
|
|
to the signal openslides.config.signals.config_signal during app loading.
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
2014-01-31 00:55:18 +01:00
|
|
|
# General
|
2014-10-11 14:34:49 +02:00
|
|
|
users_sort_users_by_first_name = ConfigVariable(
|
|
|
|
name='users_sort_users_by_first_name',
|
2014-01-31 00:55:18 +01:00
|
|
|
default_value=False,
|
|
|
|
form_field=forms.BooleanField(
|
|
|
|
required=False,
|
2014-10-11 14:34:49 +02:00
|
|
|
label=ugettext_lazy('Sort users by first name'),
|
2014-01-31 00:55:18 +01:00
|
|
|
help_text=ugettext_lazy('Disable for sorting by last name')))
|
|
|
|
|
|
|
|
group_general = ConfigGroup(
|
|
|
|
title=ugettext_lazy('Sorting'),
|
2014-10-11 14:34:49 +02:00
|
|
|
variables=(users_sort_users_by_first_name,))
|
2014-01-31 00:55:18 +01:00
|
|
|
|
|
|
|
# PDF
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_welcometitle = ConfigVariable(
|
|
|
|
name='users_pdf_welcometitle',
|
2013-10-23 23:47:25 +02:00
|
|
|
default_value=_('Welcome to OpenSlides!'),
|
2014-01-31 01:54:41 +01:00
|
|
|
translatable=True,
|
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')))
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_welcometext = ConfigVariable(
|
|
|
|
name='users_pdf_welcometext',
|
2013-10-23 23:47:25 +02:00
|
|
|
default_value=_('[Place for your welcome and help text.]'),
|
2014-01-31 01:54:41 +01:00
|
|
|
translatable=True,
|
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')))
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_url = ConfigVariable(
|
|
|
|
name='users_pdf_url',
|
2014-01-31 00:55:18 +01:00
|
|
|
default_value='http://example.com:8000',
|
|
|
|
form_field=forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
2013-03-01 17:13:12 +01:00
|
|
|
required=False,
|
2014-01-31 00:55:18 +01:00
|
|
|
label=ugettext_lazy('System URL'),
|
|
|
|
help_text=ugettext_lazy('Used for QRCode in PDF of access data.')))
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_wlan_ssid = ConfigVariable(
|
|
|
|
name='users_pdf_wlan_ssid',
|
2014-01-31 00:55:18 +01:00
|
|
|
default_value='',
|
|
|
|
form_field=forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
|
|
|
required=False,
|
|
|
|
label=ugettext_lazy('WLAN name (SSID)'),
|
|
|
|
help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.')))
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_wlan_password = ConfigVariable(
|
|
|
|
name='users_pdf_wlan_password',
|
2014-01-31 00:55:18 +01:00
|
|
|
default_value='',
|
|
|
|
form_field=forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
|
|
|
required=False,
|
|
|
|
label=ugettext_lazy('WLAN password'),
|
|
|
|
help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.')))
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
users_pdf_wlan_encryption = ConfigVariable(
|
|
|
|
name='users_pdf_wlan_encryption',
|
2014-01-31 00:55:18 +01:00
|
|
|
default_value='',
|
|
|
|
form_field=forms.ChoiceField(
|
|
|
|
widget=forms.Select(),
|
|
|
|
required=False,
|
|
|
|
label=ugettext_lazy('WLAN encryption'),
|
|
|
|
help_text=ugettext_lazy('Used for WLAN QRCode in PDF of access data.'),
|
|
|
|
choices=(
|
|
|
|
('', '---------'),
|
|
|
|
('WEP', 'WEP'),
|
|
|
|
('WPA', 'WPA/WPA2'),
|
|
|
|
('nopass', ugettext_lazy('No encryption')))))
|
|
|
|
|
|
|
|
group_pdf = ConfigGroup(
|
|
|
|
title=ugettext_lazy('PDF'),
|
2014-10-11 14:34:49 +02:00
|
|
|
variables=(users_pdf_welcometitle,
|
|
|
|
users_pdf_welcometext,
|
|
|
|
users_pdf_url,
|
|
|
|
users_pdf_wlan_ssid,
|
|
|
|
users_pdf_wlan_password,
|
|
|
|
users_pdf_wlan_encryption))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2014-01-31 00:55:18 +01:00
|
|
|
return ConfigGroupedCollection(
|
2014-10-11 14:34:49 +02:00
|
|
|
title=ugettext_noop('Users'),
|
|
|
|
url='users',
|
2014-01-31 00:55:18 +01:00
|
|
|
weight=50,
|
|
|
|
groups=(group_general, group_pdf))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
|
|
|
2015-02-12 20:57:05 +01:00
|
|
|
def create_builtin_groups_and_admin(**kwargs):
|
2014-11-13 22:23:16 +01:00
|
|
|
"""
|
2015-02-12 20:57:05 +01:00
|
|
|
Creates the builtin groups: Anonymous, Registered, Delegates and Staff.
|
|
|
|
|
|
|
|
Creates the builtin user: admin.
|
2014-11-13 22:23:16 +01:00
|
|
|
"""
|
2015-02-12 20:57:05 +01:00
|
|
|
# Check whether the group pks 1 to 4 are free
|
|
|
|
if Group.objects.filter(pk__in=range(1, 5)).exists():
|
|
|
|
# Do completely nothing if there are already some of our groups in the database.
|
2014-10-11 14:34:49 +02:00
|
|
|
return
|
|
|
|
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_strings = (
|
|
|
|
'agenda.can_be_speaker',
|
2015-03-26 05:36:10 +01:00
|
|
|
'agenda.can_manage',
|
|
|
|
'agenda.can_see',
|
2015-02-18 15:58:12 +01:00
|
|
|
'agenda.can_see_orga_items',
|
2015-03-26 05:36:10 +01:00
|
|
|
'assignments.can_manage',
|
|
|
|
'assignments.can_nominate_other',
|
|
|
|
'assignments.can_nominate_self',
|
|
|
|
'assignments.can_see',
|
2015-02-18 15:58:12 +01:00
|
|
|
'config.can_manage',
|
|
|
|
'core.can_manage_projector',
|
|
|
|
'core.can_manage_tags',
|
|
|
|
'core.can_see_dashboard',
|
|
|
|
'core.can_see_projector',
|
|
|
|
'core.can_use_chat',
|
2015-03-26 05:36:10 +01:00
|
|
|
'mediafiles.can_manage',
|
|
|
|
'mediafiles.can_see',
|
|
|
|
'mediafiles.can_upload',
|
|
|
|
'motions.can_create',
|
|
|
|
'motions.can_manage',
|
|
|
|
'motions.can_see',
|
|
|
|
'motions.can_support',
|
2015-02-18 15:58:12 +01:00
|
|
|
'users.can_manage',
|
|
|
|
'users.can_see_extra_data',
|
|
|
|
'users.can_see_name', )
|
|
|
|
permission_dict = {}
|
|
|
|
permission_query = Q()
|
|
|
|
|
|
|
|
for permission_string in permission_strings:
|
|
|
|
app_label, codename = permission_string.split('.')
|
|
|
|
query_part = Q(content_type__app_label=app_label) & Q(codename=codename)
|
|
|
|
permission_query = permission_query | query_part
|
|
|
|
for permission in Permission.objects.select_related('content_type').filter(permission_query):
|
|
|
|
permission_string = '.'.join((permission.content_type.app_label, permission.codename))
|
|
|
|
permission_dict[permission_string] = permission
|
2015-02-12 20:57:05 +01:00
|
|
|
|
2015-02-18 15:58:12 +01:00
|
|
|
# Anonymous (pk 1) and Registered (pk 2)
|
|
|
|
base_permissions = (
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['agenda.can_see'],
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_dict['agenda.can_see_orga_items'],
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['assignments.can_see'],
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_dict['core.can_see_dashboard'],
|
|
|
|
permission_dict['core.can_see_projector'],
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['mediafiles.can_see'],
|
|
|
|
permission_dict['motions.can_see'],
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_dict['users.can_see_extra_data'],
|
|
|
|
permission_dict['users.can_see_name'], )
|
2015-02-12 20:57:05 +01:00
|
|
|
group_anonymous = Group.objects.create(name=ugettext_noop('Anonymous'), pk=1)
|
2015-02-18 15:58:12 +01:00
|
|
|
group_anonymous.permissions.add(*base_permissions)
|
2015-02-12 20:57:05 +01:00
|
|
|
group_registered = Group.objects.create(name=ugettext_noop('Registered'), pk=2)
|
2015-02-18 15:58:12 +01:00
|
|
|
group_registered.permissions.add(
|
|
|
|
permission_dict['agenda.can_be_speaker'],
|
|
|
|
*base_permissions)
|
2015-02-12 20:57:05 +01:00
|
|
|
|
|
|
|
# Delegates (pk 3)
|
2015-02-18 15:58:12 +01:00
|
|
|
delegates_permissions = (
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['assignments.can_nominate_other'],
|
|
|
|
permission_dict['assignments.can_nominate_self'],
|
|
|
|
permission_dict['mediafiles.can_upload'],
|
|
|
|
permission_dict['motions.can_create'],
|
|
|
|
permission_dict['motions.can_support'], )
|
2015-02-12 20:57:05 +01:00
|
|
|
group_delegates = Group.objects.create(name=ugettext_noop('Delegates'), pk=3)
|
2015-02-18 15:58:12 +01:00
|
|
|
group_delegates.permissions.add(*delegates_permissions)
|
2015-02-12 20:57:05 +01:00
|
|
|
|
|
|
|
# Staff (pk 4)
|
2015-02-18 15:58:12 +01:00
|
|
|
staff_permissions = (
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['agenda.can_manage'],
|
|
|
|
permission_dict['assignments.can_manage'],
|
|
|
|
permission_dict['assignments.can_nominate_other'],
|
|
|
|
permission_dict['assignments.can_nominate_self'],
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_dict['config.can_manage'],
|
|
|
|
permission_dict['core.can_manage_projector'],
|
|
|
|
permission_dict['core.can_manage_tags'],
|
|
|
|
permission_dict['core.can_use_chat'],
|
2015-03-26 05:36:10 +01:00
|
|
|
permission_dict['mediafiles.can_manage'],
|
|
|
|
permission_dict['mediafiles.can_upload'],
|
|
|
|
permission_dict['motions.can_create'],
|
|
|
|
permission_dict['motions.can_manage'],
|
2015-02-18 15:58:12 +01:00
|
|
|
permission_dict['users.can_manage'], )
|
2015-02-12 20:57:05 +01:00
|
|
|
group_staff = Group.objects.create(name=ugettext_noop('Staff'), pk=4)
|
2015-02-18 15:58:12 +01:00
|
|
|
group_staff.permissions.add(*staff_permissions)
|
|
|
|
|
|
|
|
# Add users.can_see_name and users.can_see_extra_data permissions
|
2015-02-12 20:57:05 +01:00
|
|
|
# TODO: Remove this redundancy after cleanup of the permission system.
|
2015-02-18 15:58:12 +01:00
|
|
|
group_staff.permissions.add(
|
|
|
|
permission_dict['users.can_see_extra_data'],
|
|
|
|
permission_dict['users.can_see_name'])
|
2015-02-12 20:57:05 +01:00
|
|
|
|
|
|
|
# Admin user
|
|
|
|
User.objects.create_or_reset_admin_user()
|