Grant ContactMessage perms to staff users
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def grant_contactmessage_permissions_to_staff(apps, schema_editor):
|
||||||
|
Permission = apps.get_model("auth", "Permission")
|
||||||
|
ContentType = apps.get_model("contenttypes", "ContentType")
|
||||||
|
|
||||||
|
# Default Django user model in this project.
|
||||||
|
User = apps.get_model("auth", "User")
|
||||||
|
|
||||||
|
content_type = ContentType.objects.get(app_label="mandelstudio", model="contactmessage")
|
||||||
|
perms = list(
|
||||||
|
Permission.objects.filter(
|
||||||
|
content_type=content_type,
|
||||||
|
codename__in=[
|
||||||
|
"add_contactmessage",
|
||||||
|
"change_contactmessage",
|
||||||
|
"delete_contactmessage",
|
||||||
|
"view_contactmessage",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not perms:
|
||||||
|
return
|
||||||
|
|
||||||
|
for user in User.objects.filter(is_staff=True, is_active=True).iterator():
|
||||||
|
user.user_permissions.add(*perms)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("mandelstudio", "0005_grant_contactmessage_permissions"),
|
||||||
|
("contenttypes", "0002_remove_content_type_name"),
|
||||||
|
("auth", "0012_alter_user_first_name_max_length"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
grant_contactmessage_permissions_to_staff,
|
||||||
|
reverse_code=migrations.RunPython.noop,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
Reference in New Issue
Block a user