2024-04-14 11:23:35 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2024-04-12 20:23:49 +00:00
|
|
|
def _get_perms(permission_name_list):
|
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
permissions = []
|
|
|
|
for permission_name in permission_name_list:
|
2024-04-13 00:12:21 +00:00
|
|
|
try:
|
|
|
|
permission = Permission.objects.get(codename=permission_name)
|
|
|
|
permissions.append(permission)
|
|
|
|
except Permission.DoesNotExist:
|
2024-04-14 11:23:35 +00:00
|
|
|
logging.warning("Permissions not correctly migrated, please run the migration again")
|
2024-04-12 20:23:49 +00:00
|
|
|
return permissions
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_groups(sender, **kwargs):
|
|
|
|
from django.contrib.auth.models import Group
|
2024-04-13 00:12:21 +00:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
|
2024-04-12 20:23:49 +00:00
|
|
|
|
|
|
|
member_permissions = []
|
|
|
|
coordinator_permissions = ["create_active_adoption_notice"]
|
|
|
|
moderator_permissions = coordinator_permissions + ["view_report", "add_moderationaction", "change_user"]
|
|
|
|
admin_permissions = moderator_permissions
|
|
|
|
|
|
|
|
admins, created = Group.objects.get_or_create(name="Admins")
|
|
|
|
admins.permissions.set(_get_perms(admin_permissions))
|
|
|
|
|
|
|
|
moderators, created = Group.objects.get_or_create(name="Moderators")
|
|
|
|
moderators.permissions.set(_get_perms(moderator_permissions))
|
|
|
|
|
|
|
|
coordinators, created = Group.objects.get_or_create(name="Coordinators")
|
|
|
|
coordinators.permissions.set(_get_perms(coordinator_permissions))
|
|
|
|
|
|
|
|
members, created = Group.objects.get_or_create(name="Members")
|
|
|
|
members.permissions.set(_get_perms(member_permissions))
|
2024-04-14 11:23:35 +00:00
|
|
|
|
|
|
|
def ensure_languages(sender, **kwargs):
|
|
|
|
from fellchensammlung.models import Language
|
|
|
|
Language.objects.get_or_create(name="Deutsch", languagecode="de")
|
|
|
|
Language.objects.get_or_create(name="English", languagecode="en")
|