summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2020-05-15 14:03:43 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-05-15 14:03:43 (GMT)
commit62e93b441a366ece9b0b09ddd7bf96ee3ae7c092 (patch)
tree84b0d1992e1c8c9028fd280ad4095189c79f5a4c
parent0613710ef30bc542416495c4e896301e2098ca39 (diff)
downloadmisc-fred-62e93b441a366ece9b0b09ddd7bf96ee3ae7c092.zip
misc-fred-62e93b441a366ece9b0b09ddd7bf96ee3ae7c092.tar.gz
misc-fred-62e93b441a366ece9b0b09ddd7bf96ee3ae7c092.tar.bz2
grandlyon: make all roles inherit from agent
-rw-r--r--grandlyon/scripts/copy-roles.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/grandlyon/scripts/copy-roles.py b/grandlyon/scripts/copy-roles.py
index 3f9861d..45a6d40 100644
--- a/grandlyon/scripts/copy-roles.py
+++ b/grandlyon/scripts/copy-roles.py
@@ -9,19 +9,29 @@ Role = get_role_model()
mapping = {}
-name_src = sys.argv[1]
-name_dst = sys.argv[2]
+name_src = sys.argv[1].decode('utf-8')
+name_dst = sys.argv[2].decode('utf-8')
ou_src = Ou.objects.get(name=name_src)
ou = Ou.objects.get(name=name_dst)
+agent_role = None
+
for role in Role.objects.filter(ou=ou_src):
- if not (role.name.startswith('Gestionnaire') or role.name.startswith('Administrateur')):
- continue
+ #if not (role.name.startswith('Gestionnaire') or role.name.startswith('Administrateur')):
+ # continue
if role.slug.startswith('_'):
continue
new_name = role.name.replace(name_src, name_dst).replace(name_src.lower(), name_dst.lower())
new_role, created = Role.objects.get_or_create(ou=ou, name=new_name)
mapping[role.uuid] = {name_dst: new_role.uuid}
+ if new_name == 'Agent':
+ agent_role = new_role
+
+if agent_role:
+ for role in Role.objects.filter(ou=ou):
+ if ou.uuid == agent_role.uuid:
+ continue
+ role.add_parent(agent_role)
json.dump(mapping, open('/tmp/roles.mapping.json', 'w'), indent=2)