summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/scripts/ig-hotfix/role_check.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/scripts/ig-hotfix/role_check.py b/tools/scripts/ig-hotfix/role_check.py
index 776bd74cd5..076f2e1b90 100644
--- a/tools/scripts/ig-hotfix/role_check.py
+++ b/tools/scripts/ig-hotfix/role_check.py
@@ -12,6 +12,7 @@ from awx.main.models.rbac import Role
team_ct = ContentType.objects.get(app_label='main', model='team')
crosslinked = defaultdict(lambda: defaultdict(dict))
+crosslinked_parents = defaultdict(list)
orphaned_roles = []
@@ -99,6 +100,7 @@ for r in Role.objects.exclude(role_field__startswith='system_').order_by('id'):
if plus:
plus = [f"{x.content_type!r} {x.object_id} {x.role_field}" for x in plus]
sys.stderr.write(f"Role id={r.id} has cross-linked parents: {plus}\n")
+ crosslinked_parents[r.id].extend(x.id for x in plus)
rev = getattr(r.content_object, r.role_field, None)
if rev is None or r.id != rev.id:
@@ -141,6 +143,10 @@ for ct, objs in crosslinked.items():
print(f"cls.objects.filter(id={obj}).update(**{kv!r})")
print(f"queue.append((cls, {obj}))")
+for child, parents in crosslinked_parents.items():
+ print(f"\n\nr = Role.objects.get(id={child})")
+ print(f"r.parents.remove(*Role.objects.filter(id__in={parents!r}))")
+
print(f"\n\nfor cls, obj_id in queue:")
print(f" obj = cls.objects.get(id=obj_id)")
print(f" obj.save()")