1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Merge pull request #1335 from mabashian/1260-org-credentials

Check for org credentials and present the count to the user before org deletion
This commit is contained in:
Michael Abashian 2018-04-19 09:58:00 -04:00 committed by GitHub
commit 38d83081bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 34 deletions

View File

@ -1,21 +1,36 @@
let Base;
let Credential;
function setDependentResources (id) {
this.dependentResources = [
{
model: new Credential(),
params: {
organization: id
}
}
];
}
function OrganizationModel (method, resource, config) {
Base.call(this, 'organizations');
this.Constructor = OrganizationModel;
this.setDependentResources = setDependentResources.bind(this);
return this.create(method, resource, config);
}
function OrganizationModelLoader (BaseModel) {
function OrganizationModelLoader (BaseModel, CredentialModel) {
Base = BaseModel;
Credential = CredentialModel;
return OrganizationModel;
}
OrganizationModelLoader.$inject = [
'BaseModel'
'BaseModel',
'CredentialModel'
];
export default OrganizationModelLoader;

View File

@ -73,6 +73,7 @@ function BaseStringService (namespace) {
this.deleteResource = {
HEADER: t.s('Delete'),
USED_BY: resourceType => t.s('The {{ resourceType }} is currently being used by other resources.', { resourceType }),
UNAVAILABLE: resourceType => t.s('Deleting this {{ resourceType }} will make the following resources unavailable.', { resourceType }),
CONFIRM: resourceType => t.s('Are you sure you want to delete this {{ resourceType }}?', { resourceType })
};

View File

@ -6,39 +6,40 @@
export default ['$stateParams', '$scope', '$rootScope',
'Rest', 'OrganizationList', 'Prompt',
'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'rbacUiControlService', '$filter', 'Dataset', 'i18n',
'Rest', 'OrganizationList', 'Prompt', 'OrganizationModel',
'ProcessErrors', 'GetBasePath', 'Wait', '$state',
'rbacUiControlService', '$filter', 'Dataset', 'i18n',
'AppStrings',
function($stateParams, $scope, $rootScope,
Rest, OrganizationList, Prompt,
ProcessErrors, GetBasePath, Wait, $state, rbacUiControlService, $filter, Dataset, i18n) {
Rest, OrganizationList, Prompt, Organization,
ProcessErrors, GetBasePath, Wait, $state,
rbacUiControlService, $filter, Dataset, i18n,
AppStrings
) {
var defaultUrl = GetBasePath('organizations'),
list = OrganizationList;
init();
$scope.canAdd = false;
function init() {
$scope.canAdd = false;
rbacUiControlService.canAdd("organizations")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
$scope.orgCount = Dataset.data.count;
rbacUiControlService.canAdd("organizations")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
$scope.orgCount = Dataset.data.count;
// search init
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
// search init
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.orgCards = parseCardData($scope[list.name]);
$rootScope.flashMessage = null;
$scope.orgCards = parseCardData($scope[list.name]);
$rootScope.flashMessage = null;
// grab the pagination elements, move, destroy list generator elements
$('#organization-pagination').appendTo('#OrgCards');
$('#organizations tag-search').appendTo('.OrgCards-search');
$('#organizations-list').remove();
}
// grab the pagination elements, move, destroy list generator elements
$('#organization-pagination').appendTo('#OrgCards');
$('#organizations tag-search').appendTo('.OrgCards-search');
$('#organizations-list').remove();
function parseCardData(cards) {
return cards.map(function(card) {
@ -167,13 +168,34 @@ export default ['$stateParams', '$scope', '$rootScope',
});
};
Prompt({
hdr: i18n._('Delete'),
resourceName: $filter('sanitize')(name),
body: '<div class="Prompt-bodyQuery">' + i18n._('Are you sure you want to delete this organization? This makes everything in this organization unavailable.') + '</div>',
action: action,
actionText: i18n._('DELETE')
});
const organization = new Organization();
organization.getDependentResourceCounts(id)
.then((counts) => {
const invalidateRelatedLines = [];
let deleteModalBody = `<div class="Prompt-bodyQuery">${AppStrings.get('deleteResource.CONFIRM', 'organization')}</div>`;
counts.forEach(countObj => {
if(countObj.count && countObj.count > 0) {
invalidateRelatedLines.push(`<div><span class="Prompt-warningResourceTitle">${countObj.label}</span><span class="badge List-titleBadge">${countObj.count}</span></div>`);
}
});
if (invalidateRelatedLines && invalidateRelatedLines.length > 0) {
deleteModalBody = `<div class="Prompt-bodyQuery">${AppStrings.get('deleteResource.UNAVAILABLE', 'organization')} ${AppStrings.get('deleteResource.CONFIRM', 'organization')}</div>`;
invalidateRelatedLines.forEach(invalidateRelatedLine => {
deleteModalBody += invalidateRelatedLine;
});
}
Prompt({
hdr: i18n._('Delete'),
resourceName: $filter('sanitize')(name),
body: deleteModalBody,
action: action,
actionText: i18n._('DELETE')
});
});
};
}
];

View File

@ -241,7 +241,7 @@ export default ['$scope', '$rootScope', '$log', 'Rest', 'Alert',
resourceName: $filter('sanitize')(name),
body: deleteModalBody,
action: action,
actionText: 'DELETE'
actionText: i18n._('DELETE')
});
});
};