mirror of
https://github.com/ansible/awx.git
synced 2026-04-11 04:59:22 -02:30
disable input source lookups when they can't be changed
If a user doesn't have permission to change an input field, we disable the input field.
This commit is contained in:
@@ -21,6 +21,7 @@ function AddEditCredentialsController (
|
|||||||
credentialType,
|
credentialType,
|
||||||
organization,
|
organization,
|
||||||
isOrgEditableByUser,
|
isOrgEditableByUser,
|
||||||
|
sourceCredentials,
|
||||||
} = models;
|
} = models;
|
||||||
|
|
||||||
const omit = ['user', 'team', 'inputs'];
|
const omit = ['user', 'team', 'inputs'];
|
||||||
@@ -131,7 +132,11 @@ function AddEditCredentialsController (
|
|||||||
const apiConfig = ConfigService.get();
|
const apiConfig = ConfigService.get();
|
||||||
|
|
||||||
credentialType.mergeInputProperties();
|
credentialType.mergeInputProperties();
|
||||||
const fields = credential.assignInputGroupValues(apiConfig, credentialType);
|
const fields = credential.assignInputGroupValues(
|
||||||
|
apiConfig,
|
||||||
|
credentialType,
|
||||||
|
sourceCredentials
|
||||||
|
);
|
||||||
|
|
||||||
if (credentialType.get('name') === 'Google Compute Engine') {
|
if (credentialType.get('name') === 'Google Compute Engine') {
|
||||||
fields.splice(2, 0, gceFileInputSchema);
|
fields.splice(2, 0, gceFileInputSchema);
|
||||||
@@ -417,6 +422,11 @@ function AddEditCredentialsController (
|
|||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
data.results = data.results.filter(({ id }) => id !== credential.get('id'));
|
data.results = data.results.filter(({ id }) => id !== credential.get('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only show credentials we can use
|
||||||
|
data.results = data.results
|
||||||
|
.filter(({ summary_fields }) => summary_fields.user_capabilities.use);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ function CredentialsResolve (
|
|||||||
CredentialType,
|
CredentialType,
|
||||||
Organization,
|
Organization,
|
||||||
ProcessErrors,
|
ProcessErrors,
|
||||||
strings
|
strings,
|
||||||
|
Rest,
|
||||||
|
GetBasePath,
|
||||||
) {
|
) {
|
||||||
const id = $stateParams.credential_id;
|
const id = $stateParams.credential_id;
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ function CredentialsResolve (
|
|||||||
promises.credential = new Credential('options');
|
promises.credential = new Credential('options');
|
||||||
promises.credentialType = new CredentialType();
|
promises.credentialType = new CredentialType();
|
||||||
promises.organization = new Organization();
|
promises.organization = new Organization();
|
||||||
|
promises.sourceCredentials = $q.resolve({ data: { count: 0, results: [] } });
|
||||||
|
|
||||||
return $q.all(promises);
|
return $q.all(promises);
|
||||||
}
|
}
|
||||||
@@ -39,10 +42,15 @@ function CredentialsResolve (
|
|||||||
const typeId = models.credential.get('credential_type');
|
const typeId = models.credential.get('credential_type');
|
||||||
const orgId = models.credential.get('organization');
|
const orgId = models.credential.get('organization');
|
||||||
|
|
||||||
|
Rest.setUrl(GetBasePath('credentials'));
|
||||||
|
const params = { target_input_sources__target_credential: id };
|
||||||
|
const sourceCredentialsPromise = Rest.get({ params });
|
||||||
|
|
||||||
const dependents = {
|
const dependents = {
|
||||||
credentialType: new CredentialType('get', typeId),
|
credentialType: new CredentialType('get', typeId),
|
||||||
organization: new Organization('get', orgId),
|
organization: new Organization('get', orgId),
|
||||||
credentialInputSources: models.credential.extend('GET', 'input_sources')
|
credentialInputSources: models.credential.extend('GET', 'input_sources'),
|
||||||
|
sourceCredentials: sourceCredentialsPromise
|
||||||
};
|
};
|
||||||
|
|
||||||
dependents.isOrgCredAdmin = dependents.organization.then((org) => org.search({ role_level: 'credential_admin_role' }));
|
dependents.isOrgCredAdmin = dependents.organization.then((org) => org.search({ role_level: 'credential_admin_role' }));
|
||||||
@@ -51,6 +59,7 @@ function CredentialsResolve (
|
|||||||
.then(related => {
|
.then(related => {
|
||||||
models.credentialType = related.credentialType;
|
models.credentialType = related.credentialType;
|
||||||
models.organization = related.organization;
|
models.organization = related.organization;
|
||||||
|
models.sourceCredentials = related.sourceCredentials;
|
||||||
|
|
||||||
const isOrgAdmin = _.some(models.me.get('related.admin_of_organizations.results'), (org) => org.id === models.organization.get('id'));
|
const isOrgAdmin = _.some(models.me.get('related.admin_of_organizations.results'), (org) => org.id === models.organization.get('id'));
|
||||||
const isSuperuser = models.me.get('is_superuser');
|
const isSuperuser = models.me.get('is_superuser');
|
||||||
@@ -79,7 +88,9 @@ CredentialsResolve.$inject = [
|
|||||||
'CredentialTypeModel',
|
'CredentialTypeModel',
|
||||||
'OrganizationModel',
|
'OrganizationModel',
|
||||||
'ProcessErrors',
|
'ProcessErrors',
|
||||||
'CredentialsStrings'
|
'CredentialsStrings',
|
||||||
|
'Rest',
|
||||||
|
'GetBasePath',
|
||||||
];
|
];
|
||||||
|
|
||||||
function CredentialsRun ($stateExtender, legacy, strings) {
|
function CredentialsRun ($stateExtender, legacy, strings) {
|
||||||
|
|||||||
@@ -14,11 +14,16 @@
|
|||||||
<span ng-if="state.tagMode && state.asTag" class="form-control at-Input">
|
<span ng-if="state.tagMode && state.asTag" class="form-control at-Input">
|
||||||
<div class="at-InputTagContainer">
|
<div class="at-InputTagContainer">
|
||||||
<at-tag
|
<at-tag
|
||||||
ng-show="state._tagValue"
|
ng-show="(!state._disabled) && state._tagValue"
|
||||||
icon="external"
|
icon="external"
|
||||||
tag="state._tagValue"
|
tag="state._tagValue"
|
||||||
remove-tag="state._onRemoveTag(state)"
|
remove-tag="state._onRemoveTag(state)"
|
||||||
/>
|
/>
|
||||||
|
<at-tag
|
||||||
|
ng-show="state._disabled && state._tagValue"
|
||||||
|
icon="external"
|
||||||
|
tag="state._tagValue"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<input ng-if="!state.asTag" type="{{ type }}"
|
<input ng-if="!state.asTag" type="{{ type }}"
|
||||||
|
|||||||
@@ -13,11 +13,16 @@
|
|||||||
<span ng-if="state.asTag" class="form-control at-Input">
|
<span ng-if="state.asTag" class="form-control at-Input">
|
||||||
<div class="at-InputTagContainer">
|
<div class="at-InputTagContainer">
|
||||||
<at-tag
|
<at-tag
|
||||||
ng-show="state._tagValue"
|
ng-show="(!state._disabled) && state._tagValue"
|
||||||
icon="external"
|
icon="external"
|
||||||
tag="state._tagValue"
|
tag="state._tagValue"
|
||||||
remove-tag="state._onRemoveTag(state)"
|
remove-tag="state._onRemoveTag(state)"
|
||||||
/>
|
/>
|
||||||
|
<at-tag
|
||||||
|
ng-show="state._disabled && state._tagValue"
|
||||||
|
icon="external"
|
||||||
|
tag="state._tagValue"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<input ng-if="!state.asTag" type="text" class="form-control at-Input"
|
<input ng-if="!state.asTag" type="text" class="form-control at-Input"
|
||||||
|
|||||||
@@ -27,11 +27,17 @@
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<div class="at-InputTagContainer">
|
<div class="at-InputTagContainer">
|
||||||
<at-tag
|
<at-tag
|
||||||
icon="external"
|
ng-show="(!state._disabled) && state._tagValue"
|
||||||
tag="state._tagValue"
|
icon="external"
|
||||||
remove-tag="state._onRemoveTag(state)"
|
tag="state._tagValue"
|
||||||
/>
|
remove-tag="state._onRemoveTag(state)"
|
||||||
|
/>
|
||||||
|
<at-tag
|
||||||
|
ng-show="state._disabled && state._tagValue"
|
||||||
|
icon="external"
|
||||||
|
tag="state._tagValue"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
|
|||||||
@@ -18,6 +18,13 @@
|
|||||||
>
|
>
|
||||||
<div class="at-InputTagContainer">
|
<div class="at-InputTagContainer">
|
||||||
<at-tag
|
<at-tag
|
||||||
|
ng-show="(!state._disabled) && state._tagValue"
|
||||||
|
icon="external"
|
||||||
|
tag="state._tagValue"
|
||||||
|
remove-tag="state._onRemoveTag(state)"
|
||||||
|
/>
|
||||||
|
<at-tag
|
||||||
|
ng-show="state._disabled && state._tagValue"
|
||||||
icon="external"
|
icon="external"
|
||||||
tag="state._tagValue"
|
tag="state._tagValue"
|
||||||
remove-tag="state._onRemoveTag(state)"
|
remove-tag="state._onRemoveTag(state)"
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ function createFormSchema (method, config) {
|
|||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assignInputGroupValues (apiConfig, credentialType) {
|
function assignInputGroupValues (apiConfig, credentialType, sourceCredentials) {
|
||||||
let inputs = credentialType.get('inputs.fields');
|
let inputs = credentialType.get('inputs.fields');
|
||||||
|
|
||||||
if (!inputs) {
|
if (!inputs) {
|
||||||
@@ -79,7 +79,16 @@ function assignInputGroupValues (apiConfig, credentialType) {
|
|||||||
const { summary_fields } = this.get('related.input_sources.results')
|
const { summary_fields } = this.get('related.input_sources.results')
|
||||||
.find(({ input_field_name }) => input_field_name === field.id);
|
.find(({ input_field_name }) => input_field_name === field.id);
|
||||||
field._tagValue = summary_fields.source_credential.name;
|
field._tagValue = summary_fields.source_credential.name;
|
||||||
|
|
||||||
|
const { source_credential: { id } } = summary_fields;
|
||||||
|
const src = sourceCredentials.data.results.find(obj => obj.id === id);
|
||||||
|
const canRemove = _.get(src, ['summary_fields', 'user_capabilities', 'delete'], false);
|
||||||
|
|
||||||
|
if (!canRemove) {
|
||||||
|
field._disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return field;
|
return field;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user