From a968a44afbf1b38b47f1abb03874be2c72ccbaa7 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 17 Jul 2018 00:38:40 -0400 Subject: [PATCH] add inventory field to inventory update --- awx/api/serializers.py | 6 ++- ...044_v330_add_inventory_update_inventory.py | 21 +++++++++ awx/main/models/inventory.py | 9 +++- .../features/output/details.component.js | 46 ------------------- .../features/output/details.partial.html | 12 ----- .../factories/build-anchor.factory.js | 4 ++ docs/CHANGELOG.md | 1 + 7 files changed, 39 insertions(+), 60 deletions(-) create mode 100644 awx/main/migrations/0044_v330_add_inventory_update_inventory.py diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 9ae461c53c..1fb9a43f72 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2172,7 +2172,7 @@ class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSeri class Meta: model = InventoryUpdate - fields = ('*', 'inventory_source', 'license_error', 'source_project_update', + fields = ('*', 'inventory', 'inventory_source', 'license_error', 'source_project_update', '-controller_node',) def get_related(self, obj): @@ -2193,8 +2193,12 @@ class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSeri if obj.source_project_update_id: res['source_project_update'] = self.reverse('api:project_update_detail', kwargs={'pk': obj.source_project_update.pk}) + if obj.inventory: + res['inventory'] = self.reverse('api:inventory_detail', kwargs={'pk': obj.inventory.pk}) + if self.version > 1: res['credentials'] = self.reverse('api:inventory_update_credentials_list', kwargs={'pk': obj.pk}) + return res diff --git a/awx/main/migrations/0044_v330_add_inventory_update_inventory.py b/awx/main/migrations/0044_v330_add_inventory_update_inventory.py new file mode 100644 index 0000000000..1ec8b838ec --- /dev/null +++ b/awx/main/migrations/0044_v330_add_inventory_update_inventory.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.11 on 2018-07-17 03:57 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0043_v330_oauth2accesstoken_modified'), + ] + + operations = [ + migrations.AddField( + model_name='inventoryupdate', + name='inventory', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='inventory_updates', to='main.Inventory'), + ), + ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 24d0e9a1c5..76fee71175 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -1420,7 +1420,7 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions, RelatedJobsMix @classmethod def _get_unified_job_field_names(cls): return set(f.name for f in InventorySourceOptions._meta.fields) | set( - ['name', 'description', 'schedule', 'credentials'] + ['name', 'description', 'schedule', 'credentials', 'inventory'] ) def save(self, *args, **kwargs): @@ -1599,6 +1599,13 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin, class Meta: app_label = 'main' + inventory = models.ForeignKey( + 'Inventory', + related_name='inventory_updates', + null=True, + default=None, + on_delete=models.DO_NOTHING, + ) inventory_source = models.ForeignKey( 'InventorySource', related_name='inventory_updates', diff --git a/awx/ui/client/features/output/details.component.js b/awx/ui/client/features/output/details.component.js index 35a59d128e..0417246e8e 100644 --- a/awx/ui/client/features/output/details.component.js +++ b/awx/ui/client/features/output/details.component.js @@ -133,51 +133,6 @@ function getJobTemplateDetails () { return { label, link, value, tooltip }; } -function getInventoryJobNameDetails () { - if (resource.model.get('type') !== 'inventory_update') { - return null; - } - - const jobArgs = resource.model.get('job_args'); - - if (!jobArgs) { - return null; - } - - let parsedJobArgs; - - try { - parsedJobArgs = JSON.parse(jobArgs); - } catch (e) { - return null; - } - - if (!Array.isArray(parsedJobArgs)) { - return null; - } - - const jobArgIndex = parsedJobArgs.indexOf('--inventory-id'); - const inventoryId = parsedJobArgs[jobArgIndex + 1]; - - if (jobArgIndex < 0) { - return null; - } - - if (!Number.isInteger(parseInt(inventoryId, 10))) { - return null; - } - - const name = resource.model.get('name'); - const id = resource.model.get('id'); - - const label = strings.get('labels.NAME'); - const tooltip = strings.get('tooltips.INVENTORY'); - const value = `${id} - ${$filter('sanitize')(name)}`; - const link = `/#/inventories/inventory/${inventoryId}`; - - return { label, link, tooltip, value }; -} - function getInventorySourceDetails () { if (!resource.model.has('summary_fields.inventory_source.source')) { return null; @@ -726,7 +681,6 @@ function JobDetailsController ( vm.skipTags = getSkipTagDetails(); vm.extraVars = getExtraVarsDetails(); vm.labels = getLabelDetails(); - vm.inventoryJobName = getInventoryJobNameDetails(); vm.inventorySource = getInventorySourceDetails(); vm.overwrite = getOverwriteDetails(); vm.overwriteVars = getOverwriteVarsDetails(); diff --git a/awx/ui/client/features/output/details.partial.html b/awx/ui/client/features/output/details.partial.html index fb1829def2..f681059f90 100644 --- a/awx/ui/client/features/output/details.partial.html +++ b/awx/ui/client/features/output/details.partial.html @@ -41,18 +41,6 @@ - -
- - -
-
diff --git a/awx/ui/client/src/activity-stream/factories/build-anchor.factory.js b/awx/ui/client/src/activity-stream/factories/build-anchor.factory.js index e3bfa0dcb4..0803a957c4 100644 --- a/awx/ui/client/src/activity-stream/factories/build-anchor.factory.js +++ b/awx/ui/client/src/activity-stream/factories/build-anchor.factory.js @@ -81,6 +81,10 @@ export default function BuildAnchor($log, $filter) { case 'label': url = null; break; + case 'inventory_source': + const inventoryId = _.get(obj, 'inventory', '').split('-').reverse()[0]; + url += `inventories/inventory/${inventoryId}/inventory_sources/edit/${obj.id}`; + break; default: url += resource + 's/' + obj.id + '/'; } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9823025af6..10f8668888 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -74,6 +74,7 @@ * Changed the name of the session length setting from `AUTH_TOKEN_EXPIRATION` to `SESSION_COOKIE_AGE`. * Changed the name of the session length setting from `AUTH_TOKEN_PER_USER` to `SESSIONS_PER_USER`. * External logging now defaults to HTTPS (instead of HTTP) *unless* http:// is explicitly specified in the log aggregator hostname [[#2048](https://github.com/ansible/awx/issues/2048)] +* Added `inventory` field to inventory updates 3.2.0 =====