diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js
index 227c06d06b..c49b6ba541 100644
--- a/awx/ui/static/js/app.js
+++ b/awx/ui/static/js/app.js
@@ -16,6 +16,7 @@ angular.module('ansible', [
'FormGenerator',
'OrganizationListDefinition',
'UserListDefinition',
+ 'UserHelper',
'ListGenerator',
'PromptDialog',
'ApiLoader',
diff --git a/awx/ui/static/js/controllers/Users.js b/awx/ui/static/js/controllers/Users.js
index e992e437b2..280ffe2fbe 100644
--- a/awx/ui/static/js/controllers/Users.js
+++ b/awx/ui/static/js/controllers/Users.js
@@ -75,7 +75,7 @@ UsersList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams
function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
- GetBasePath, LookUpInit, OrganizationList)
+ GetBasePath, LookUpInit, OrganizationList, ResetForm)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -83,20 +83,12 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
// Inject dynamic view
var defaultUrl = GetBasePath('organizations');
var form = UserForm;
-
- // Restore form to default condition. It may have been modified during edit of an LDAP user
- form.fields['first_name'].readonly = false;
- form.fields['first_name'].editRequired = true;
- form.fields['last_name'].readonly = false;
- form.fields['last_name'].editRequired = true;
- form.fields['email'].readonly = false;
- form.fields['email'].editRequired = true;
- form.fields['organization'].awRequiredWhen = { variable: "orgrequired", init: true};
-
+ ResetForm();
var generator = GenerateForm;
var scope = generator.inject(form, {mode: 'add', related: false});
- scope.not_ldap_user = true;
+ scope.ldap_user = false;
+ scope.not_ldap_user = !scope.ldap_user;
scope.ldap_dn = null;
generator.reset();
@@ -164,6 +156,7 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
scope.formReset = function() {
// Defaults
generator.reset();
+ scope.ldap_user = false;
};
// Password change
@@ -176,12 +169,12 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
UsersAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath',
- 'LookUpInit', 'OrganizationList' ];
+ 'LookUpInit', 'OrganizationList', 'ResetForm' ];
function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
- RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath, Prompt, CheckAccess)
+ RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath, Prompt, CheckAccess, ResetForm)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -190,14 +183,17 @@ function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
var generator = GenerateForm;
var form = UserForm;
var base = $location.path().replace(/^\//,'').split('/')[0];
-
- $scope.$on('formReady', function() {
+ var master = {};
+ var id = $routeParams.user_id;
+ var relatedSets = {};
+
+ if ($scope.removeFormReady) {
+ $scope.removeFormReady();
+ }
+ $scope.removeFormReady = $scope.$on('formReady', function() {
var scope = generator.inject(form, {mode: 'edit', related: true});
generator.reset();
- var master = {};
- var id = $routeParams.user_id;
- var relatedSets = {};
-
+
scope.PermissionAddAllowed = false;
// After the Organization is loaded, retrieve each related set
@@ -231,7 +227,9 @@ function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
}
}
- scope.not_ldap_user = (scope.ldap_dn) ? false : true;
+ 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;
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
@@ -360,41 +358,59 @@ function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
}
}); // $scope.$on
-
- // Restore form to default condition
- form.fields['first_name'].readonly = false;
- form.fields['first_name'].editRequired = true;
- form.fields['last_name'].readonly = false;
- form.fields['last_name'].editRequired = true;
- form.fields['email'].readonly = false;
- form.fields['email'].editRequired = true;
- form.fields['organization'].awRequiredWhen = { variable: "orgrequired", init: true};
-
- // Modify form based on LDAP settings
- Rest.setUrl(GetBasePath('config'));
- Rest.get()
- .success( function(data, status, headers, config) {
- if (data['user_ldap_fields']) {
- for (var i in data['user_ldap_fields']) {
- var 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;
+
+ // Put form back to its original state
+ ResetForm();
+
+
+ if ($scope.removeModifyForm) {
+ $scope.removeModifyForm();
+ }
+ $scope.removeModifyForm = $scope.$on('modifyForm', function() {
+ // Modify form based on LDAP settings
+ Rest.setUrl(GetBasePath('config'));
+ Rest.get()
+ .success( function(data, status, headers, config) {
+ if (data['user_ldap_fields']) {
+ var fld;
+ for (var 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, headers, config) {
- ProcessErrors(scope, data, status, null,
- { hdr: 'Error!', msg: 'Failed to retrieve application config. GET status: ' + status });
+ }
+ $scope.$emit('formReady');
+ })
+ .error( function(data, status, headers, config) {
+ ProcessErrors($scope, data, status, null,
+ { hdr: 'Error!', msg: 'Failed to retrieve application config. GET status: ' + status });
+ });
});
+
+ Rest.setUrl(defaultUrl + id + '/');
+ Rest.get()
+ .success( function(data, status, headers, config) {
+ 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, headers, config) {
+ ProcessErrors($scope, data, status, null,
+ { hdr: 'Error!', msg: 'Failed to retrieve user: ' + id + '. GET status: ' + status });
+ });
}
UsersEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
- 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Prompt', 'CheckAccess'];
+ 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Prompt', 'CheckAccess',
+ 'ResetForm' ];
diff --git a/awx/ui/static/js/forms/Users.js b/awx/ui/static/js/forms/Users.js
index d3a23f7589..b882c26319 100644
--- a/awx/ui/static/js/forms/Users.js
+++ b/awx/ui/static/js/forms/Users.js
@@ -56,7 +56,7 @@ angular.module('UserFormDefinition', [])
awRequiredWhen: { variable: "not_ldap_user", init: true },
autocomplete: false
},
- ldap_dn: {
+ ldap_user: {
label: 'Created by LDAP?',
type: 'checkbox',
readonly: true
@@ -64,7 +64,7 @@ angular.module('UserFormDefinition', [])
password: {
label: 'Password',
type: 'password',
- ngShow: 'not_ldap_user == true',
+ ngShow: 'ldap_user == false',
awRequiredWhen: { variable: "not_ldap_user", init: true},
ngChange: "clearPWConfirm('password_confirm')",
autocomplete: false,
@@ -73,7 +73,7 @@ angular.module('UserFormDefinition', [])
password_confirm: {
label: 'Confirm Password',
type: 'password',
- ngShow: 'not_ldap_user == true',
+ ngShow: 'ldap_user == false',
addRequired: false,
editRequired: false,
awPassMatch: true,
diff --git a/awx/ui/static/js/helpers/Users.js b/awx/ui/static/js/helpers/Users.js
new file mode 100644
index 0000000000..475e1c2a6c
--- /dev/null
+++ b/awx/ui/static/js/helpers/Users.js
@@ -0,0 +1,29 @@
+/*********************************************
+ * Copyright (c) 2013 AnsibleWorks, Inc.
+ *
+ * UserHelper
+ * Routines shared amongst the user controllers
+ */
+
+angular.module('UserHelper', [ 'UserFormDefinition' ])
+ .factory('ResetForm', ['UserForm', function(UserForm) {
+ return function() {
+ // Restore form to default conditions. Run before applying LDAP configuration.
+ // LDAP may manage some or all of these fields in which case the user cannot
+ // make changes to their values in AWX.
+
+ UserForm.fields['first_name'].readonly = false;
+ UserForm.fields['first_name'].editRequired = true;
+ UserForm.fields['last_name'].readonly = false;
+ UserForm.fields['last_name'].editRequired = true;
+ UserForm.fields['email'].readonly = false;
+ UserForm.fields['email'].editRequired = true;
+ UserForm.fields['organization'].awRequiredWhen = { variable: "orgrequired", init: true};
+ UserForm.fields['organization'].readonly = false;
+ UserForm.fields['username'].awRequiredWhen = { variable: "not_ldap_user", init: true };
+ UserForm.fields['username'].readonly = false;
+ UserForm.fields['password'].awRequiredWhen = { variable: "not_ldap_user", init: true },
+ UserForm.fields['password'].readonly = false;
+
+ }
+ }]);
\ No newline at end of file
diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html
index 8ff46a77c0..b8de52419f 100644
--- a/awx/ui/templates/ui/index.html
+++ b/awx/ui/templates/ui/index.html
@@ -103,6 +103,7 @@
+