mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 10:27:34 -02:30
Check for org credentials and present the count to the user before org deletion
This commit is contained in:
@@ -1,21 +1,36 @@
|
|||||||
let Base;
|
let Base;
|
||||||
|
let Credential;
|
||||||
|
|
||||||
|
function setDependentResources (id) {
|
||||||
|
this.dependentResources = [
|
||||||
|
{
|
||||||
|
model: new Credential(),
|
||||||
|
params: {
|
||||||
|
organization: id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
function OrganizationModel (method, resource, config) {
|
function OrganizationModel (method, resource, config) {
|
||||||
Base.call(this, 'organizations');
|
Base.call(this, 'organizations');
|
||||||
|
|
||||||
this.Constructor = OrganizationModel;
|
this.Constructor = OrganizationModel;
|
||||||
|
this.setDependentResources = setDependentResources.bind(this);
|
||||||
|
|
||||||
return this.create(method, resource, config);
|
return this.create(method, resource, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function OrganizationModelLoader (BaseModel) {
|
function OrganizationModelLoader (BaseModel, CredentialModel) {
|
||||||
Base = BaseModel;
|
Base = BaseModel;
|
||||||
|
Credential = CredentialModel;
|
||||||
|
|
||||||
return OrganizationModel;
|
return OrganizationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
OrganizationModelLoader.$inject = [
|
OrganizationModelLoader.$inject = [
|
||||||
'BaseModel'
|
'BaseModel',
|
||||||
|
'CredentialModel'
|
||||||
];
|
];
|
||||||
|
|
||||||
export default OrganizationModelLoader;
|
export default OrganizationModelLoader;
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ function BaseStringService (namespace) {
|
|||||||
this.deleteResource = {
|
this.deleteResource = {
|
||||||
HEADER: t.s('Delete'),
|
HEADER: t.s('Delete'),
|
||||||
USED_BY: resourceType => t.s('The {{ resourceType }} is currently being used by other resources.', { resourceType }),
|
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 })
|
CONFIRM: resourceType => t.s('Are you sure you want to delete this {{ resourceType }}?', { resourceType })
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,39 +6,40 @@
|
|||||||
|
|
||||||
|
|
||||||
export default ['$stateParams', '$scope', '$rootScope',
|
export default ['$stateParams', '$scope', '$rootScope',
|
||||||
'Rest', 'OrganizationList', 'Prompt',
|
'Rest', 'OrganizationList', 'Prompt', 'OrganizationModel',
|
||||||
'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'rbacUiControlService', '$filter', 'Dataset', 'i18n',
|
'ProcessErrors', 'GetBasePath', 'Wait', '$state',
|
||||||
|
'rbacUiControlService', '$filter', 'Dataset', 'i18n',
|
||||||
|
'AppStrings',
|
||||||
function($stateParams, $scope, $rootScope,
|
function($stateParams, $scope, $rootScope,
|
||||||
Rest, OrganizationList, Prompt,
|
Rest, OrganizationList, Prompt, Organization,
|
||||||
ProcessErrors, GetBasePath, Wait, $state, rbacUiControlService, $filter, Dataset, i18n) {
|
ProcessErrors, GetBasePath, Wait, $state,
|
||||||
|
rbacUiControlService, $filter, Dataset, i18n,
|
||||||
|
AppStrings
|
||||||
|
) {
|
||||||
|
|
||||||
var defaultUrl = GetBasePath('organizations'),
|
var defaultUrl = GetBasePath('organizations'),
|
||||||
list = OrganizationList;
|
list = OrganizationList;
|
||||||
|
|
||||||
init();
|
$scope.canAdd = false;
|
||||||
|
|
||||||
function init() {
|
rbacUiControlService.canAdd("organizations")
|
||||||
$scope.canAdd = false;
|
.then(function(params) {
|
||||||
|
$scope.canAdd = params.canAdd;
|
||||||
|
});
|
||||||
|
$scope.orgCount = Dataset.data.count;
|
||||||
|
|
||||||
rbacUiControlService.canAdd("organizations")
|
// search init
|
||||||
.then(function(params) {
|
$scope.list = list;
|
||||||
$scope.canAdd = params.canAdd;
|
$scope[`${list.iterator}_dataset`] = Dataset.data;
|
||||||
});
|
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
|
||||||
$scope.orgCount = Dataset.data.count;
|
|
||||||
|
|
||||||
// search init
|
$scope.orgCards = parseCardData($scope[list.name]);
|
||||||
$scope.list = list;
|
$rootScope.flashMessage = null;
|
||||||
$scope[`${list.iterator}_dataset`] = Dataset.data;
|
|
||||||
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
|
|
||||||
|
|
||||||
$scope.orgCards = parseCardData($scope[list.name]);
|
// grab the pagination elements, move, destroy list generator elements
|
||||||
$rootScope.flashMessage = null;
|
$('#organization-pagination').appendTo('#OrgCards');
|
||||||
|
$('#organizations tag-search').appendTo('.OrgCards-search');
|
||||||
// grab the pagination elements, move, destroy list generator elements
|
$('#organizations-list').remove();
|
||||||
$('#organization-pagination').appendTo('#OrgCards');
|
|
||||||
$('#organizations tag-search').appendTo('.OrgCards-search');
|
|
||||||
$('#organizations-list').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCardData(cards) {
|
function parseCardData(cards) {
|
||||||
return cards.map(function(card) {
|
return cards.map(function(card) {
|
||||||
@@ -167,13 +168,34 @@ export default ['$stateParams', '$scope', '$rootScope',
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Prompt({
|
const organization = new Organization();
|
||||||
hdr: i18n._('Delete'),
|
|
||||||
resourceName: $filter('sanitize')(name),
|
organization.getDependentResourceCounts(id)
|
||||||
body: '<div class="Prompt-bodyQuery">' + i18n._('Are you sure you want to delete this organization? This makes everything in this organization unavailable.') + '</div>',
|
.then((counts) => {
|
||||||
action: action,
|
const invalidateRelatedLines = [];
|
||||||
actionText: i18n._('DELETE')
|
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')
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ export default ['$scope', '$rootScope', '$log', 'Rest', 'Alert',
|
|||||||
resourceName: $filter('sanitize')(name),
|
resourceName: $filter('sanitize')(name),
|
||||||
body: deleteModalBody,
|
body: deleteModalBody,
|
||||||
action: action,
|
action: action,
|
||||||
actionText: 'DELETE'
|
actionText: i18n._('DELETE')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user