diff --git a/mandelstudio/migrations/0007_remove_contactmessage_permissions_from_editors.py b/mandelstudio/migrations/0007_remove_contactmessage_permissions_from_editors.py new file mode 100644 index 0000000..45bdb0f --- /dev/null +++ b/mandelstudio/migrations/0007_remove_contactmessage_permissions_from_editors.py @@ -0,0 +1,40 @@ +from django.db import migrations + + +def remove_contactmessage_permissions_from_editors(apps, schema_editor): + Group = apps.get_model("auth", "Group") + Permission = apps.get_model("auth", "Permission") + ContentType = apps.get_model("contenttypes", "ContentType") + + try: + group = Group.objects.get(name="Editors") + except Group.DoesNotExist: + return + + content_type = ContentType.objects.get(app_label="mandelstudio", model="contactmessage") + perms = Permission.objects.filter( + content_type=content_type, + codename__in=[ + "add_contactmessage", + "change_contactmessage", + "delete_contactmessage", + "view_contactmessage", + ], + ) + group.permissions.remove(*perms) + + +class Migration(migrations.Migration): + dependencies = [ + ("mandelstudio", "0006_grant_contactmessage_permissions_to_staff"), + ("contenttypes", "0002_remove_content_type_name"), + ("auth", "0012_alter_user_first_name_max_length"), + ] + + operations = [ + migrations.RunPython( + remove_contactmessage_permissions_from_editors, + reverse_code=migrations.RunPython.noop, + ), + ] +