From f8f1b4f26b7ed7a14144e9723850e691e45fdd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 31 Mar 2017 11:49:21 +0200 Subject: [PATCH] grandlyon: script to add all technical admin roles to "Administrateur " --- grandlyon/scripts/mark-admin-roles.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 grandlyon/scripts/mark-admin-roles.py diff --git a/grandlyon/scripts/mark-admin-roles.py b/grandlyon/scripts/mark-admin-roles.py new file mode 100644 index 0000000..7ef9f7a --- /dev/null +++ b/grandlyon/scripts/mark-admin-roles.py @@ -0,0 +1,24 @@ +# add all collectivity technical admin roles to "Administrateur " + +# authentic2-multitenant-manage tenant_command runscript -d connexion.guichet-recette.grandlyon.com ~tma/misc-fred/grandlyon/scripts/mark-admin-roles.py + +import os +import json +import sys + +from django.db.models.query import Q + +from django_rbac.utils import get_role_model, get_ou_model + +Ou = get_ou_model() +Role = get_role_model() + +communes_json = os.path.join(os.path.dirname(__file__), 'communes.json') + +for dest in json.load(open(communes_json))['dests']: + ou = Ou.objects.get(name=dest['name']) + role = Role.objects.get(name=u'Administrateur %s' % dest['name']) + for subrole in Role.objects.filter(Q(slug='_a2-hobo-superuser', ou=ou) | + Q(slug__startswith='administrateur-fonc', ou=ou) | + Q(slug__startswith='_a2-administrateur', ou=ou)): + role.add_parent(subrole)