From 58f142e2e6291f9e280a29dee17067ff6a9bb0c9 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 18 May 2016 16:05:35 -0400 Subject: [PATCH] Update user add/edit UI to support System Auditor setting Also moved the LDAP indicator to be inline with the mockups (bubble next to the uesrname in the upper left) #1937 #1888 --- awx/ui/client/legacy-styles/forms.less | 4 +- awx/ui/client/src/controllers/Users.js | 67 ++++++++++++++++++++-- awx/ui/client/src/forms/Users.js | 20 ++----- awx/ui/client/src/shared/form-generator.js | 11 +++- 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/awx/ui/client/legacy-styles/forms.less b/awx/ui/client/legacy-styles/forms.less index 20bf364141..c8f30a3d16 100644 --- a/awx/ui/client/legacy-styles/forms.less +++ b/awx/ui/client/legacy-styles/forms.less @@ -49,7 +49,7 @@ min-height: 40px; } -.Form-title--is_superuser{ +.Form-title--is_superuser, .Form-title--is_system_auditor, .Form-title--is_ldap_user{ height:15px; color: @default-interface-txt; background-color: @default-list-header-bg; @@ -61,7 +61,7 @@ margin-left: 10px; text-transform: uppercase; font-weight: 100; - position: absolute; + //position: absolute; margin-top: 2.25px; height: 16px; } diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index f6ac43d219..09bde96e87 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -10,6 +10,26 @@ * @description This controller's the Users page */ +const user_type_options = [ + {type: 'normal' , label: 'Normal User' }, + {type: 'system_auditor' , label: 'System Auditor' }, + {type: 'system_administrator', label: 'System Administrator' }, +]; + +function user_type_sync($scope) { + return (type_option) => { + $scope.is_superuser = false; + $scope.is_system_auditor = false; + switch (type_option.type) { + case 'system_administrator': + $scope.is_superuser = true; + break; + case 'system_auditor': + $scope.is_system_auditor = true; + break; + } + }; +} export function UsersList($scope, $rootScope, $location, $log, $stateParams, Rest, Alert, UserList, GenerateList, Prompt, SearchInit, PaginateInit, @@ -116,10 +136,13 @@ UsersList.$inject = ['$scope', '$rootScope', '$location', '$log', ]; + + + export function UsersAdd($scope, $rootScope, $compile, $location, $log, $stateParams, UserForm, GenerateForm, Rest, Alert, ProcessErrors, ReturnToCaller, ClearScope, GetBasePath, LookUpInit, OrganizationList, - ResetForm, Wait, $state) { + ResetForm, Wait, CreateSelect2, $state) { ClearScope(); @@ -138,6 +161,15 @@ export function UsersAdd($scope, $rootScope, $compile, $location, $log, generator.reset(); + $scope.user_type_options = user_type_options; + $scope.user_type = user_type_options[0] + $scope.$watch('user_type', user_type_sync($scope)); + + CreateSelect2({ + element: '#user_user_type', + multiple: false + }); + // Configure the lookup dialog. If we're adding a user through the Organizations tab, // default the Organization value. LookUpInit({ @@ -177,7 +209,8 @@ export function UsersAdd($scope, $rootScope, $compile, $location, $log, data[fld] = $scope[fld]; } } - data.is_superuser = data.is_superuser || false; + data.is_superuser = $scope.is_superuser; + data.is_system_auditor = $scope.is_system_auditor; Wait('start'); Rest.post(data) .success(function (data) { @@ -215,14 +248,14 @@ export function UsersAdd($scope, $rootScope, $compile, $location, $log, UsersAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$stateParams', 'UserForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', - 'LookUpInit', 'OrganizationList', 'ResetForm', 'Wait', '$state' + 'LookUpInit', 'OrganizationList', 'ResetForm', 'Wait', 'CreateSelect2', '$state' ]; export function UsersEdit($scope, $rootScope, $location, $stateParams, UserForm, GenerateForm, Rest, ProcessErrors, RelatedSearchInit, RelatedPaginateInit, ClearScope, - GetBasePath, ResetForm, Wait, $state) { + GetBasePath, ResetForm, Wait, CreateSelect2 ,$state) { ClearScope(); @@ -237,6 +270,10 @@ export function UsersEdit($scope, $rootScope, $location, generator.inject(form, { mode: 'edit', related: true, scope: $scope }); generator.reset(); + $scope.user_type_options = user_type_options; + $scope.user_type = user_type_options[0] + $scope.$watch('user_type', user_type_sync($scope)); + var setScopeFields = function(data){ _(data) .pick(function(value, key){ @@ -278,6 +315,8 @@ export function UsersEdit($scope, $rootScope, $location, data[key] = $scope[key]; } }); + data.is_superuser = $scope.is_superuser; + data.is_system_auditor = $scope.is_system_auditor; return data; }; @@ -292,6 +331,24 @@ export function UsersEdit($scope, $rootScope, $location, master.ldap_user = $scope.ldap_user; $scope.socialAuthUser = (data.auth.length > 0) ? true : false; + $scope.user_type = $scope.user_type_options[0]; + $scope.is_system_auditor = false; + $scope.is_superuser = false; + if (data.is_system_auditor) { + $scope.user_type = $scope.user_type_options[1]; + $scope.is_system_auditor = true; + } + if (data.is_superuser) { + $scope.user_type = $scope.user_type_options[2]; + $scope.is_superuser = true; + } + + CreateSelect2({ + element: '#user_user_type', + multiple: false + }); + + setScopeFields(data); setScopeRelated(data, form.related); @@ -353,5 +410,5 @@ export function UsersEdit($scope, $rootScope, $location, UsersEdit.$inject = ['$scope', '$rootScope', '$location', '$stateParams', 'UserForm', 'GenerateForm', 'Rest', 'ProcessErrors', 'RelatedSearchInit', 'RelatedPaginateInit', 'ClearScope', 'GetBasePath', - 'ResetForm', 'Wait', '$state' + 'ResetForm', 'Wait', 'CreateSelect2', '$state' ]; diff --git a/awx/ui/client/src/forms/Users.js b/awx/ui/client/src/forms/Users.js index 1fa3db40d6..03d816749b 100644 --- a/awx/ui/client/src/forms/Users.js +++ b/awx/ui/client/src/forms/Users.js @@ -87,21 +87,13 @@ export default associated: 'password', autocomplete: false }, - is_superuser: { - label: 'Superuser (User has full system administration privileges)', - type: 'checkbox', - trueValue: 'true', - falseValue: 'false', - "default": 'false', - ngShow: "current_user['is_superuser'] == true", - ngModel: 'is_superuser' + user_type: { + label: 'User Type', + type: 'select', + ngOptions: 'item as item.label for item in user_type_options track by item.type', + disableChooseOption: true, + ngModel: 'user_type', }, - ldap_user: { - label: 'Created by LDAP', - type: 'checkbox', - readonly: true, - awFeature: 'ldap' - } }, buttons: { diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index c9e367886e..60e6f1e7a9 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -1101,7 +1101,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += "
\n"; html += "