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:
Jake McDermott 2019-03-25 15:58:57 -04:00
parent c4a79a778f
commit f0f4f487fb
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7
7 changed files with 65 additions and 12 deletions

View File

@ -21,6 +21,7 @@ function AddEditCredentialsController (
credentialType,
organization,
isOrgEditableByUser,
sourceCredentials,
} = models;
const omit = ['user', 'team', 'inputs'];
@ -131,7 +132,11 @@ function AddEditCredentialsController (
const apiConfig = ConfigService.get();
credentialType.mergeInputProperties();
const fields = credential.assignInputGroupValues(apiConfig, credentialType);
const fields = credential.assignInputGroupValues(
apiConfig,
credentialType,
sourceCredentials
);
if (credentialType.get('name') === 'Google Compute Engine') {
fields.splice(2, 0, gceFileInputSchema);
@ -417,6 +422,11 @@ function AddEditCredentialsController (
if (isExternal) {
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;
};

View File

@ -16,7 +16,9 @@ function CredentialsResolve (
CredentialType,
Organization,
ProcessErrors,
strings
strings,
Rest,
GetBasePath,
) {
const id = $stateParams.credential_id;
@ -28,6 +30,7 @@ function CredentialsResolve (
promises.credential = new Credential('options');
promises.credentialType = new CredentialType();
promises.organization = new Organization();
promises.sourceCredentials = $q.resolve({ data: { count: 0, results: [] } });
return $q.all(promises);
}
@ -39,10 +42,15 @@ function CredentialsResolve (
const typeId = models.credential.get('credential_type');
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 = {
credentialType: new CredentialType('get', typeId),
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' }));
@ -51,6 +59,7 @@ function CredentialsResolve (
.then(related => {
models.credentialType = related.credentialType;
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 isSuperuser = models.me.get('is_superuser');
@ -79,7 +88,9 @@ CredentialsResolve.$inject = [
'CredentialTypeModel',
'OrganizationModel',
'ProcessErrors',
'CredentialsStrings'
'CredentialsStrings',
'Rest',
'GetBasePath',
];
function CredentialsRun ($stateExtender, legacy, strings) {

View File

@ -14,11 +14,16 @@
<span ng-if="state.tagMode && state.asTag" class="form-control at-Input">
<div class="at-InputTagContainer">
<at-tag
ng-show="state._tagValue"
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"
tag="state._tagValue"
/>
</div>
</span>
<input ng-if="!state.asTag" type="{{ type }}"

View File

@ -13,11 +13,16 @@
<span ng-if="state.asTag" class="form-control at-Input">
<div class="at-InputTagContainer">
<at-tag
ng-show="state._tagValue"
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"
tag="state._tagValue"
/>
</div>
</span>
<input ng-if="!state.asTag" type="text" class="form-control at-Input"

View File

@ -27,11 +27,17 @@
}"
>
<div class="at-InputTagContainer">
<at-tag
icon="external"
tag="state._tagValue"
remove-tag="state._onRemoveTag(state)"
/>
<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"
tag="state._tagValue"
/>
</div>
</div>
<textarea

View File

@ -18,6 +18,13 @@
>
<div class="at-InputTagContainer">
<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"
tag="state._tagValue"
remove-tag="state._onRemoveTag(state)"

View File

@ -30,7 +30,7 @@ function createFormSchema (method, config) {
return schema;
}
function assignInputGroupValues (apiConfig, credentialType) {
function assignInputGroupValues (apiConfig, credentialType, sourceCredentials) {
let inputs = credentialType.get('inputs.fields');
if (!inputs) {
@ -79,7 +79,16 @@ function assignInputGroupValues (apiConfig, credentialType) {
const { summary_fields } = this.get('related.input_sources.results')
.find(({ input_field_name }) => input_field_name === field.id);
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;
});