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
7 changed files with 65 additions and 12 deletions

View File

@@ -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;
}; };

View File

@@ -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) {

View File

@@ -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 }}"

View File

@@ -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"

View File

@@ -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

View File

@@ -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)"

View File

@@ -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;
}); });