mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
AC-435 latest LDAP changes for UI.
This commit is contained in:
@@ -16,6 +16,7 @@ angular.module('ansible', [
|
|||||||
'FormGenerator',
|
'FormGenerator',
|
||||||
'OrganizationListDefinition',
|
'OrganizationListDefinition',
|
||||||
'UserListDefinition',
|
'UserListDefinition',
|
||||||
|
'UserHelper',
|
||||||
'ListGenerator',
|
'ListGenerator',
|
||||||
'PromptDialog',
|
'PromptDialog',
|
||||||
'ApiLoader',
|
'ApiLoader',
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ UsersList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams
|
|||||||
|
|
||||||
function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
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
|
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||||
//scope.
|
//scope.
|
||||||
@@ -83,20 +83,12 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
// Inject dynamic view
|
// Inject dynamic view
|
||||||
var defaultUrl = GetBasePath('organizations');
|
var defaultUrl = GetBasePath('organizations');
|
||||||
var form = UserForm;
|
var form = UserForm;
|
||||||
|
ResetForm();
|
||||||
// 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};
|
|
||||||
|
|
||||||
var generator = GenerateForm;
|
var generator = GenerateForm;
|
||||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
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;
|
scope.ldap_dn = null;
|
||||||
|
|
||||||
generator.reset();
|
generator.reset();
|
||||||
@@ -164,6 +156,7 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
scope.formReset = function() {
|
scope.formReset = function() {
|
||||||
// Defaults
|
// Defaults
|
||||||
generator.reset();
|
generator.reset();
|
||||||
|
scope.ldap_user = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Password change
|
// Password change
|
||||||
@@ -176,12 +169,12 @@ function UsersAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
|
|
||||||
UsersAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
|
UsersAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
|
||||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath',
|
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath',
|
||||||
'LookUpInit', 'OrganizationList' ];
|
'LookUpInit', 'OrganizationList', 'ResetForm' ];
|
||||||
|
|
||||||
|
|
||||||
function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
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
|
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||||
//scope.
|
//scope.
|
||||||
@@ -190,14 +183,17 @@ function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
var generator = GenerateForm;
|
var generator = GenerateForm;
|
||||||
var form = UserForm;
|
var form = UserForm;
|
||||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
|
var master = {};
|
||||||
$scope.$on('formReady', function() {
|
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});
|
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||||
generator.reset();
|
generator.reset();
|
||||||
var master = {};
|
|
||||||
var id = $routeParams.user_id;
|
|
||||||
var relatedSets = {};
|
|
||||||
|
|
||||||
scope.PermissionAddAllowed = false;
|
scope.PermissionAddAllowed = false;
|
||||||
|
|
||||||
// After the Organization is loaded, retrieve each related set
|
// 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.
|
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||||
@@ -360,41 +358,59 @@ function UsersEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
}
|
}
|
||||||
|
|
||||||
}); // $scope.$on
|
}); // $scope.$on
|
||||||
|
|
||||||
// Restore form to default condition
|
// Put form back to its original state
|
||||||
form.fields['first_name'].readonly = false;
|
ResetForm();
|
||||||
form.fields['first_name'].editRequired = true;
|
|
||||||
form.fields['last_name'].readonly = false;
|
|
||||||
form.fields['last_name'].editRequired = true;
|
if ($scope.removeModifyForm) {
|
||||||
form.fields['email'].readonly = false;
|
$scope.removeModifyForm();
|
||||||
form.fields['email'].editRequired = true;
|
}
|
||||||
form.fields['organization'].awRequiredWhen = { variable: "orgrequired", init: true};
|
$scope.removeModifyForm = $scope.$on('modifyForm', function() {
|
||||||
|
// Modify form based on LDAP settings
|
||||||
// Modify form based on LDAP settings
|
Rest.setUrl(GetBasePath('config'));
|
||||||
Rest.setUrl(GetBasePath('config'));
|
Rest.get()
|
||||||
Rest.get()
|
.success( function(data, status, headers, config) {
|
||||||
.success( function(data, status, headers, config) {
|
if (data['user_ldap_fields']) {
|
||||||
if (data['user_ldap_fields']) {
|
var fld;
|
||||||
for (var i in data['user_ldap_fields']) {
|
for (var i=0; i < data['user_ldap_fields'].length; i++) {
|
||||||
var fld = data['user_ldap_fields'][i];
|
fld = data['user_ldap_fields'][i];
|
||||||
if (form.fields[fld]) {
|
if (form.fields[fld]) {
|
||||||
form.fields[fld]['readonly'] = true;
|
form.fields[fld]['readonly'] = true;
|
||||||
form.fields[fld]['editRequired'] = false;
|
form.fields[fld]['editRequired'] = false;
|
||||||
if (form.fields[fld].awRequiredWhen) {
|
if (form.fields[fld].awRequiredWhen) {
|
||||||
delete form.fields[fld].awRequiredWhen;
|
delete form.fields[fld].awRequiredWhen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
$scope.$emit('formReady');
|
||||||
$scope.$emit('formReady');
|
})
|
||||||
})
|
.error( function(data, status, headers, config) {
|
||||||
.error( function(data, status, headers, config) {
|
ProcessErrors($scope, data, status, null,
|
||||||
ProcessErrors(scope, data, status, null,
|
{ hdr: 'Error!', msg: 'Failed to retrieve application config. GET status: ' + status });
|
||||||
{ 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',
|
UsersEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Prompt', 'CheckAccess'];
|
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Prompt', 'CheckAccess',
|
||||||
|
'ResetForm' ];
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ angular.module('UserFormDefinition', [])
|
|||||||
awRequiredWhen: { variable: "not_ldap_user", init: true },
|
awRequiredWhen: { variable: "not_ldap_user", init: true },
|
||||||
autocomplete: false
|
autocomplete: false
|
||||||
},
|
},
|
||||||
ldap_dn: {
|
ldap_user: {
|
||||||
label: 'Created by LDAP?',
|
label: 'Created by LDAP?',
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
readonly: true
|
readonly: true
|
||||||
@@ -64,7 +64,7 @@ angular.module('UserFormDefinition', [])
|
|||||||
password: {
|
password: {
|
||||||
label: 'Password',
|
label: 'Password',
|
||||||
type: 'password',
|
type: 'password',
|
||||||
ngShow: 'not_ldap_user == true',
|
ngShow: 'ldap_user == false',
|
||||||
awRequiredWhen: { variable: "not_ldap_user", init: true},
|
awRequiredWhen: { variable: "not_ldap_user", init: true},
|
||||||
ngChange: "clearPWConfirm('password_confirm')",
|
ngChange: "clearPWConfirm('password_confirm')",
|
||||||
autocomplete: false,
|
autocomplete: false,
|
||||||
@@ -73,7 +73,7 @@ angular.module('UserFormDefinition', [])
|
|||||||
password_confirm: {
|
password_confirm: {
|
||||||
label: 'Confirm Password',
|
label: 'Confirm Password',
|
||||||
type: 'password',
|
type: 'password',
|
||||||
ngShow: 'not_ldap_user == true',
|
ngShow: 'ldap_user == false',
|
||||||
addRequired: false,
|
addRequired: false,
|
||||||
editRequired: false,
|
editRequired: false,
|
||||||
awPassMatch: true,
|
awPassMatch: true,
|
||||||
|
|||||||
29
awx/ui/static/js/helpers/Users.js
Normal file
29
awx/ui/static/js/helpers/Users.js
Normal file
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}]);
|
||||||
@@ -103,6 +103,7 @@
|
|||||||
<script src="{{ STATIC_URL }}js/helpers/Access.js"></script>
|
<script src="{{ STATIC_URL }}js/helpers/Access.js"></script>
|
||||||
<script src="{{ STATIC_URL }}js/helpers/Selection.js"></script>
|
<script src="{{ STATIC_URL }}js/helpers/Selection.js"></script>
|
||||||
<script src="{{ STATIC_URL }}js/helpers/Projects.js"></script>
|
<script src="{{ STATIC_URL }}js/helpers/Projects.js"></script>
|
||||||
|
<script src="{{ STATIC_URL }}js/helpers/Users.js"></script>
|
||||||
|
|
||||||
<script src="{{ STATIC_URL }}lib/less/less-1.4.1.min.js"></script>
|
<script src="{{ STATIC_URL }}lib/less/less-1.4.1.min.js"></script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user