1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-01-12 08:25:18 +00:00
webvirtcloud/instances/migrations/0003_migrate_can_clone_instances.py
Real-Gecko 3d0493537f Added 'instances:clone_instances' permission
Replaces 'can_clone_instances' user attribute
2020-05-28 11:20:23 +06:00

35 lines
922 B
Python

from django.db import migrations
def migrate_can_clone_instances(apps, schema_editor):
from django.contrib.auth.models import User, Permission
user: User
users = User.objects.all()
permission = Permission.objects.get(codename='clone_instances')
for user in users:
if user.userattributes.can_clone_instances:
user.user_permissions.add(permission)
def reverse_can_clone_instances(apps, schema_editor):
from django.contrib.auth.models import User, Permission
user: User
users = User.objects.all()
permission = Permission.objects.get(codename='clone_instances')
for user in users:
user.user_permissions.remove(permission)
class Migration(migrations.Migration):
dependencies = [
('instances', '0002_permissionset'),
]
operations = [
migrations.RunPython(migrate_can_clone_instances, reverse_can_clone_instances),
]