diff options
author | Jeff Bradberry <jeff.bradberry@gmail.com> | 2024-05-01 22:42:53 +0200 |
---|---|---|
committer | Jeff Bradberry <jeff.bradberry@gmail.com> | 2024-06-10 22:36:22 +0200 |
commit | 5cfeeb3e87615b83392d6ce8c132171721dad9fc (patch) | |
tree | 478c139890c1fdf98286dd6c2b4de932246f2b1a /tools | |
parent | Set up an enhanced version of Seth's bad role scenario (diff) | |
download | awx-5cfeeb3e87615b83392d6ce8c132171721dad9fc.tar.xz awx-5cfeeb3e87615b83392d6ce8c132171721dad9fc.zip |
Treat resources with null role fks differently
The underlying role should be re-linked, instead of treated as orphaned.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/scripts/ig-hotfix/role_check.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tools/scripts/ig-hotfix/role_check.py b/tools/scripts/ig-hotfix/role_check.py index 5018a57462..f5d902340f 100644 --- a/tools/scripts/ig-hotfix/role_check.py +++ b/tools/scripts/ig-hotfix/role_check.py @@ -37,12 +37,13 @@ for r in Role.objects.exclude(role_field__startswith='system_').order_by('id'): orphaned_roles.append(r.id) continue rev = getattr(r.content_object, r.role_field, None) - if not rev: - continue - if r.id != rev.id: - if (r.content_type_id, r.object_id, r.role_field) == (rev.content_type_id, rev.object_id, rev.role_field): + if rev is None or r.id != rev.id: + if rev and (r.content_type_id, r.object_id, r.role_field) == (rev.content_type_id, rev.object_id, rev.role_field): sys.stderr.write(f"Role id={r.id} {r.content_type!r} {r.object_id} {r.role_field} is an orphaned duplicate of Role id={rev.id}, which is actually being used by the assigned resource\n") orphaned_roles.append(r.id) + elif not rev: + sys.stderr.write(f"Role id={r.id} {r.content_type!r} {r.object_id} {r.role_field} is pointing to an object currently using no role\n") + crosslinked[r.content_type_id][r.object_id][f'{r.role_field}_id'] = r.id else: sys.stderr.write(f"Role id={r.id} {r.content_type!r} {r.object_id} {r.role_field} is pointing to an object using a different role: id={rev.id} {rev.content_type!r} {rev.object_id} {rev.role_field}\n") crosslinked[r.content_type_id][r.object_id][f'{r.role_field}_id'] = r.id @@ -55,7 +56,7 @@ sys.stderr.write('===================================\n') print(f"""\ from django.contrib.contenttypes.models import ContentType -from awx.main.models.rbac import Role, batch_role_ancestor_rebuilding +from awx.main.models.rbac import Role """) @@ -76,7 +77,6 @@ for ct, objs in crosslinked.items(): print(f"cls.objects.filter(id={obj}).update(**{kv!r})") print(f"queue.append((cls, {obj}))") -print(f"\nwith batch_role_ancestor_rebuilding():") -print(f" for cls, obj_id in queue:") -print(f" obj = cls.objects.get(id=obj_id)") -print(f" obj.save()") +print(f"\n\nfor cls, obj_id in queue:") +print(f" obj = cls.objects.get(id=obj_id)") +print(f" obj.save()") |