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)
|
logger.debug(block)
|
||||||
if content_type == "assignment":
|
if content_type == "assignment":
|
||||||
assignment = value.get("assignment_id")
|
assignment = value.get("assignment_id")
|
||||||
|
# copy the assignment
|
||||||
assignment.pk = None
|
assignment.pk = None
|
||||||
assignment.title = f"{assignment.title} (Kopie)"
|
assignment.title = f"{assignment.title} (Kopie)"
|
||||||
assignment.module = new_module
|
assignment.module = new_module
|
||||||
logger.debug(f"setting new module {new_module}, {assignment.module}")
|
logger.debug(f"setting new module {new_module}, {assignment.module}")
|
||||||
assignment.save()
|
assignment.save()
|
||||||
block = AssignmentBlock()
|
data = {"assignment_id": assignment}
|
||||||
data = {"assignment_id": assignment.pk}
|
new_block = ("assignment", data)
|
||||||
value = block.to_python(data)
|
|
||||||
cleaned_value = block.clean(value)
|
|
||||||
new_block = ("assignment", cleaned_value)
|
|
||||||
logger.debug(new_block)
|
|
||||||
return new_block
|
return new_block
|
||||||
if content_type == "survey":
|
if content_type == "survey":
|
||||||
logger.debug(value)
|
logger.debug(value)
|
||||||
survey = value.get("survey_id")
|
survey = value.get("survey_id")
|
||||||
|
# copy the survey
|
||||||
survey.pk = None
|
survey.pk = None
|
||||||
survey.title = f"{survey.title} (Kopie)"
|
survey.title = f"{survey.title} (Kopie)"
|
||||||
survey.module = new_module
|
survey.module = new_module
|
||||||
logger.debug(f"setting new module {new_module}, {survey.module}")
|
logger.debug(f"setting new module {new_module}, {survey.module}")
|
||||||
survey.save()
|
survey.save()
|
||||||
block = SurveyBlock()
|
data = {"survey_id": survey}
|
||||||
data = {"survey_id": survey.pk}
|
new_block = ("survey", data)
|
||||||
value = block.to_python(data)
|
|
||||||
cleaned_value = block.clean(value)
|
|
||||||
new_block = ("survey", cleaned_value)
|
|
||||||
# logger.debug(new_block)
|
|
||||||
logger.debug(new_block)
|
logger.debug(new_block)
|
||||||
return new_block
|
return new_block
|
||||||
return block
|
return block
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,50 @@
|
||||||
# Generated by Django 3.2.16 on 2023-03-09 17:14
|
# 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
|
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)]
|
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):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
("core", "0002_delete_admindata"),
|
("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