From 530d9c5eb7322ca54386a29e4c999bb70a4b40d4 Mon Sep 17 00:00:00 2001 From: Mandel Olaiya Date: Sat, 9 May 2026 16:55:14 +0200 Subject: [PATCH] Grant ContactMessage snippet perms to Editors --- .../0005_grant_contactmessage_permissions.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mandelstudio/migrations/0005_grant_contactmessage_permissions.py diff --git a/mandelstudio/migrations/0005_grant_contactmessage_permissions.py b/mandelstudio/migrations/0005_grant_contactmessage_permissions.py new file mode 100644 index 0000000..ebce4e5 --- /dev/null +++ b/mandelstudio/migrations/0005_grant_contactmessage_permissions.py @@ -0,0 +1,40 @@ +from django.db import migrations + + +def grant_contactmessage_permissions(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.add(*perms) + + +class Migration(migrations.Migration): + dependencies = [ + ("mandelstudio", "0004_contact_messages"), + ("contenttypes", "0002_remove_content_type_name"), + ("auth", "0012_alter_user_first_name_max_length"), + ] + + operations = [ + migrations.RunPython( + grant_contactmessage_permissions, + reverse_code=migrations.RunPython.noop, + ), + ] +