2018-01-06 23:33:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Generated by Django 1.10.7 on 2017-12-31 19:53
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
dependencies = [("users", "0066_grouppermissions")]
|
2018-01-06 23:33:52 +00:00
|
|
|
|
|
|
|
def transfer_permissions(apps, schema_editor):
|
|
|
|
db_alias = schema_editor.connection.alias
|
2019-11-04 16:55:03 +00:00
|
|
|
contenttype = apps.get_model("contenttypes", "ContentType")
|
2018-01-06 23:33:52 +00:00
|
|
|
rights = apps.get_model("users", "ListRight")
|
|
|
|
permissions = apps.get_model("auth", "Permission")
|
|
|
|
groups = apps.get_model("auth", "Group")
|
|
|
|
machine = apps.get_model("machines", "Machine")
|
2019-11-04 16:55:03 +00:00
|
|
|
perm = permissions.objects.using(db_alias).filter(codename="serveur").first()
|
2018-01-06 23:33:52 +00:00
|
|
|
if not perm:
|
|
|
|
perm = permissions.objects.using(db_alias).create(
|
2019-11-04 16:55:03 +00:00
|
|
|
codename="serveur",
|
|
|
|
name="Serveur",
|
|
|
|
content_type=contenttype.objects.get_for_model(machine),
|
2018-01-06 23:33:52 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
group_object = (
|
|
|
|
rights.objects.using(db_alias).filter(unix_name="serveur").first()
|
|
|
|
)
|
2018-01-06 23:33:52 +00:00
|
|
|
if not group_object:
|
2019-11-04 16:55:03 +00:00
|
|
|
last_gid = rights.objects.using(db_alias).all().order_by("gid").last().gid
|
2018-01-06 23:33:52 +00:00
|
|
|
gid = last_gid + 1
|
2019-11-04 16:55:03 +00:00
|
|
|
abstract_group = groups.objects.using(db_alias).create(name="serveur")
|
|
|
|
group_object = rights.objects.using(db_alias).create(
|
|
|
|
group_ptr=abstract_group, unix_name="serveur", gid=gid
|
|
|
|
)
|
2018-01-06 23:33:52 +00:00
|
|
|
group_object = group_object.group_ptr
|
|
|
|
group_object.permissions.add(perm)
|
|
|
|
group_object.save()
|
|
|
|
|
|
|
|
def untransfer_permissions(apps, schema_editor):
|
|
|
|
return
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
operations = [migrations.RunPython(transfer_permissions, untransfer_permissions)]
|