Skip to content
Snippets Groups Projects
Commit 2b22052d authored by Benoit Alessandroni's avatar Benoit Alessandroni
Browse files

Merge branch 'fix_migration' into 'master'

Fix migration

See merge request !57
parents 06055eda ead5c37f
No related branches found
No related tags found
1 merge request!57Fix migration
Pipeline #16484 passed
...@@ -5,11 +5,15 @@ from guardian.shortcuts import assign_perm ...@@ -5,11 +5,15 @@ from guardian.shortcuts import assign_perm
def create_group(apps, circle, field_name, permissions): def create_group(apps, circle, field_name, permissions):
Group = apps.get_model("auth", "Group") Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission") Permission = apps.get_model("auth", "Permission")
GroupObjectPermission = apps.get_model("guardian", "GroupObjectPermission")
ContentType = apps.get_model("contenttypes", "ContentType")
group = Group.objects.create(name=f'LDP_{circle._meta.model_name}_{field_name}_{circle.id}') group = Group.objects.create(name=f'LDP_{circle._meta.model_name}_{field_name}_{circle.id}')
setattr(circle, field_name, group) setattr(circle, field_name, group)
for perm_name in permissions: for perm_name in permissions:
perm = Permission.objects.get(content_type__app_label='djangoldp_circle', codename=f'{perm_name}_circle') ctype = ContentType.objects.get(model='circle')
group.permissions.add(perm) permission = Permission.objects.get(content_type=ctype, codename=f'{perm_name}_circle')
GroupObjectPermission.objects.get_or_create(permission=permission, group=group, content_type=ctype, object_pk=circle.pk)
def migrate_groups(apps, schema_editor): def migrate_groups(apps, schema_editor):
'''copies the members and admins of the circles into new groups''' '''copies the members and admins of the circles into new groups'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment