From 08bd6ee94f219584db2f2be6bf72cebe4f9302d6 Mon Sep 17 00:00:00 2001 From: Leigh Johnson Date: Sat, 26 Nov 2016 16:12:32 -0500 Subject: [PATCH] Fix missing closing div in form-generator, update stateDefinition generator to support new user/team permissions directive --- awx/ui/client/src/shared/form-generator.js | 1 + .../src/shared/stateDefinitions.factory.js | 79 ++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index d487efa925..0d66226088 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -1760,6 +1760,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat if (this.form.horizontal) { html += "\n"; } + html += ''; } } diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index b76c5b5a36..62b7f9cb68 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -230,7 +230,74 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat */ generateFormListDefinitions: function(form, formStateDefinition) { - function buildPermissionDirective() { + function buildRbacUserTeamDirective(){ + let states = []; + + states.push($stateExtender.buildDefinition({ + name: `${formStateDefinition.name}.permissions.add`, + squashSearchUrl: true, + url: '/add-permissions', + params: { + project_search: { + value: {order_by: 'name', page_size: '5'}, + dynamic: true + }, + template_search: { + value: {order_by: 'name', page_size: '5', type: 'workflow_job_template,job_template'}, // @issue and also system_job_template? + dynamic: true + }, + inventory_search: { + value: {order_by: 'name', page_size: '5'}, + dynamic: true + }, + credential_search: { + value: {order_by: 'name', page_size: '5'}, + dynamic: true + } + }, + views: { + [`modal@${formStateDefinition.name}`]: { + template: `` + } + }, + resolve: { + templatesDataset: ['TemplateList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = GetBasePath(list.basePath) || GetBasePath(list.name); + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ], + projectsDataset: ['ProjectList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = GetBasePath(list.basePath) || GetBasePath(list.name); + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ], + inventoriesDataset: ['InventoryList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = GetBasePath(list.basePath) || GetBasePath(list.name); + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ], + credentialsDataset: ['CredentialList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = GetBasePath(list.basePath) || GetBasePath(list.name); + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ], + }, + onExit: function($state) { + if ($state.transition) { + $('#add-permissions-modal').modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + } + }, + })); + return states; + } + + function buildRbacResourceDirective() { let states = []; states.push($stateExtender.buildDefinition({ @@ -249,7 +316,7 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat }, views: { [`modal@${formStateDefinition.name}`]: { - template: `` + template: `` } }, resolve: { @@ -282,7 +349,13 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat let states = []; states.push(buildListDefinition(field)); if (field.iterator === 'permission' && field.actions && field.actions.add) { - states.push(buildPermissionDirective()); + if (form.name === 'user' || form.name === 'team'){ + states.push(buildRbacUserTeamDirective()); + + } + else { + states.push(buildRbacResourceDirective()); + } states = _.flatten(states); } return states;