From f9309c9cd95204c7cd6ed2c6bf7d3af47fca9eed Mon Sep 17 00:00:00 2001 From: Yunfan Zhang Date: Tue, 31 Jul 2018 10:19:51 -0400 Subject: [PATCH] Add instance groups to activity streams. Signed-off-by: Yunfan Zhang --- .../0047_v330_activitystream_instance.py | 20 +++++++++++++++++++ awx/main/models/activity_stream.py | 1 + awx/main/signals.py | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 awx/main/migrations/0047_v330_activitystream_instance.py diff --git a/awx/main/migrations/0047_v330_activitystream_instance.py b/awx/main/migrations/0047_v330_activitystream_instance.py new file mode 100644 index 0000000000..0bc6b3c0bc --- /dev/null +++ b/awx/main/migrations/0047_v330_activitystream_instance.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.11 on 2018-07-25 20:19 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0046_v330_remove_client_credentials_grant'), + ] + + operations = [ + migrations.AddField( + model_name='activitystream', + name='instance', + field=models.ManyToManyField(blank=True, to='main.Instance'), + ), + ] diff --git a/awx/main/models/activity_stream.py b/awx/main/models/activity_stream.py index 5881008bf2..766cefbc5b 100644 --- a/awx/main/models/activity_stream.py +++ b/awx/main/models/activity_stream.py @@ -66,6 +66,7 @@ class ActivityStream(models.Model): notification = models.ManyToManyField("Notification", blank=True) label = models.ManyToManyField("Label", blank=True) role = models.ManyToManyField("Role", blank=True) + instance = models.ManyToManyField("Instance", blank=True) instance_group = models.ManyToManyField("InstanceGroup", blank=True) o_auth2_application = models.ManyToManyField("OAuth2Application", blank=True) o_auth2_access_token = models.ManyToManyField("OAuth2AccessToken", blank=True) diff --git a/awx/main/signals.py b/awx/main/signals.py index 108300dd89..a08556285d 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -12,6 +12,7 @@ import sys # Django from django.conf import settings from django.db.models.signals import ( + pre_save, post_save, pre_delete, post_delete, @@ -389,6 +390,7 @@ model_serializer_mapping = { Inventory: InventorySerializer, Host: HostSerializer, Group: GroupSerializer, + InstanceGroup: InstanceGroupSerializer, InventorySource: InventorySourceSerializer, CustomInventoryScript: CustomInventoryScriptSerializer, Credential: CredentialSerializer, @@ -641,3 +643,7 @@ def create_access_token_user_if_missing(sender, **kwargs): post_save.connect(create_access_token_user_if_missing, sender=OAuth2AccessToken) +# Connect the Instance Group to Activity Stream receivers. +post_save.connect(activity_stream_create, sender=InstanceGroup, dispatch_uid=str(InstanceGroup) + "_create") +pre_save.connect(activity_stream_update, sender=InstanceGroup, dispatch_uid=str(InstanceGroup) + "_update") +pre_delete.connect(activity_stream_delete, sender=InstanceGroup, dispatch_uid=str(InstanceGroup) + "_delete")