mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
Merge pull request #2605 from mabashian/802-jt-creds
Allow users with edit permission on the JT to add/remove credentials
This commit is contained in:
commit
d5edeb6f73
@ -78,7 +78,7 @@ function MultiCredentialModal(
|
||||
|
||||
function multiCredentialModalController(GetBasePath, qs, MultiCredentialService) {
|
||||
const vm = this;
|
||||
const { createTag, isReadOnly } = MultiCredentialService;
|
||||
const { createTag } = MultiCredentialService;
|
||||
|
||||
const types = {};
|
||||
const unwatch = [];
|
||||
@ -109,7 +109,6 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
||||
});
|
||||
scope.$watchCollection('modalSelectedCredentials', updateListView);
|
||||
scope.$watchCollection('modalSelectedCredentials', updateTagView);
|
||||
scope.$watchCollection('modalSelectedCredentials', updateDisplayedCredentialTypes);
|
||||
scope.$watchCollection('credentials', updateListView);
|
||||
|
||||
unwatch.push(watchType);
|
||||
@ -137,30 +136,11 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
||||
});
|
||||
}
|
||||
|
||||
function updateDisplayedCredentialTypes() {
|
||||
const displayedCredentialTypes = _.cloneDeep(scope.credentialTypes);
|
||||
|
||||
scope.modalSelectedCredentials.forEach(credential => {
|
||||
const credentialTypeId = credential.credential_type || credential.credential_type_id;
|
||||
|
||||
if(isReadOnly(credential) && credentialTypeId !== types.Vault) {
|
||||
const index = displayedCredentialTypes
|
||||
.map(t => t.id).indexOf(credentialTypeId);
|
||||
|
||||
if (index > -1) {
|
||||
displayedCredentialTypes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
scope.displayedCredentialTypes = displayedCredentialTypes;
|
||||
}
|
||||
|
||||
function getInitialCredentialType () {
|
||||
const selectedMachineCredential = scope.modalSelectedCredentials
|
||||
.find(c => c.id === types.Machine);
|
||||
|
||||
if (selectedMachineCredential && isReadOnly(selectedMachineCredential)) {
|
||||
if (selectedMachineCredential) {
|
||||
return `${types.Vault}`;
|
||||
}
|
||||
|
||||
@ -176,12 +156,6 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
||||
|
||||
return qs.search(endpoint, scope.credential_default_params)
|
||||
.then(({ data }) => {
|
||||
const results = data.results.filter(c => !isReadOnly(c));
|
||||
const readOnlyCount = data.results.length - results.length;
|
||||
|
||||
data.results = results;
|
||||
data.count = data.count - readOnlyCount;
|
||||
|
||||
scope.credential_dataset = data;
|
||||
scope.credentials = data.results;
|
||||
|
||||
@ -211,7 +185,7 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
||||
|
||||
vm.toggle_credential = credential => {
|
||||
// This is called only when a checkbox input is clicked directly. Clicks anywhere else
|
||||
// on the row or direct radio button clicks invoke the toggle_row handler instead. We
|
||||
// on the row or direct radio button clicks invoke the toggle_row handler instead. We
|
||||
// pass this through to the other function so that the behavior is consistent.
|
||||
vm.toggle_row(credential);
|
||||
};
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
<div class="MultiCredential-tags">
|
||||
<div class="MultiCredential-tagSection">
|
||||
<div class="MultiCredential-flexContainer">
|
||||
<div class="MultiCredential-tagContainer ng-scope" ng-repeat="tag in tags track by $index" ng-class="{'MultiCredential-tagContainer--disabled': tag.readOnly}">
|
||||
<div class="MultiCredential-iconContainer--disabled" ng-switch="tag.kind" ng-if="fieldIsDisabled || tag.readOnly">
|
||||
<div class="MultiCredential-tagContainer ng-scope" ng-repeat="tag in tags track by $index">
|
||||
<div class="MultiCredential-iconContainer" ng-switch="tag.kind">
|
||||
<i class="fa fa-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></i>
|
||||
<i class="fa fa-sitemap MultiCredential-tagIcon" ng-switch-when="net"></i>
|
||||
@ -30,16 +30,7 @@
|
||||
<i class="fa fa-key MultiCredential-tagIcon" ng-switch-when="ssh"></i>
|
||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||
</div>
|
||||
<div class="MultiCredential-iconContainer" ng-switch="tag.kind" ng-if="!(fieldIsDisabled || tag.readOnly)">
|
||||
<i class="fa fa-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></i>
|
||||
<i class="fa fa-sitemap MultiCredential-tagIcon" ng-switch-when="net"></i>
|
||||
<i class="fa fa-code-fork MultiCredential-tagIcon" ng-switch-when="scm"></i>
|
||||
<i class="fa fa-key MultiCredential-tagIcon" ng-switch-when="ssh"></i>
|
||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||
</div>
|
||||
<div class="MultiCredential-tag"
|
||||
ng-class="{'MultiCredential-tag--deletable': !fieldIsDisabled && !tag.readOnly, 'MultiCredential-tag--disabled': tag.readOnly}">
|
||||
<div class="MultiCredential-tag MultiCredential-tag--deletable">
|
||||
<span ng-if="!tag.info" class="MultiCredential-name--label ng-binding">
|
||||
{{ tag.name }}
|
||||
</span>
|
||||
@ -48,8 +39,7 @@
|
||||
</span>
|
||||
</div>
|
||||
<div class="MultiCredential-deleteContainer"
|
||||
ng-click="vm.removeCredential(tag)"
|
||||
ng-hide="fieldIsDisabled || tag.readOnly">
|
||||
ng-click="vm.removeCredential(tag)">
|
||||
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
<div class="MultiCredential-tagContainer ng-scope"
|
||||
ng-class="{'MultiCredential-tagContainer--disabled': tag.readOnly}"
|
||||
ng-repeat="tag in tags track by $index">
|
||||
<div class="MultiCredential-iconContainer--disabled" ng-switch="tag.kind" ng-if="fieldIsDisabled || tag.readOnly">
|
||||
<div class="MultiCredential-iconContainer--disabled" ng-switch="tag.kind" ng-if="fieldIsDisabled">
|
||||
<i class="fa fa-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></i>
|
||||
<i class="fa fa-sitemap MultiCredential-tagIcon" ng-switch-when="net"></i>
|
||||
@ -26,7 +26,7 @@
|
||||
<i class="fa fa-key MultiCredential-tagIcon" ng-switch-when="ssh"></i>
|
||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||
</div>
|
||||
<div class="MultiCredential-iconContainer" ng-switch="tag.kind" ng-if="!(fieldIsDisabled || tag.readOnly)">
|
||||
<div class="MultiCredential-iconContainer" ng-switch="tag.kind" ng-if="!fieldIsDisabled">
|
||||
<i class="fa fa-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></i>
|
||||
<i class="fa fa-sitemap MultiCredential-tagIcon" ng-switch-when="net"></i>
|
||||
@ -35,7 +35,7 @@
|
||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||
</div>
|
||||
<div class="MultiCredential-tag"
|
||||
ng-class="{'MultiCredential-tag--deletable': !fieldIsDisabled && !tag.readOnly, 'MultiCredential-tag--disabled': tag.readOnly}">
|
||||
ng-class="{'MultiCredential-tag--deletable': !fieldIsDisabled, 'MultiCredential-tag--disabled': fieldIsDisabled}">
|
||||
<span ng-if="!tag.info" class="MultiCredential-name--label ng-binding">
|
||||
{{ tag.name }}
|
||||
</span>
|
||||
@ -45,7 +45,7 @@
|
||||
</div>
|
||||
<div class="MultiCredential-deleteContainer"
|
||||
ng-click="vm.deselectCredential(tag)"
|
||||
ng-hide="fieldIsDisabled || tag.readOnly">
|
||||
ng-hide="fieldIsDisabled">
|
||||
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -67,13 +67,6 @@ function MultiCredentialService (Rest, ProcessErrors, $q, GetBasePath) {
|
||||
.catch(handleError('GET', 'credential types'));
|
||||
};
|
||||
|
||||
this.isReadOnly = credential => {
|
||||
const canEdit = _.get(credential, 'summary_fields.user_capabilities.edit');
|
||||
const canDelete = _.get(credential, 'summary_fields.user_capabilities.delete');
|
||||
|
||||
return !(canEdit || canDelete);
|
||||
};
|
||||
|
||||
this.createTag = (credential, credential_types) => {
|
||||
const credentialTypeId = credential.credential_type || credential.credential_type_id;
|
||||
const credentialType = credential_types.find(t => t.id === credentialTypeId);
|
||||
@ -83,8 +76,7 @@ function MultiCredentialService (Rest, ProcessErrors, $q, GetBasePath) {
|
||||
name: credential.name,
|
||||
kind: _.get(credentialType, 'kind'),
|
||||
typeName: _.get(credentialType, 'name'),
|
||||
info: _.get(credential, 'inputs.vault_id'),
|
||||
readOnly: this.isReadOnly(credential),
|
||||
info: _.get(credential, 'inputs.vault_id')
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user