Grant ContactMessage snippet perms to Editors
This commit is contained in:
@@ -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,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
Reference in New Issue
Block a user