From 00698b82fca08899bd0a500002b1e78525da0aad Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Fri, 10 Jun 2016 17:03:55 -0400 Subject: [PATCH 1/3] fix issue with Team.roles and ActivityStream --- awx/main/signals.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/awx/main/signals.py b/awx/main/signals.py index 40382c98b4..7f3f900db8 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -158,13 +158,17 @@ def org_admin_edit_members(instance, action, model, reverse, pk_set, **kwargs): def rbac_activity_stream(instance, sender, **kwargs): user_type = ContentType.objects.get_for_model(User) + team_type = ContentType.objects.get_for_model(Team) # Only if we are associating/disassociating if kwargs['action'] in ['pre_add', 'pre_remove']: # Only if this isn't for the User.admin_role if hasattr(instance, 'content_type'): if instance.content_type in [None, user_type]: return - role = instance + elif instance.content_type == team_type: + role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first() + else: + role = instance instance = instance.content_object else: role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first() @@ -192,6 +196,7 @@ post_save.connect(emit_ad_hoc_command_event_detail, sender=AdHocCommandEvent) m2m_changed.connect(rebuild_role_ancestor_list, Role.parents.through) m2m_changed.connect(org_admin_edit_members, Role.members.through) m2m_changed.connect(rbac_activity_stream, Role.members.through) +m2m_changed.connect(rbac_activity_stream, Role.parents.through) post_save.connect(sync_superuser_status_to_rbac, sender=User) post_save.connect(create_user_role, sender=User) pre_delete.connect(cleanup_detached_labels_on_deleted_parent, sender=UnifiedJob) From db1647883025952d348d0c9ee9aadd8cd9623393 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Fri, 10 Jun 2016 17:24:18 -0400 Subject: [PATCH 2/3] only special case team when sender is Role_parents --- awx/main/signals.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/awx/main/signals.py b/awx/main/signals.py index 7f3f900db8..e9de3617f2 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -158,14 +158,13 @@ def org_admin_edit_members(instance, action, model, reverse, pk_set, **kwargs): def rbac_activity_stream(instance, sender, **kwargs): user_type = ContentType.objects.get_for_model(User) - team_type = ContentType.objects.get_for_model(Team) # Only if we are associating/disassociating if kwargs['action'] in ['pre_add', 'pre_remove']: # Only if this isn't for the User.admin_role if hasattr(instance, 'content_type'): if instance.content_type in [None, user_type]: return - elif instance.content_type == team_type: + elif sender.__name__ == 'Role_parents': role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first() else: role = instance From 019c5bac045955f6b207e6d658aef4a6fb3870e4 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Mon, 13 Jun 2016 09:39:52 -0400 Subject: [PATCH 3/3] fix tests to be more specific about AS query --- awx/main/tests/functional/api/test_activity_streams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/tests/functional/api/test_activity_streams.py b/awx/main/tests/functional/api/test_activity_streams.py index 39990064d7..f1c42cdd9d 100644 --- a/awx/main/tests/functional/api/test_activity_streams.py +++ b/awx/main/tests/functional/api/test_activity_streams.py @@ -13,7 +13,7 @@ def mock_feature_enabled(feature, bypass_database=None): @pytest.fixture def activity_stream_entry(organization, org_admin): - return ActivityStream.objects.filter(organization__pk=organization.pk, operation='associate').first() + return ActivityStream.objects.filter(organization__pk=organization.pk, user=org_admin, operation='associate').first() @pytest.mark.skipif(not getattr(settings, 'ACTIVITY_STREAM_ENABLED', True), reason="Activity stream not enabled") @mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)