Move builtin groups to a signal.
This commit is contained in:
parent
514577f7c6
commit
9679be1867
@ -22,9 +22,6 @@ from openslides.utils.views import FormView, TemplateView
|
|||||||
from .forms import GeneralConfigForm
|
from .forms import GeneralConfigForm
|
||||||
from .models import config
|
from .models import config
|
||||||
|
|
||||||
# TODO: Do not import the participant module in config
|
|
||||||
from openslides.participant.api import get_or_create_anonymous_group
|
|
||||||
|
|
||||||
|
|
||||||
class GeneralConfig(FormView):
|
class GeneralConfig(FormView):
|
||||||
"""
|
"""
|
||||||
@ -62,7 +59,6 @@ class GeneralConfig(FormView):
|
|||||||
# system
|
# system
|
||||||
if form.cleaned_data['system_enable_anonymous']:
|
if form.cleaned_data['system_enable_anonymous']:
|
||||||
config['system_enable_anonymous'] = True
|
config['system_enable_anonymous'] = True
|
||||||
get_or_create_anonymous_group()
|
|
||||||
else:
|
else:
|
||||||
config['system_enable_anonymous'] = False
|
config['system_enable_anonymous'] = False
|
||||||
|
|
||||||
|
@ -271,7 +271,6 @@ def run_syncdb():
|
|||||||
# now initialize the database
|
# now initialize the database
|
||||||
argv = ["", "syncdb", "--noinput"]
|
argv = ["", "syncdb", "--noinput"]
|
||||||
execute_from_command_line(argv)
|
execute_from_command_line(argv)
|
||||||
execute_from_command_line(["", "loaddata", "groups_de"])
|
|
||||||
|
|
||||||
|
|
||||||
def set_system_url(url):
|
def set_system_url(url):
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
openslides.participant
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The OpenSlides participant app.
|
||||||
|
|
||||||
|
:copyright: (c) 2011-2013 by the OpenSlides team, see AUTHORS.
|
||||||
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext_noop
|
from django.utils.translation import ugettext_noop
|
||||||
|
|
||||||
|
import openslides.participant.signals
|
||||||
|
|
||||||
|
|
||||||
NAME = ugettext_noop('Participant')
|
NAME = ugettext_noop('Participant')
|
||||||
|
@ -97,21 +97,8 @@ def import_users(csv_file):
|
|||||||
return (count_success, error_messages)
|
return (count_success, error_messages)
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_registered_group():
|
def get_registered_group():
|
||||||
registered, created = Group.objects.get_or_create(
|
"""
|
||||||
name__iexact='Registered', defaults={'name': 'Registered'})
|
Returns the Group 'Registered'. Upper and lower case is possible.
|
||||||
if created:
|
"""
|
||||||
registered.permissions = Permission.objects.filter(
|
return Group.objects.get(name__iexact='Registered')
|
||||||
codename__in=DEFAULT_PERMS)
|
|
||||||
registered.save()
|
|
||||||
return registered
|
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_anonymous_group():
|
|
||||||
anonymous, created = Group.objects.get_or_create(
|
|
||||||
name__iexact='Anonymous', defaults={'name': 'Anonymous'})
|
|
||||||
if created:
|
|
||||||
anonymous.permissions = Permission.objects.filter(
|
|
||||||
codename__in=DEFAULT_PERMS)
|
|
||||||
anonymous.save()
|
|
||||||
return anonymous
|
|
||||||
|
@ -1,233 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"pk": 1,
|
|
||||||
"model": "auth.group",
|
|
||||||
"fields": {
|
|
||||||
"name": "Beobachter/in",
|
|
||||||
"permissions": [
|
|
||||||
[
|
|
||||||
"can_see_agenda",
|
|
||||||
"agenda",
|
|
||||||
"item"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_create_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_other",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_self",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_assignment",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_projector",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_dashboard",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pk": 2,
|
|
||||||
"model": "auth.group",
|
|
||||||
"fields": {
|
|
||||||
"name": "Delegierte/r",
|
|
||||||
"permissions": [
|
|
||||||
[
|
|
||||||
"can_see_agenda",
|
|
||||||
"agenda",
|
|
||||||
"item"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_create_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_support_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_other",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_self",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_assignment",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_projector",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_dashboard",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pk": 3,
|
|
||||||
"model": "auth.group",
|
|
||||||
"fields": {
|
|
||||||
"name": "Versammlungsleitung",
|
|
||||||
"permissions": [
|
|
||||||
[
|
|
||||||
"can_manage_agenda",
|
|
||||||
"agenda",
|
|
||||||
"item"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_agenda",
|
|
||||||
"agenda",
|
|
||||||
"item"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_create_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_motion",
|
|
||||||
"motion",
|
|
||||||
"motion"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_assignment",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_other",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_nominate_self",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_assignment",
|
|
||||||
"assignment",
|
|
||||||
"assignment"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_config",
|
|
||||||
"config",
|
|
||||||
"configstore"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_projector",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_projector",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_dashboard",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pk": 4,
|
|
||||||
"model": "auth.group",
|
|
||||||
"fields": {
|
|
||||||
"name": "Teilnehmerverwaltung",
|
|
||||||
"permissions": [
|
|
||||||
[
|
|
||||||
"can_see_agenda",
|
|
||||||
"agenda",
|
|
||||||
"item"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_manage_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_participant",
|
|
||||||
"participant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_projector",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"can_see_dashboard",
|
|
||||||
"projector",
|
|
||||||
"projectorslide"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
@ -19,7 +19,7 @@ from openslides.utils.forms import (
|
|||||||
CssClassMixin, LocalizedModelMultipleChoiceField)
|
CssClassMixin, LocalizedModelMultipleChoiceField)
|
||||||
|
|
||||||
from openslides.participant.models import User, Group
|
from openslides.participant.models import User, Group
|
||||||
from openslides.participant.api import get_or_create_registered_group
|
from openslides.participant.api import get_registered_group
|
||||||
|
|
||||||
|
|
||||||
class UserCreateForm(forms.ModelForm, CssClassMixin):
|
class UserCreateForm(forms.ModelForm, CssClassMixin):
|
||||||
@ -30,7 +30,7 @@ class UserCreateForm(forms.ModelForm, CssClassMixin):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if kwargs.get('instance', None) is None:
|
if kwargs.get('instance', None) is None:
|
||||||
initial = kwargs.setdefault('initial', {})
|
initial = kwargs.setdefault('initial', {})
|
||||||
registered = get_or_create_registered_group()
|
registered = get_registered_group()
|
||||||
initial['groups'] = [registered.pk]
|
initial['groups'] = [registered.pk]
|
||||||
super(UserCreateForm, self).__init__(*args, **kwargs)
|
super(UserCreateForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -257,9 +257,9 @@ def djangogroup_post_save(sender, instance, signal, *args, **kwargs):
|
|||||||
|
|
||||||
@receiver(signals.post_save, sender=User)
|
@receiver(signals.post_save, sender=User)
|
||||||
def user_post_save(sender, instance, *args, **kwargs):
|
def user_post_save(sender, instance, *args, **kwargs):
|
||||||
from openslides.participant.api import get_or_create_registered_group
|
|
||||||
if not kwargs['created']:
|
if not kwargs['created']:
|
||||||
return
|
return
|
||||||
registered = get_or_create_registered_group()
|
from openslides.participant.api import get_registered_group # TODO: Test, if global import is possible
|
||||||
|
registered = get_registered_group()
|
||||||
instance.groups.add(registered)
|
instance.groups.add(registered)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
70
openslides/participant/signals.py
Normal file
70
openslides/participant/signals.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
openslides.participant.signals
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Signals for the participant app.
|
||||||
|
|
||||||
|
:copyright: (c) 2011-2013 by the OpenSlides team, see AUTHORS.
|
||||||
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django.utils.translation import ugettext_noop
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
|
from openslides.core.signals import post_database_setup
|
||||||
|
|
||||||
|
from .models import Group
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_database_setup, dispatch_uid='participant_create_builtin_groups')
|
||||||
|
def create_builtin_groups(sender, **kwargs):
|
||||||
|
"""
|
||||||
|
Creates the builtin groups: Anonymous, Registered, Delegates and Staff.
|
||||||
|
"""
|
||||||
|
# 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')
|
||||||
|
perm_3 = Permission.objects.get(content_type=ct_agenda, codename='can_see_agenda')
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
group_anonymous = Group.objects.create(name=ugettext_noop('Anonymous'))
|
||||||
|
group_anonymous.permissions.add(perm_1, perm_2, perm_3, perm_4, perm_5, perm_6)
|
||||||
|
group_registered = Group.objects.create(name=ugettext_noop('Registered'))
|
||||||
|
group_registered.permissions.add(perm_1, perm_2, perm_3, perm_4, perm_5, perm_6)
|
||||||
|
|
||||||
|
# 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')
|
||||||
|
|
||||||
|
group_delegates = Group.objects.create(name=ugettext_noop('Delegates'))
|
||||||
|
group_delegates.permissions.add(perm_7, perm_8, perm_9, perm_10)
|
||||||
|
|
||||||
|
# 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')
|
||||||
|
|
||||||
|
ct_config = ContentType.objects.get(app_label='config', model='configstore')
|
||||||
|
perm_16 = Permission.objects.get(content_type=ct_config, codename='can_manage_config')
|
||||||
|
|
||||||
|
group_staff = Group.objects.create(name=ugettext_noop('Staff'))
|
||||||
|
group_staff.permissions.add(perm_7, perm_9, perm_10, perm_11, perm_12, perm_13, perm_14, perm_15, perm_16)
|
Loading…
Reference in New Issue
Block a user