mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -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:
@@ -78,7 +78,7 @@ function MultiCredentialModal(
|
|||||||
|
|
||||||
function multiCredentialModalController(GetBasePath, qs, MultiCredentialService) {
|
function multiCredentialModalController(GetBasePath, qs, MultiCredentialService) {
|
||||||
const vm = this;
|
const vm = this;
|
||||||
const { createTag, isReadOnly } = MultiCredentialService;
|
const { createTag } = MultiCredentialService;
|
||||||
|
|
||||||
const types = {};
|
const types = {};
|
||||||
const unwatch = [];
|
const unwatch = [];
|
||||||
@@ -109,7 +109,6 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
|||||||
});
|
});
|
||||||
scope.$watchCollection('modalSelectedCredentials', updateListView);
|
scope.$watchCollection('modalSelectedCredentials', updateListView);
|
||||||
scope.$watchCollection('modalSelectedCredentials', updateTagView);
|
scope.$watchCollection('modalSelectedCredentials', updateTagView);
|
||||||
scope.$watchCollection('modalSelectedCredentials', updateDisplayedCredentialTypes);
|
|
||||||
scope.$watchCollection('credentials', updateListView);
|
scope.$watchCollection('credentials', updateListView);
|
||||||
|
|
||||||
unwatch.push(watchType);
|
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 () {
|
function getInitialCredentialType () {
|
||||||
const selectedMachineCredential = scope.modalSelectedCredentials
|
const selectedMachineCredential = scope.modalSelectedCredentials
|
||||||
.find(c => c.id === types.Machine);
|
.find(c => c.id === types.Machine);
|
||||||
|
|
||||||
if (selectedMachineCredential && isReadOnly(selectedMachineCredential)) {
|
if (selectedMachineCredential) {
|
||||||
return `${types.Vault}`;
|
return `${types.Vault}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,12 +156,6 @@ function multiCredentialModalController(GetBasePath, qs, MultiCredentialService)
|
|||||||
|
|
||||||
return qs.search(endpoint, scope.credential_default_params)
|
return qs.search(endpoint, scope.credential_default_params)
|
||||||
.then(({ data }) => {
|
.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.credential_dataset = data;
|
||||||
scope.credentials = data.results;
|
scope.credentials = data.results;
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
<div class="MultiCredential-tags">
|
<div class="MultiCredential-tags">
|
||||||
<div class="MultiCredential-tagSection">
|
<div class="MultiCredential-tagSection">
|
||||||
<div class="MultiCredential-flexContainer">
|
<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-tagContainer ng-scope" 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" ng-switch="tag.kind">
|
||||||
<i class="fa fa-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
<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-info MultiCredential-tagIcon" ng-switch-when="insights"></i>
|
||||||
<i class="fa fa-sitemap MultiCredential-tagIcon" ng-switch-when="net"></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-key MultiCredential-tagIcon" ng-switch-when="ssh"></i>
|
||||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="MultiCredential-iconContainer" ng-switch="tag.kind" ng-if="!(fieldIsDisabled || tag.readOnly)">
|
<div class="MultiCredential-tag MultiCredential-tag--deletable">
|
||||||
<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}">
|
|
||||||
<span ng-if="!tag.info" class="MultiCredential-name--label ng-binding">
|
<span ng-if="!tag.info" class="MultiCredential-name--label ng-binding">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
</span>
|
</span>
|
||||||
@@ -48,8 +39,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="MultiCredential-deleteContainer"
|
<div class="MultiCredential-deleteContainer"
|
||||||
ng-click="vm.removeCredential(tag)"
|
ng-click="vm.removeCredential(tag)">
|
||||||
ng-hide="fieldIsDisabled || tag.readOnly">
|
|
||||||
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<div class="MultiCredential-tagContainer ng-scope"
|
<div class="MultiCredential-tagContainer ng-scope"
|
||||||
ng-class="{'MultiCredential-tagContainer--disabled': tag.readOnly}"
|
ng-class="{'MultiCredential-tagContainer--disabled': tag.readOnly}"
|
||||||
ng-repeat="tag in tags track by $index">
|
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-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></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-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-key MultiCredential-tagIcon" ng-switch-when="ssh"></i>
|
||||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||||
</div>
|
</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-cloud MultiCredential-tagIcon" ng-switch-when="cloud"></i>
|
||||||
<i class="fa fa-info MultiCredential-tagIcon" ng-switch-when="insights"></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-sitemap MultiCredential-tagIcon" ng-switch-when="net"></i>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
<i class="fa fa-archive MultiCredential-tagIcon" ng-switch-when="vault"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="MultiCredential-tag"
|
<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">
|
<span ng-if="!tag.info" class="MultiCredential-name--label ng-binding">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
</span>
|
</span>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="MultiCredential-deleteContainer"
|
<div class="MultiCredential-deleteContainer"
|
||||||
ng-click="vm.deselectCredential(tag)"
|
ng-click="vm.deselectCredential(tag)"
|
||||||
ng-hide="fieldIsDisabled || tag.readOnly">
|
ng-hide="fieldIsDisabled">
|
||||||
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
<i class="fa fa-times MultiCredential-tagDelete"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -67,13 +67,6 @@ function MultiCredentialService (Rest, ProcessErrors, $q, GetBasePath) {
|
|||||||
.catch(handleError('GET', 'credential types'));
|
.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) => {
|
this.createTag = (credential, credential_types) => {
|
||||||
const credentialTypeId = credential.credential_type || credential.credential_type_id;
|
const credentialTypeId = credential.credential_type || credential.credential_type_id;
|
||||||
const credentialType = credential_types.find(t => t.id === credentialTypeId);
|
const credentialType = credential_types.find(t => t.id === credentialTypeId);
|
||||||
@@ -83,8 +76,7 @@ function MultiCredentialService (Rest, ProcessErrors, $q, GetBasePath) {
|
|||||||
name: credential.name,
|
name: credential.name,
|
||||||
kind: _.get(credentialType, 'kind'),
|
kind: _.get(credentialType, 'kind'),
|
||||||
typeName: _.get(credentialType, 'name'),
|
typeName: _.get(credentialType, 'name'),
|
||||||
info: _.get(credential, 'inputs.vault_id'),
|
info: _.get(credential, 'inputs.vault_id')
|
||||||
readOnly: this.isReadOnly(credential),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user