2020-05-01 15:05:26 +02:00
|
|
|
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',
|
2024-04-22 14:25:15 +02:00
|
|
|
'add_restream',
|
|
|
|
'add_pull',
|
2020-05-01 15:05:26 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
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)
|