grandlyon: make all roles inherit from agent
This commit is contained in:
parent
0613710ef3
commit
62e93b441a
|
@ -9,19 +9,29 @@ Role = get_role_model()
|
||||||
|
|
||||||
mapping = {}
|
mapping = {}
|
||||||
|
|
||||||
name_src = sys.argv[1]
|
name_src = sys.argv[1].decode('utf-8')
|
||||||
name_dst = sys.argv[2]
|
name_dst = sys.argv[2].decode('utf-8')
|
||||||
|
|
||||||
ou_src = Ou.objects.get(name=name_src)
|
ou_src = Ou.objects.get(name=name_src)
|
||||||
ou = Ou.objects.get(name=name_dst)
|
ou = Ou.objects.get(name=name_dst)
|
||||||
|
|
||||||
|
agent_role = None
|
||||||
|
|
||||||
for role in Role.objects.filter(ou=ou_src):
|
for role in Role.objects.filter(ou=ou_src):
|
||||||
if not (role.name.startswith('Gestionnaire') or role.name.startswith('Administrateur')):
|
#if not (role.name.startswith('Gestionnaire') or role.name.startswith('Administrateur')):
|
||||||
continue
|
# continue
|
||||||
if role.slug.startswith('_'):
|
if role.slug.startswith('_'):
|
||||||
continue
|
continue
|
||||||
new_name = role.name.replace(name_src, name_dst).replace(name_src.lower(), name_dst.lower())
|
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)
|
new_role, created = Role.objects.get_or_create(ou=ou, name=new_name)
|
||||||
mapping[role.uuid] = {name_dst: new_role.uuid}
|
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)
|
json.dump(mapping, open('/tmp/roles.mapping.json', 'w'), indent=2)
|
||||||
|
|
Loading…
Reference in New Issue