From 30439a85b08bd5e39539c01643831ea746a9fdd3 Mon Sep 17 00:00:00 2001 From: Leigh Johnson Date: Tue, 12 Apr 2016 11:10:37 -0400 Subject: [PATCH] populate fields in users.edit and teams.edit $states resolves #1403 users edit done finish fixes to UsersTeamsEdit fix logging issue --- awx/ui/client/src/controllers/Teams.js | 326 ++++++-------------- awx/ui/client/src/controllers/Users.js | 397 ++++++------------------- awx/ui/client/src/forms/Teams.js | 91 ++---- awx/ui/client/src/forms/Users.js | 137 +++------ 4 files changed, 256 insertions(+), 695 deletions(-) diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index 0bb7e9e2d4..368f8c70b3 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -166,7 +166,7 @@ export function TeamsAdd($scope, $rootScope, $compile, $location, $log, Wait('stop'); $rootScope.flashMessage = "New team successfully created!"; $rootScope.$broadcast("EditIndicatorChange", "users", data.id); - $location.path('/teams/' + data.id); + $state.go('teams.edit', {team_id: data.id}, {reload: true}); }) .error(function (data, status) { Wait('stop'); @@ -188,11 +188,10 @@ TeamsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', ]; -export function TeamsEdit($scope, $rootScope, $compile, $location, $log, - $stateParams, TeamForm, GenerateForm, Rest, Alert, ProcessErrors, - RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, - LookUpInit, Prompt, GetBasePath, CheckAccess, OrganizationList, Wait, - fieldChoices, fieldLabels, permissionsSearchSelect, $state) { +export function TeamsEdit($scope, $rootScope, $location, + $stateParams, TeamForm, GenerateForm, Rest, ProcessErrors, + RelatedSearchInit, RelatedPaginateInit, ClearScope, + LookUpInit, GetBasePath, OrganizationList, Wait, $state) { ClearScope(); @@ -204,238 +203,109 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, id = $stateParams.team_id, relatedSets = {}; - $scope.permission_label = {}; - $scope.permission_search_select = []; - - $scope.$emit("RefreshTeamsList"); - - // return a promise from the options request with the permission type choices (including adhoc) as a param - // var permissionsChoice = fieldChoices({ - // scope: $scope, - // url: 'api/v1/' + base + '/' + id + '/permissions/', - // field: 'permission_type' - // }); - - // // manipulate the choices from the options request to be set on - // // scope and be usable by the list form - // permissionsChoice.then(function (choices) { - // choices = - // fieldLabels({ - // choices: choices - // }); - // _.map(choices, function(n, key) { - // $scope.permission_label[key] = n; - // }); - // }); - - // manipulate the choices from the options request to be usable - // by the search option for permission_type, you can't inject the - // list until this is done! - // permissionsChoice.then(function (choices) { - // form.related.permissions.fields.permission_type.searchOptions = - // permissionsSearchSelect({ - // choices: choices - // }); - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - generator.reset(); - $scope.$emit('loadTeam'); - // }); - - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - generator.reset(); - $scope.$emit('loadTeam'); - $scope.team_id = id; - $scope.PermissionAddAllowed = false; - // Retrieve each related set and any lookups - if ($scope.loadTeamRemove) { - $scope.loadTeamRemove(); - } - $scope.loadTeamRemove = $scope.$on('loadTeam', function () { - // Retrieve detail record and prepopulate the form - Wait('start'); - Rest.setUrl(defaultUrl + ':id/'); - Rest.get({ - params: { - id: id - } + generator.inject(form, { mode: 'edit', related: true, scope: $scope }); + generator.reset() + + var setScopeFields = function(data){ + _(data) + .pick(function(value, key){ + return form.fields.hasOwnProperty(key) === true; }) - .success(function (data) { - var fld, related, set; - $scope.team_name = data.name; - for (fld in form.fields) { - if (data[fld]) { - $scope[fld] = data[fld]; - master[fld] = $scope[fld]; - } - } - related = data.related; - for (set in form.related) { - if (related[set]) { - relatedSets[set] = { - url: related[set], - iterator: form.related[set].iterator - }; - } - } - // Initialize related search functions. Doing it here to make sure relatedSets object is populated. - RelatedSearchInit({ - scope: $scope, - form: form, - relatedSets: relatedSets - }); - RelatedPaginateInit({ - scope: $scope, - relatedSets: relatedSets - }); - - LookUpInit({ - scope: $scope, - form: form, - current_item: data.organization, - list: OrganizationList, - field: 'organization', - input_type: 'radio' - }); - - $scope.organization_url = data.related.organization; - $scope.organization_name = data.summary_fields.organization.name; - master.organization_name = data.summary_fields.organization.name; - - // get related object values and populate - for (var relatedValues in relatedSets) { - $scope.search(relatedSets[relatedValues].iterator); - } - CheckAccess({ scope: $scope }); //Does the user have access to add/edit Permissions? - Wait('stop'); - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to retrieve team: ' + $stateParams.team_id + - '. GET status: ' + status }); - Wait('stop'); - }); - }); - - $scope.getPermissionText = function () { - if (this.permission.permission_type !== "admin" && this.permission.run_ad_hoc_commands) { - return $scope.permission_label[this.permission.permission_type] + - " and " + $scope.permission_label.adhoc; - } else { - return $scope.permission_label[this.permission.permission_type]; - } + .forEach(function(value, key){ + $scope[key] = value; + }) + .value(); + return + }; + var setScopeRelated = function(data, related){ + _(related) + .pick(function(value, key){ + return data.related.hasOwnProperty(key) === true; + }) + .forEach(function(value, key){ + relatedSets[key] = { + url: data.related[key], + iterator: value.iterator + }; + }) + .value(); }; - // Save changes to the parent - $scope.formSave = function () { - var data = {}, fld; - generator.clearApiErrors(); - Wait('start'); - $rootScope.flashMessage = null; - Rest.setUrl(defaultUrl + $stateParams.team_id + '/'); - for (fld in form.fields) { - data[fld] = $scope[fld]; - } - Rest.put(data) - .success(function () { - Wait('stop'); - var base = $location.path().replace(/^\//, '').split('/')[0]; - $scope.team_name = $scope.name; - if (base === 'teams') { - ReturnToCaller(); - } - else { - ReturnToCaller(1); - } - }) - .error(function (data, status) { - Wait('stop'); - ProcessErrors($scope, data, status, form, { hdr: 'Error!', - msg: 'Failed to update team: ' + $stateParams.team_id + '. PUT status: ' + status }); - }); - }; - - $scope.formCancel = function () { - $state.transitionTo('teams'); - }; - - // Related set: Add button - $scope.add = function (set) { - $rootScope.flashMessage = null; - if (set === 'permissions') { - if ($scope.PermissionAddAllowed) { - $location.path('/' + base + '/' + $stateParams.team_id + '/' + set + '/add'); - } else { - Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.'); + // prepares a data payload for a PUT request to the API + var processNewData = function(fields){ + var data = {}; + _.forEach(fields, function(value, key){ + if ($scope[key] !== '' && $scope[key] !== null && $scope[key] !== undefined){ + data[key] = $scope[key]; } - } else { - $location.path('/' + base + '/' + $stateParams.team_id + '/' + set); - } - }; - - // Related set: Edit button - $scope.edit = function (set, id) { - $rootScope.flashMessage = null; - if (set === 'permissions') { - $location.path('/' + base + '/' + $stateParams.team_id + '/' + set + '/' + id); - } else { - $location.path('/' + set + '/' + id); - } - }; - - // Related set: Delete button - $scope['delete'] = function (set, itm_id, name, title) { - $rootScope.flashMessage = null; - - var action = function () { - var url; - if (set === 'permissions') { - if ($scope.PermissionAddAllowed) { - url = GetBasePath('base') + 'permissions/' + itm_id + '/'; - Rest.setUrl(url); - Rest.destroy() - .success(function () { - $('#prompt-modal').modal('hide'); - $scope.search(form.related[set].iterator); - }) - .error(function (data, status) { - $('#prompt-modal').modal('hide'); - ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + - ' failed. DELETE returned status: ' + status }); - }); - } else { - Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.'); - } - } else { - url = defaultUrl + $stateParams.team_id + '/' + set + '/'; - Rest.setUrl(url); - Rest.post({ id: itm_id, disassociate: 1 }) - .success(function () { - $('#prompt-modal').modal('hide'); - $scope.search(form.related[set].iterator); - }) - .error(function (data, status) { - $('#prompt-modal').modal('hide'); - ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + - ' failed. POST returned status: ' + status }); - }); - } - }; - - Prompt({ - hdr: 'Delete', - body: '
Are you sure you want to remove the ' + title + ' below from ' + $scope.name + '?
' + name + '
', - action: action, - actionText: 'DELETE' }); + return data }; + + var init = function(){ + var url = defaultUrl + id; + Rest.setUrl(url); + Wait('start'); + Rest.get(url).success(function(data){ + setScopeFields(data); + setScopeRelated(data, form.related) + $scope.organization_name = data.summary_fields.organization.name; + + RelatedSearchInit({ + scope: $scope, + form: form, + relatedSets: relatedSets + }); + + RelatedPaginateInit({ + scope: $scope, + relatedSets: relatedSets + }); + + LookUpInit({ + url: GetBasePath('organizations'), + scope: $scope, + form: form, + current_item: $scope.organization, + list: OrganizationList, + field: 'organization', + input_type: 'radio' + }); + }); + } + + $scope.formCancel = function(){ + $state.go('teams', null, {reload: true}); + } + + $scope.formSave = function(){ + generator.clearApiErrors(); + generator.checkAutoFill(); + $rootScope.flashMessage = null; + if ($scope[form.name + '_form'].$valid){ + Rest.setUrl(defaultUrl + id + '/'); + var data = processNewData(form.fields); + Rest.put(data).success(function(res){ + $state.go('teams', null, {reload: true}); + }) + .error(function (data, status) { + ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve user: ' + + $stateParams.id + '. GET status: ' + status }); + }); + } + }; + + init(); + + /* Related Set implementation TDB */ } -TeamsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', - '$stateParams', 'TeamForm', 'GenerateForm', 'Rest', 'Alert', +TeamsEdit.$inject = ['$scope', '$rootScope', '$location', + '$stateParams', 'TeamForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'RelatedSearchInit', 'RelatedPaginateInit', - 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'GetBasePath', - 'CheckAccess', 'OrganizationList', 'Wait', 'fieldChoices', - 'fieldLabels', 'permissionsSearchSelect', '$state' + 'ClearScope', 'LookUpInit', 'GetBasePath', + 'OrganizationList', 'Wait', '$state' ]; diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index c17d6456f5..02d094fd1f 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -185,7 +185,7 @@ export function UsersAdd($scope, $rootScope, $compile, $location, $log, if (base === 'users') { $rootScope.flashMessage = 'New user successfully created!'; $rootScope.$broadcast("EditIndicatorChange", "users", data.id); - $location.path('/users/' + data.id); + $state.go('users.edit', {user_id: data.id}, {reload: true}); } else { ReturnToCaller(1); @@ -219,11 +219,10 @@ UsersAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', ]; -export function UsersEdit($scope, $rootScope, $compile, $location, $log, - $stateParams, UserForm, GenerateForm, Rest, Alert, ProcessErrors, - RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, - GetBasePath, Prompt, CheckAccess, ResetForm, Wait, fieldChoices, - fieldLabels, permissionsSearchSelect, $state) { +export function UsersEdit($scope, $rootScope, $location, + $stateParams, UserForm, GenerateForm, Rest, ProcessErrors, + RelatedSearchInit, RelatedPaginateInit, ClearScope, + GetBasePath, ResetForm, Wait, $state) { ClearScope(); @@ -235,315 +234,111 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, id = $stateParams.user_id, relatedSets = {}; - $scope.permission_label = {}; - $scope.permission_search_select = []; - - $scope.$emit("RefreshUsersList"); - - // // return a promise from the options request with the permission type choices (including adhoc) as a param - // var permissionsChoice = fieldChoices({ - // scope: $scope, - // url: 'api/v1/' + base + '/' + id + '/permissions/', - // field: 'permission_type' - // }); - // - // // manipulate the choices from the options request to be set on - // // scope and be usable by the list form - // permissionsChoice.then(function (choices) { - // choices = - // fieldLabels({ - // choices: choices - // }); - // _.map(choices, function(n, key) { - // $scope.permission_label[key] = n; - // }); - // }); - - // manipulate the choices from the options request to be usable - // by the search option for permission_type, you can't inject the - // list until this is done! - // permissionsChoice.then(function (choices) { - // form.related.permissions.fields.permission_type.searchOptions = - // permissionsSearchSelect({ - // choices: choices - // }); - // }); - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); generator.reset(); - $scope.$emit("loadForm"); - if ($scope.removeFormReady) { - $scope.removeFormReady(); - } - $scope.removeFormReady = $scope.$on('formReady', function () { - if ($scope.removePostRefresh) { - $scope.removePostRefresh(); - } - $scope.removePostRefresh = $scope.$on('PostRefresh', function () { - // Cleanup after a delete - Wait('stop'); - $('#prompt-modal').modal('hide'); - }); + var setScopeFields = function(data){ + _(data) + .pick(function(value, key){ + return form.fields.hasOwnProperty(key) === true; + }) + .forEach(function(value, key){ + $scope[key] = value; + }) + .value(); + return + }; - $scope.PermissionAddAllowed = false; - - // After the Organization is loaded, retrieve each related set - if ($scope.removeUserLoaded) { - $scope.removeUserLoaded(); - } - $scope.removeUserLoaded = $scope.$on('userLoaded', function () { - for (var set in relatedSets) { - $scope.search(relatedSets[set].iterator); + var setScopeRelated = function(data, related){ + _(related) + .pick(function(value, key){ + return data.related.hasOwnProperty(key) === true; + }) + .forEach(function(value, key){ + relatedSets[key] = { + url: data.related[key], + iterator: value.iterator + }; + }) + .value(); + }; + // prepares a data payload for a PUT request to the API + var processNewData = function(fields){ + var data = {}; + _.forEach(fields, function(value, key){ + if ($scope[key] !== '' && $scope[key] !== null && $scope[key] !== undefined){ + data[key] = $scope[key]; } - CheckAccess({ scope: $scope }); //Does the user have access to add/edit Permissions? - Wait('stop'); }); + return data + }; - // Retrieve detail record and prepopulate the form - Rest.setUrl(defaultUrl + ':id/'); - Rest.get({ params: { id: id } }) - .success(function (data) { - $scope.user_id = id; - $scope.username_title = data.username; - var fld, related, set; - for (fld in form.fields) { - if (data[fld]) { - if (fld === 'is_superuser') { - $scope[fld] = (data[fld] === 'true' || data[fld] === true) ? 'true' : 'false'; - } else { - $scope[fld] = data[fld]; - } - master[fld] = $scope[fld]; - } - } - related = data.related; - for (set in form.related) { - if (related[set]) { - relatedSets[set] = { - url: related[set], - iterator: form.related[set].iterator - }; - } - } + var init = function(){ + var url = defaultUrl + id; + Rest.setUrl(url); + Wait('start'); + Rest.get(url).success(function(data){ + $scope.user_id = id; + $scope.ldap_user = (data.ldap_dn !== null && data.ldap_dn !== undefined && data.ldap_dn !== '') ? true : false; + $scope.not_ldap_user = !$scope.ldap_user; + master.ldap_user = $scope.ldap_user; + $scope.socialAuthUser = (data.auth.length > 0) ? true : false; - $scope.ldap_user = (data.ldap_dn !== null && data.ldap_dn !== undefined && data.ldap_dn !== '') ? true : false; - $scope.not_ldap_user = !$scope.ldap_user; - master.ldap_user = $scope.ldap_user; - $scope.socialAuthUser = (data.auth.length > 0) ? true : false; + setScopeFields(data); + setScopeRelated(data, form.related); - // Initialize related search functions. Doing it here to make sure relatedSets object is populated. - RelatedSearchInit({ - scope: $scope, - form: form, - relatedSets: relatedSets - }); - RelatedPaginateInit({ - scope: $scope, - relatedSets: relatedSets - }); - $scope.$emit('userLoaded'); + RelatedSearchInit({ + scope: $scope, + form: form, + relatedSets: relatedSets + }); + RelatedPaginateInit({ + scope: $scope, + relatedSets: relatedSets + }); + Wait('stop'); + }) + .error(function (data, status) { + ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve user: ' + + $stateParams.id + '. GET status: ' + status }); + }); + }; + + $scope.formCancel = function(){ + $state.go('users', null, {reload: true}); + }; + + $scope.formSave = function(){ + generator.clearApiErrors(); + generator.checkAutoFill(); + $rootScope.flashMessage = null; + if ($scope[form.name + '_form'].$valid){ + Rest.setUrl(defaultUrl + id + '/'); + var data = processNewData(form.fields); + Rest.put(data).success(function(res){ + $state.go('users', null, {reload: true}) }) .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve user: ' + - $stateParams.id + '. GET status: ' + status }); - }); - - $scope.getPermissionText = function () { - if (this.permission.permission_type !== "admin" && this.permission.run_ad_hoc_commands) { - return $scope.permission_label[this.permission.permission_type] + - " and " + $scope.permission_label.adhoc; - } else { - return $scope.permission_label[this.permission.permission_type]; - } - }; - - // Save changes to the parent - $scope.formSave = function () { - var data = {}, fld; - generator.clearApiErrors(); - generator.checkAutoFill(); - $rootScope.flashMessage = null; - if ($scope[form.name + '_form'].$valid) { - Rest.setUrl(defaultUrl + id + '/'); - for (fld in form.fields) { - if (form.fields[fld].realName) { - data[form.fields[fld].realName] = $scope[fld]; - } else { - data[fld] = $scope[fld]; - } - } - - data.is_superuser = data.is_superuser || false; - - Wait('start'); - Rest.put(data) - .success(function () { - Wait('stop'); - $scope.username_title = $scope.username; - var base = $location.path().replace(/^\//, '').split('/')[0]; - if (base === 'users') { - ReturnToCaller(); - } - else { - ReturnToCaller(1); - } - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to update users: ' + $stateParams.id + - '. PUT status: ' + status }); - }); - } - }; - - $scope.formCancel = function () { - $state.transitionTo('users'); - }; - - // Password change - $scope.clearPWConfirm = function (fld) { - // If password value changes, make sure password_confirm must be re-entered - $scope[fld] = ''; - $scope[form.name + '_form'][fld].$setValidity('awpassmatch', false); - $rootScope.flashMessage = null; - }; - - - // Related set: Add button - $scope.add = function (set) { - $rootScope.flashMessage = null; - if (set === 'permissions') { - if ($scope.PermissionAddAllowed) { - $location.path('/' + base + '/' + $stateParams.user_id + '/' + set + '/add'); - } else { - Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.'); - } - } else { - $location.path('/' + base + '/' + $stateParams.user_id + '/' + set); - } - }; - - // Related set: Edit button - $scope.edit = function (set, id) { - $rootScope.flashMessage = null; - if (set === 'permissions') { - $location.path('/users/' + $stateParams.user_id + '/permissions/' + id); - } else { - $location.path('/' + set + '/' + id); - } - }; - - // Related set: Delete button - $scope['delete'] = function (set, itm_id, name, title) { - $rootScope.flashMessage = null; - - var action = function () { - var url; - if (set === 'permissions') { - if ($scope.PermissionAddAllowed) { - url = GetBasePath('base') + 'permissions/' + itm_id + '/'; - Rest.setUrl(url); - Rest.destroy() - .success(function () { - $('#prompt-modal').modal('hide'); - $scope.search(form.related[set].iterator); - }) - .error(function (data, status) { - $('#prompt-modal').modal('hide'); - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); - }); - } else { - Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.'); - } - } else { - url = defaultUrl + $stateParams.user_id + '/' + set + '/'; - Rest.setUrl(url); - Rest.post({ - id: itm_id, - disassociate: 1 - }) - .success(function () { - $('#prompt-modal').modal('hide'); - $scope.search(form.related[set].iterator); - }) - .error(function (data, status) { - $('#prompt-modal').modal('hide'); - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. POST returned status: ' + status }); - }); - } - }; - - Prompt({ - hdr: 'Delete', - body: '
Are you sure you want to remove the ' + title + ' below from ' + $scope.username + '?
' + name + '
', - action: action, - actionText: 'DELETE' - }); - }; - }); // $scope.$on - - // Put form back to its original state - ResetForm(); - - if ($scope.removeLoadForm) { - $scope.removeLoadForm(); - } - $scope.removeLoadForm = $scope.$on('loadForm', function () { - - - if ($scope.removeModifyForm) { - $scope.removeModifyForm(); + $stateParams.id + '. GET status: ' + status }); + }); } - $scope.removeModifyForm = $scope.$on('modifyForm', function () { - // Modify form based on LDAP settings - Rest.setUrl(GetBasePath('config')); - Rest.get() - .success(function (data) { - var i, fld; - if (data.user_ldap_fields) { - for (i = 0; i < data.user_ldap_fields.length; i++) { - fld = data.user_ldap_fields[i]; - if (form.fields[fld]) { - form.fields[fld].readonly = true; - form.fields[fld].editRequired = false; - if (form.fields[fld].awRequiredWhen) { - delete form.fields[fld].awRequiredWhen; - } - } - } - } - $scope.$emit('formReady'); - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to retrieve application config. GET status: ' + status }); - }); - }); + }; - Wait('start'); - Rest.setUrl(defaultUrl + id + '/'); - Rest.get() - .success(function (data) { - if (data.ldap_dn !== null && data.ldap_dn !== undefined && data.ldap_dn !== '') { - //this is an LDAP user - $scope.$emit('modifyForm'); - } else { - $scope.$emit('formReady'); - } - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to retrieve user: ' + id + '. GET status: ' + status }); - }); - }); + $scope.clearPWConfirm = function (fld) { + // If password value changes, make sure password_confirm must be re-entered + $scope[fld] = ''; + $scope[form.name + '_form'][fld].$setValidity('awpassmatch', false); + $rootScope.flashMessage = null; + }; + + init(); + + /* Related Set implementation TDB */ } -UsersEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', - '$stateParams', 'UserForm', 'GenerateForm', 'Rest', 'Alert', - 'ProcessErrors', 'RelatedSearchInit', 'RelatedPaginateInit', - 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Prompt', 'CheckAccess', - 'ResetForm', 'Wait', 'fieldChoices', 'fieldLabels', - 'permissionsSearchSelect', '$state' +UsersEdit.$inject = ['$scope', '$rootScope', '$location', + '$stateParams', 'UserForm', 'GenerateForm', 'Rest', 'ProcessErrors', + 'RelatedSearchInit', 'RelatedPaginateInit', 'ClearScope', 'GetBasePath', + 'ResetForm', 'Wait', '$state' ]; diff --git a/awx/ui/client/src/forms/Teams.js b/awx/ui/client/src/forms/Teams.js index 45bc14ecbd..e15b191900 100644 --- a/awx/ui/client/src/forms/Teams.js +++ b/awx/ui/client/src/forms/Teams.js @@ -38,10 +38,12 @@ export default type: 'lookup', sourceModel: 'organization', sourceField: 'name', + addRequired: true, + editRequire: false, ngClick: 'lookUpOrganization()', awRequiredWhen: { - variable: "teamrequired", - init: "true" + variable: "orgrequired", + init: true } } }, @@ -57,6 +59,27 @@ export default }, related: { + /* + permissions: { + basePath: 'teams/:id/access_list/', + type: 'collection', + title: 'Permissions', + iterator: 'permission', + index: false, + open: false, + searchType: 'select', + actions: { + add: { + ngClick: "addPermission", + label: 'Add', + awToolTip: 'Add a permission', + actionClass: 'btn List-buttonSubmit', + buttonContent: '+ ADD' + } + } + }, + */ + credentials: { type: 'collection', @@ -103,70 +126,6 @@ export default } }, - permissions: { - type: 'collection', - title: 'Permissions', - iterator: 'permission', - open: false, - index: false, - - actions: { - add: { - ngClick: "add('permissions')", - label: 'Add', - awToolTip: 'Add a permission for this user', - ngShow: 'PermissionAddAllowed', - actionClass: 'btn List-buttonSubmit', - buttonContent: '+ ADD' - } - }, - - fields: { - name: { - key: true, - label: 'Name', - ngClick: "edit('permissions', permission.id, permission.name)" - }, - inventory: { - label: 'Inventory', - sourceModel: 'inventory', - sourceField: 'name', - ngBind: 'permission.summary_fields.inventory.name' - }, - project: { - label: 'Project', - sourceModel: 'project', - sourceField: 'name', - ngBind: 'permission.summary_fields.project.name' - }, - permission_type: { - label: 'Permission', - ngBind: 'getPermissionText()', - searchType: 'select' - } - }, - - fieldActions: { - edit: { - label: 'Edit', - ngClick: "edit('permissions', permission.id, permission.name)", - icon: 'icon-edit', - awToolTip: 'Edit the permission', - 'class': 'btn btn-default' - }, - - "delete": { - label: 'Delete', - ngClick: "delete('permissions', permission.id, permission.name, 'permission')", - icon: 'icon-trash', - "class": 'btn-danger', - awToolTip: 'Delete the permission', - ngShow: 'PermissionAddAllowed' - } - } - - }, - projects: { type: 'collection', title: 'Projects', diff --git a/awx/ui/client/src/forms/Users.js b/awx/ui/client/src/forms/Users.js index 820f86a8cf..f3af8243c7 100644 --- a/awx/ui/client/src/forms/Users.js +++ b/awx/ui/client/src/forms/Users.js @@ -42,18 +42,6 @@ export default editRequired: true, autocomplete: false }, - organization: { - label: 'Organization', - type: 'lookup', - sourceModel: 'organization', - sourceField: 'name', - ngClick: 'lookUpOrganization()', - excludeMode: 'edit', - awRequiredWhen: { - variable: "orgrequired", - init: true - } - }, username: { label: 'Username', type: 'text', @@ -63,6 +51,20 @@ export default }, autocomplete: false }, + organization: { + label: 'Organization', + type: 'lookup', + sourceModel: 'organization', + sourceField: 'name', + addRequired: true, + editRequired: false, + excludeMode: 'edit', + ngClick: 'lookUpOrganization()', + awRequiredWhen: { + variable: "orgrequired", + init: true + } + }, password: { label: 'Password', type: 'sensitive', @@ -86,12 +88,13 @@ export default autocomplete: false }, is_superuser: { - label: 'Superuser (User has full system administration privileges.)', + label: 'Superuser (User has full system administration privileges)', type: 'checkbox', trueValue: 'true', falseValue: 'false', "default": 'false', - ngShow: "current_user['is_superuser'] == true" + ngShow: "current_user['is_superuser'] == true", + ngModel: 'is_superuser' }, ldap_user: { label: 'Created by LDAP', @@ -112,6 +115,26 @@ export default }, related: { + /* + permissions: { + basePath: 'teams/:id/access_list/', + type: 'collection', + title: 'Permissions', + iterator: 'permission', + index: false, + open: false, + searchType: 'select', + actions: { + add: { + ngClick: "addPermission", + label: 'Add', + awToolTip: 'Add a permission', + actionClass: 'btn List-buttonSubmit', + buttonContent: '+ ADD' + } + } + }, + */ credentials: { type: 'collection', @@ -157,92 +180,6 @@ export default } } }, - - // permissions: { - // type: 'collection', - // title: 'Permissions', - // iterator: 'permission', - // open: false, - // index: false, - // - // actions: { - // add: { - // ngClick: "add('permissions')", - // label: 'Add', - // awToolTip: 'Add a permission for this user', - // ngShow: 'PermissionAddAllowed', - // actionClass: 'btn List-buttonSubmit', - // buttonContent: '+ ADD' - // } - // }, - // - // fields: { - // name: { - // key: true, - // label: 'Name', - // ngClick: "edit('permissions', permission.id, permission.name)" - // }, - // inventory: { - // label: 'Inventory', - // sourceModel: 'inventory', - // sourceField: 'name', - // ngBind: 'permission.summary_fields.inventory.name' - // }, - // project: { - // label: 'Project', - // sourceModel: 'project', - // sourceField: 'name', - // ngBind: 'permission.summary_fields.project.name' - // }, - // permission_type: { - // label: 'Permission', - // ngBind: 'getPermissionText()', - // searchType: 'select' - // } - // }, - // - // fieldActions: { - // edit: { - // label: 'Edit', - // ngClick: "edit('permissions', permission.id, permission.name)", - // icon: 'icon-edit', - // awToolTip: 'Edit the permission', - // 'class': 'btn btn-default' - // }, - // - // "delete": { - // label: 'Delete', - // ngClick: "delete('permissions', permission.id, permission.name, 'permission')", - // icon: 'icon-trash', - // "class": 'btn-danger', - // awToolTip: 'Delete the permission', - // ngShow: 'PermissionAddAllowed' - // } - // } - // - // }, - - admin_of_organizations: { // Assumes a plural name (e.g. things) - type: 'collection', - title: 'Admin of Organizations', - iterator: 'adminof', // Singular form of name (e.g. thing) - open: false, // Open accordion on load? - index: false, - base: '/organizations', - - actions: {}, - - fields: { - name: { - key: true, - label: 'Name' - }, - description: { - label: 'Description' - } - } - }, - organizations: { type: 'collection', title: 'Organizations',