update migrations; management command that creates default group with default perms; add new users to default group

This commit is contained in:
Jan Koppe 2020-05-01 15:05:26 +02:00
parent 369bbf042c
commit 020393c48b
Signed by: thunfisch
GPG Key ID: BE935B0735A2129B
7 changed files with 119 additions and 0 deletions

0
core/__init__.py Normal file
View File

10
core/apps.py Normal file
View File

@ -0,0 +1,10 @@
from django.apps import AppConfig
class CoreConfig(AppConfig):
name = 'core'
def ready(self):
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from portier.common import handlers
post_save.connect(handlers.add_to_default_group, sender=User)

View File

@ -0,0 +1,24 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission
from django.conf import settings
PERMISSIONS = [
'add_stream',
'add_restreamconfig'
]
class Command(BaseCommand):
help = 'Creates default user group with default permissions available to all users'
def handle(self, *args, **options):
default_group, _ = Group.objects.get_or_create(name=settings.DEFAULT_GROUP)
for permission in PERMISSIONS:
try:
perm = Permission.objects.get(codename=permission)
except Permission.DoesNotExist:
print("permission '%s' does not exist" % permission)
continue
default_group.permissions.add(perm)

View File

@ -2,6 +2,15 @@ from django.contrib.contenttypes.models import ContentType
from django.db.models import Q from django.db.models import Q
from guardian.models import UserObjectPermission from guardian.models import UserObjectPermission
from guardian.models import GroupObjectPermission from guardian.models import GroupObjectPermission
from django.contrib.auth.models import User, Group
from django.conf import settings
def add_to_default_group(sender, **kwargs):
user = kwargs["instance"]
if kwargs["created"]:
group = Group.objects.get(name=settings.DEFAULT_GROUP)
user.groups.add(group)
def remove_obj_perms_connected_with_user(sender, instance, **kwargs): def remove_obj_perms_connected_with_user(sender, instance, **kwargs):

View File

@ -27,6 +27,8 @@ DEBUG = int(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="*").split(" ") ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="*").split(" ")
DEFAULT_GROUP = 'default'
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
@ -40,6 +42,7 @@ INSTALLED_APPS = [
'django_registration', 'django_registration',
'bootstrap4', 'bootstrap4',
'fa', 'fa',
'core.apps.CoreConfig',
'portal.apps.PortalConfig', 'portal.apps.PortalConfig',
'rtmp.apps.RtmpConfig', 'rtmp.apps.RtmpConfig',
'concierge.apps.ConciergeConfig', 'concierge.apps.ConciergeConfig',

View File

@ -0,0 +1,39 @@
# Generated by Django 3.0.5 on 2020-05-01 13:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('rtmp', '0004_auto_20200501_1302'),
('restream', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='restreamconfig',
options={'verbose_name': 'restreamconfig_verbose_name', 'verbose_name_plural': 'restreamconfig_verbose_name_plural'},
),
migrations.AlterField(
model_name='restreamconfig',
name='active',
field=models.BooleanField(help_text='restreamconfig_activate_help'),
),
migrations.AlterField(
model_name='restreamconfig',
name='name',
field=models.CharField(help_text='restreamconfig_name_help', max_length=100),
),
migrations.AlterField(
model_name='restreamconfig',
name='stream',
field=models.ForeignKey(help_text='restreamconfig_stream_help', on_delete=django.db.models.deletion.CASCADE, to='rtmp.Stream'),
),
migrations.AlterField(
model_name='restreamconfig',
name='target',
field=models.CharField(help_text='restreamconfig_target_help', max_length=500),
),
]

View File

@ -0,0 +1,34 @@
# Generated by Django 3.0.5 on 2020-05-01 13:02
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('rtmp', '0003_auto_20200426_1834'),
]
operations = [
migrations.AlterModelOptions(
name='application',
options={'verbose_name': 'application_verbose_name', 'verbose_name_plural': 'application_verbose_name_plural'},
),
migrations.AlterField(
model_name='stream',
name='application',
field=models.ForeignKey(help_text='stream_application_help', on_delete=django.db.models.deletion.CASCADE, to='rtmp.Application'),
),
migrations.AlterField(
model_name='stream',
name='name',
field=models.CharField(help_text='stream_name_help', max_length=100),
),
migrations.AlterField(
model_name='stream',
name='stream',
field=models.UUIDField(default=uuid.uuid4, help_text='stream_stream_help', unique=True),
),
]