From a693aad95da401712efc519fd3b92979aaa46a21 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 11 Jan 2017 14:22:28 -0500 Subject: [PATCH] a workable version of the new copy GET schema implemented --- awx/api/views.py | 12 +++--- .../tests/functional/test_rbac_workflow.py | 6 +-- .../list/templates-list.controller.js | 38 +++++++++++++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 7e8ea65540..7c22bdf57f 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2907,12 +2907,12 @@ class WorkflowJobTemplateCopy(WorkflowsEnforcementMixin, GenericAPIView): def get(self, request, *args, **kwargs): obj = self.get_object() can_copy, messages = request.user.can_access_with_errors(self.model, 'copy', obj) - data = { - 'can_copy': can_copy, 'can_copy_without_user_input': can_copy, - 'templates_unable_to_copy': [] if can_copy else ['all'], - 'credentials_unable_to_copy': [] if can_copy else ['all'], - 'inventories_unable_to_copy': [] if can_copy else ['all'] - } + data = OrderedDict([ + ('can_copy', can_copy), ('can_copy_without_user_input', can_copy), + ('templates_unable_to_copy', [] if can_copy else ['all']), + ('credentials_unable_to_copy', [] if can_copy else ['all']), + ('inventories_unable_to_copy', [] if can_copy else ['all']) + ]) if messages and can_copy: data['can_copy_without_user_input'] = False data.update(messages) diff --git a/awx/main/tests/functional/test_rbac_workflow.py b/awx/main/tests/functional/test_rbac_workflow.py index a0f0348e38..f2ce04404f 100644 --- a/awx/main/tests/functional/test_rbac_workflow.py +++ b/awx/main/tests/functional/test_rbac_workflow.py @@ -120,13 +120,11 @@ class TestWorkflowJobAccess: access = WorkflowJobTemplateAccess(rando, save_messages=True) assert not access.can_copy(wfjt) warnings = access.messages - assert 1 in warnings - assert 'inventory' in warnings[1] + assert 'inventories_unable_to_copy' in warnings def test_workflow_copy_warnings_jt(self, wfjt, rando, job_template): wfjt.workflow_job_template_nodes.create(unified_job_template=job_template) access = WorkflowJobTemplateAccess(rando, save_messages=True) assert not access.can_copy(wfjt) warnings = access.messages - assert 1 in warnings - assert 'unified_job_template' in warnings[1] + assert 'templates_unable_to_copy' in warnings diff --git a/awx/ui/client/src/templates/list/templates-list.controller.js b/awx/ui/client/src/templates/list/templates-list.controller.js index a71f9573c3..d0b910e6b9 100644 --- a/awx/ui/client/src/templates/list/templates-list.controller.js +++ b/awx/ui/client/src/templates/list/templates-list.controller.js @@ -239,14 +239,36 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
`; - // Go and grab all of the warning strings - _.forOwn(result.data.templates_unable_to_copy, function(ujt) { - if(ujt) { - // _.forOwn(ujts, function(warningString) { - bodyHtml += '
' + ujt + '
'; - // }); - } - } ); + // List the unified job templates user can not access + if (result.data.templates_unable_to_copy.length > 0) { + bodyHtml += '
Unified Job Templates that can not be copied
    '; + _.forOwn(result.data.templates_unable_to_copy, function(ujt) { + if(ujt) { + bodyHtml += '
  • ' + ujt + '
  • '; + } + }); + bodyHtml += '
'; + } + // List the prompted inventories user can not access + if (result.data.inventories_unable_to_copy.length > 0) { + bodyHtml += '
Node prompted inventories that can not be copied
    '; + _.forOwn(result.data.inventories_unable_to_copy, function(inv) { + if(inv) { + bodyHtml += '
  • ' + inv + '
  • '; + } + }); + bodyHtml += '
'; + } + // List the prompted credentials user can not access + if (result.data.credentials_unable_to_copy.length > 0) { + bodyHtml += '
Node prompted credentials that can not be copied
    '; + _.forOwn(result.data.credentials_unable_to_copy, function(cred) { + if(cred) { + bodyHtml += '
  • ' + cred + '
  • '; + } + }); + bodyHtml += '
'; + } bodyHtml += '
';