diff options
author | Jeff Bradberry <jeff.bradberry@gmail.com> | 2024-05-08 16:21:03 +0200 |
---|---|---|
committer | Jeff Bradberry <jeff.bradberry@gmail.com> | 2024-06-10 22:36:22 +0200 |
commit | d67af794515346ca41f7ecc51e49380db8b0b9f6 (patch) | |
tree | 2af417b063cfcf989223ac4f6002b64a21f9d62a /tools | |
parent | Exclude more files in the .gitignore (diff) | |
download | awx-d67af794515346ca41f7ecc51e49380db8b0b9f6.tar.xz awx-d67af794515346ca41f7ecc51e49380db8b0b9f6.zip |
Attempt to correct any crosslinked parents
I think that rebuild_role_ancestor_list() will then correctly update
all of the affected Role.ancestors.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/scripts/ig-hotfix/role_check.py | 6 |
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()") |