From 9909ea90c1bfce9d594700f0e43678775742c0c0 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 16 Mar 2016 09:13:33 -0400 Subject: [PATCH] Fixed post delete behavior for roles, added test --- awx/main/fields.py | 2 +- awx/main/tests/functional/test_rbac_core.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/awx/main/fields.py b/awx/main/fields.py index a32f3b636c..22210124f0 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -293,4 +293,4 @@ class ImplicitRoleField(models.ForeignKey): children = [c for c in this_role.children.all()] this_role.delete() for child in children: - children.rebuild_role_ancestor_list() + child.rebuild_role_ancestor_list() diff --git a/awx/main/tests/functional/test_rbac_core.py b/awx/main/tests/functional/test_rbac_core.py index d5638878a2..d7657344f5 100644 --- a/awx/main/tests/functional/test_rbac_core.py +++ b/awx/main/tests/functional/test_rbac_core.py @@ -134,11 +134,14 @@ def test_auto_field_adjuments(organization, inventory, team, alice): def test_implicit_deletes(alice): 'Ensures implicit resources and roles delete themselves' delorg = Organization.objects.create(name='test-org') + child = Role.objects.create(name='child-role') + child.parents.add(delorg.admin_role) delorg.admin_role.members.add(alice) admin_role_id = delorg.admin_role.id auditor_role_id = delorg.auditor_role.id + assert child.ancestors.count() > 1 assert Role.objects.filter(id=admin_role_id).count() == 1 assert Role.objects.filter(id=auditor_role_id).count() == 1 n_alice_roles = alice.roles.count() @@ -152,6 +155,9 @@ def test_implicit_deletes(alice): assert alice.roles.count() == (n_alice_roles - 1) assert RolePermission.objects.filter(id=rp.id).count() == 0 assert Role.singleton('System Administrator').children.count() == (n_system_admin_children - 1) + assert child.ancestors.count() == 1 + assert child.ancestors.all()[0] == child + @pytest.mark.django_db def test_content_object(user):