From 3e25ad5ffcc338c00e9ed69a5a96f4bfd7bba504 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Thu, 13 Jul 2017 13:54:26 -0400 Subject: [PATCH] fix ctit ldap search form fields in ui --- .../configuration/configuration.controller.js | 5 ++-- .../configurationUtils.service.js | 24 +++++++++++++++---- .../shared/parse/parse-type-change.factory.js | 11 ++++++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 33056ec486..410248cf1e 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -77,8 +77,9 @@ export default [ // behind the comma. if(key === "AD_HOC_COMMANDS"){ $scope[key] = data[key].toString(); - } - else { + } else if (key === "AUTH_LDAP_USER_SEARCH" || key === "AUTH_LDAP_GROUP_SEARCH") { + $scope[key] = JSON.stringify(data[key]); + } else { $scope[key] = ConfigurationUtils.arrayToList(data[key], key); } diff --git a/awx/ui/client/src/configuration/configurationUtils.service.js b/awx/ui/client/src/configuration/configurationUtils.service.js index 7620d6917d..e9d448aff5 100644 --- a/awx/ui/client/src/configuration/configurationUtils.service.js +++ b/awx/ui/client/src/configuration/configurationUtils.service.js @@ -9,16 +9,30 @@ export default ['$q', return { listToArray: function(input) { - if (input.indexOf('\n') !== -1) { + var payload; + + if (input.indexOf('[') !== -1) { + try { + payload = JSON.parse(input); + + if (!Array.isArray(payload)) { + payload = []; + } + } catch(err) { + payload = []; + } + } else if (input.indexOf('\n') !== -1) { //Parse multiline input - return input.replace(/^\s+|\s+$/g, "").split('\n'); + payload = input.replace(/^\s+|\s+$/g, "").split('\n'); } else { - if (input === '') { - return []; + if (input === '' || input === '{}') { + payload = []; } else { - return input.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/); + payload = input.replace(/^\s+|\s+$/g, "") + .split(/\s*,\s*/); } } + return payload; }, arrayToList: function(input) { diff --git a/awx/ui/client/src/shared/parse/parse-type-change.factory.js b/awx/ui/client/src/shared/parse/parse-type-change.factory.js index 678c91abe9..1556acad78 100644 --- a/awx/ui/client/src/shared/parse/parse-type-change.factory.js +++ b/awx/ui/client/src/shared/parse/parse-type-change.factory.js @@ -51,11 +51,16 @@ export default // converting yaml to json try { removeField(fld); + json_obj = jsyaml.load(scope[fld]); + if ($.isEmptyObject(json_obj)) { - scope[fld] = "{}"; - } - else { + if (Array.isArray(json_obj)) { + scope[fld] = "[]"; + } else { + scope[fld] = "{}"; + } + } else { scope[fld] = JSON.stringify(json_obj, null, " "); } createField(onReady, onChange, fld);