mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
AC-1083 more better handling of missing machine credentials when submitting a job.
This commit is contained in:
parent
1e50f0cc24
commit
c7d489026e
@ -101,7 +101,6 @@ function CredentialsList($scope, $rootScope, $location, $log, $routeParams, Rest
|
||||
};
|
||||
|
||||
$scope.deleteCredential = function (id, name) {
|
||||
|
||||
var action = function () {
|
||||
$('#prompt-modal').on('hidden.bs.modal', function () {
|
||||
Wait('start');
|
||||
@ -121,7 +120,7 @@ function CredentialsList($scope, $rootScope, $location, $log, $routeParams, Rest
|
||||
|
||||
Prompt({
|
||||
hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
body: "<div class=\"alert alert-info\">Delete credential " + name + "?</div>",
|
||||
action: action
|
||||
});
|
||||
};
|
||||
|
@ -87,7 +87,7 @@ function OrganizationsList($routeParams, $scope, $rootScope, $location, $log, Re
|
||||
|
||||
Prompt({
|
||||
hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
body: "<div class\"alert alert-info\">Delete organization " + name + "?</div>",
|
||||
action: action
|
||||
});
|
||||
};
|
||||
|
@ -30,8 +30,8 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential
|
||||
};
|
||||
}])
|
||||
|
||||
.factory('PromptForCredential', ['Wait', 'GetBasePath', 'LookUpInit', 'JobTemplateForm', 'CredentialList',
|
||||
function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
.factory('PromptForCredential', ['$location', 'Wait', 'GetBasePath', 'LookUpInit', 'JobTemplateForm', 'CredentialList', 'Rest', 'Prompt', 'ProcessErrors',
|
||||
function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList, Rest, Prompt, ProcessErrors) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope,
|
||||
@ -41,22 +41,59 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
Wait('stop');
|
||||
scope.credential = '';
|
||||
|
||||
selectionMade = function () {
|
||||
scope.$emit(callback, scope.credential);
|
||||
};
|
||||
|
||||
LookUpInit({
|
||||
url: GetBasePath('credentials') + '?kind=ssh',
|
||||
scope: scope,
|
||||
form: JobTemplateForm(),
|
||||
current_item: null,
|
||||
list: CredentialList,
|
||||
field: 'credential',
|
||||
hdr: 'Credential Required',
|
||||
instructions: "Launching this job requires a machine credential. Please select your machine credential now or Cancel to quit.",
|
||||
postAction: selectionMade
|
||||
if (scope.removeShowLookupDialog) {
|
||||
scope.removeShowLookupDialog();
|
||||
}
|
||||
scope.removeShowLookupDialog = scope.$on('ShowLookupDialog', function() {
|
||||
selectionMade = function () {
|
||||
scope.$emit(callback, scope.credential);
|
||||
};
|
||||
|
||||
LookUpInit({
|
||||
url: GetBasePath('credentials') + '?kind=ssh',
|
||||
scope: scope,
|
||||
form: JobTemplateForm(),
|
||||
current_item: null,
|
||||
list: CredentialList,
|
||||
field: 'credential',
|
||||
hdr: 'Credential Required',
|
||||
instructions: "Launching this job requires a machine credential. Please select your machine credential now or Cancel to quit.",
|
||||
postAction: selectionMade
|
||||
});
|
||||
scope.lookUpCredential();
|
||||
});
|
||||
scope.lookUpCredential();
|
||||
|
||||
if (scope.removeAlertNoCredentials) {
|
||||
scope.removeAlertNoCredentials();
|
||||
}
|
||||
scope.removeAlertNoCredentials = scope.$on('AlertNoCredentials', function() {
|
||||
var action = function () {
|
||||
$('#prompt-modal').modal('hide');
|
||||
$location.url('/credentials/add');
|
||||
};
|
||||
|
||||
Prompt({
|
||||
hdr: 'Machine Credential Required',
|
||||
body: "<div class=\"alert alert-info\">There are no machine credentials defined in Tower. Launching this job requires a machine credential. " +
|
||||
"Create one now?",
|
||||
action: action
|
||||
});
|
||||
});
|
||||
|
||||
Rest.setUrl(GetBasePath('credentials') + '?kind=ssh');
|
||||
Rest.get()
|
||||
.success(function(data) {
|
||||
if (data.results.length > 0) {
|
||||
scope.$emit('ShowLookupDialog');
|
||||
}
|
||||
else {
|
||||
scope.$emit('AlertNoCredentials');
|
||||
}
|
||||
})
|
||||
.error(function(data,status) {
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
||||
msg: 'Checking for machine credentials failed. GET returned: ' + status });
|
||||
});
|
||||
};
|
||||
}])
|
||||
|
||||
@ -76,10 +113,11 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
|
||||
function promptPassword() {
|
||||
var e, fld, field;
|
||||
|
||||
console.log(passwords);
|
||||
password = passwords.pop();
|
||||
|
||||
// Prompt for password
|
||||
html = "";
|
||||
html += "<form name=\"password_form\" novalidate>\n";
|
||||
field = form.fields[password];
|
||||
fld = password;
|
||||
@ -123,7 +161,7 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
html += "</div>\n";
|
||||
}
|
||||
html += "</form>\n";
|
||||
$('#password-body').empty().html(html);
|
||||
$('#password-body').html(html);
|
||||
e = angular.element(document.getElementById('password-modal'));
|
||||
$compile(e)(scope);
|
||||
$('#password-modal').modal();
|
||||
@ -134,9 +172,13 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
|
||||
scope.passwordAccept = function() {
|
||||
$('#password-modal').modal('hide');
|
||||
$('#password-modal').off('shown.bs.modal');
|
||||
$('#password-body').empty();
|
||||
acceptedPasswords[password] = scope[password];
|
||||
if (passwords.length > 0) {
|
||||
promptPassword();
|
||||
setTimeout(function() {
|
||||
promptPassword();
|
||||
}, 500);
|
||||
}
|
||||
else {
|
||||
parent_scope.$emit(callback, acceptedPasswords);
|
||||
@ -146,11 +188,12 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
|
||||
|
||||
scope.passwordCancel = function() {
|
||||
$('#password-modal').modal('hide');
|
||||
$('#password-modal').off('shown.bs.modal');
|
||||
$('#password-body').empty();
|
||||
Alert('Missing Password', 'Required password(s) not provided. Your request will not be submitted.', 'alert-info');
|
||||
parent_scope.$emit('PasswordsCanceled');
|
||||
scope.$destroy();
|
||||
};
|
||||
|
||||
promptPassword();
|
||||
};
|
||||
}])
|
||||
|
@ -856,12 +856,12 @@ input[type="checkbox"].checkbox-no-label {
|
||||
.list-actions {
|
||||
margin: 0;
|
||||
}
|
||||
.list-wrapper {
|
||||
/*.list-wrapper {
|
||||
background-color: @well;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid @well-border;
|
||||
}
|
||||
}*/
|
||||
.ui-accordion-content {
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
|
@ -75,14 +75,14 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
||||
* alert-info...). Pass an optional function(){}, if you want a specific action to occur when user
|
||||
* clicks 'OK' button. Set secondAlert to true, when a second dialog is needed.
|
||||
*/
|
||||
.factory('Alert', ['$rootScope', '$compile', function ($rootScope, $compile) {
|
||||
.factory('Alert', ['$rootScope', '$compile', '$sce', function ($rootScope, $compile, $sce) {
|
||||
return function (hdr, msg, cls, action, secondAlert, disableButtons) {
|
||||
var scope = $rootScope.$new(), alertClass, e;
|
||||
if (secondAlert) {
|
||||
e = angular.element(document.getElementById('alert-modal2'));
|
||||
$compile(e)(scope);
|
||||
scope.alertHeader2 = hdr;
|
||||
scope.alertBody2 = msg;
|
||||
scope.alertBody2 = $sce.trustAsHtml(msg);
|
||||
alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger
|
||||
$('#alert2-modal-msg').attr({ "class": "alert " + alertClass });
|
||||
$('#alert-modal2').modal({
|
||||
@ -106,7 +106,7 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
||||
e = angular.element(document.getElementById('alert-modal'));
|
||||
$compile(e)(scope);
|
||||
scope.alertHeader = hdr;
|
||||
scope.alertBody = msg;
|
||||
scope.alertBody = $sce.trustAsHtml(msg);
|
||||
alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger
|
||||
$('#alert-modal-msg').attr({ "class": "alert " + alertClass });
|
||||
$('#alert-modal').modal({
|
||||
|
@ -282,7 +282,7 @@ angular.module('ListGenerator', ['GeneratorHelpers'])
|
||||
// table header row
|
||||
html += "<div class=\"list-table-container\">\n";
|
||||
html += "<table id=\"" + list.name + "_table\" ";
|
||||
html += "class=\"table";
|
||||
html += "class=\"table table-condensed";
|
||||
html += (list['class']) ? " " + list['class'] : "";
|
||||
html += (options.mode !== 'summary' && options.mode !== 'edit' && (options.mode === 'lookup' || options.id)) ?
|
||||
' table-hover-inverse' : '';
|
||||
|
@ -17,22 +17,23 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('PromptDialog', ['Utilities'])
|
||||
.factory('Prompt', [
|
||||
function () {
|
||||
.factory('Prompt', ['$sce',
|
||||
function ($sce) {
|
||||
return function (params) {
|
||||
|
||||
var dialog = angular.element(document.getElementById('prompt-modal')),
|
||||
scope = dialog.scope(), cls;
|
||||
|
||||
scope.promptHeader = params.hdr;
|
||||
scope.promptBody = params.body;
|
||||
scope.promptBody = $sce.trustAsHtml(params.body);
|
||||
scope.promptAction = params.action;
|
||||
|
||||
cls = (params['class'] === null || params['class'] === undefined) ? 'btn-danger' : params['class'];
|
||||
|
||||
$('#prompt_action_btn').removeClass(cls).addClass(cls);
|
||||
|
||||
$(dialog).modal({
|
||||
$('#prompt-modal').off('hidden.bs.modal');
|
||||
$('#prompt-modal').modal({
|
||||
backdrop: 'static',
|
||||
keyboard: true,
|
||||
show: true
|
||||
|
Loading…
Reference in New Issue
Block a user