Add permissions for user groups
Resolves MS-629 #complete
This commit is contained in:
parent
8c74bba204
commit
d18b21e466
|
|
@ -44,32 +44,26 @@ def duplicate_entities_generator(new_module):
|
|||
logger.debug(block)
|
||||
if content_type == "assignment":
|
||||
assignment = value.get("assignment_id")
|
||||
# copy the assignment
|
||||
assignment.pk = None
|
||||
assignment.title = f"{assignment.title} (Kopie)"
|
||||
assignment.module = new_module
|
||||
logger.debug(f"setting new module {new_module}, {assignment.module}")
|
||||
assignment.save()
|
||||
block = AssignmentBlock()
|
||||
data = {"assignment_id": assignment.pk}
|
||||
value = block.to_python(data)
|
||||
cleaned_value = block.clean(value)
|
||||
new_block = ("assignment", cleaned_value)
|
||||
logger.debug(new_block)
|
||||
data = {"assignment_id": assignment}
|
||||
new_block = ("assignment", data)
|
||||
return new_block
|
||||
if content_type == "survey":
|
||||
logger.debug(value)
|
||||
survey = value.get("survey_id")
|
||||
# copy the survey
|
||||
survey.pk = None
|
||||
survey.title = f"{survey.title} (Kopie)"
|
||||
survey.module = new_module
|
||||
logger.debug(f"setting new module {new_module}, {survey.module}")
|
||||
survey.save()
|
||||
block = SurveyBlock()
|
||||
data = {"survey_id": survey.pk}
|
||||
value = block.to_python(data)
|
||||
cleaned_value = block.clean(value)
|
||||
new_block = ("survey", cleaned_value)
|
||||
# logger.debug(new_block)
|
||||
data = {"survey_id": survey}
|
||||
new_block = ("survey", data)
|
||||
logger.debug(new_block)
|
||||
return new_block
|
||||
return block
|
||||
|
|
|
|||
|
|
@ -1,19 +1,50 @@
|
|||
# Generated by Django 3.2.16 on 2023-03-09 17:14
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.db import migrations
|
||||
|
||||
news = []
|
||||
support = []
|
||||
cms_editors = []
|
||||
"""
|
||||
CMS-Editors:
|
||||
Wagtail: Alle Rechte
|
||||
Django: Bereich «Lernziele»
|
||||
|
||||
Support:
|
||||
Django: Bereich «User»
|
||||
|
||||
News:
|
||||
Django: Bereich «News»
|
||||
|
||||
"""
|
||||
|
||||
news = ["news"]
|
||||
support = ["users", "auth"]
|
||||
cms_editors = [
|
||||
"objectives",
|
||||
"wagtailcore",
|
||||
"wagtailimages",
|
||||
"wagtailembeds",
|
||||
"wagtailredirects",
|
||||
"wagtailsearch",
|
||||
"wagtailusers",
|
||||
"wagtaildocs",
|
||||
]
|
||||
|
||||
groups = [("News", news), ("CMS-Editors", cms_editors), ("Support", support)]
|
||||
|
||||
for permission in Permission.objects.filter(content_type__app_label='news') #etc
|
||||
|
||||
def add_permissions(apps, schema_editor):
|
||||
for name, app_labels in groups:
|
||||
group, _ = Group.objects.get_or_create(name=name)
|
||||
for app_label in app_labels:
|
||||
for permission in Permission.objects.filter(
|
||||
content_type__app_label=app_label
|
||||
):
|
||||
group.permissions.add(permission)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("core", "0002_delete_admindata"),
|
||||
]
|
||||
|
||||
operations = []
|
||||
operations = [migrations.RunPython(add_permissions)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.2.16 on 2023-03-13 15:19
|
||||
|
||||
from django.db import migrations
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
|
||||
def delete_old_group(apps, schema_editor):
|
||||
try:
|
||||
group = Group.objects.get(name="Altes CMS")
|
||||
group.delete()
|
||||
except Group.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0003_auto_20230309_1714"),
|
||||
]
|
||||
|
||||
operations = [migrations.RunPython(delete_old_group)]
|
||||
Loading…
Reference in New Issue