On JT form, Show credential tags from summary_fields if user

doesn't have view permission on the credential
This commit is contained in:
Jared Tabor
2017-08-28 15:46:07 -07:00
parent ddc2af0691
commit a3c8bd6b6f

View File

@@ -177,7 +177,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
}, credTypes, credTypeOptions, credTags; }, credTypes, credTypeOptions, credTags;
let credDefers = []; let credDefers = [];
let job_template_obj = data;
// get machine credential // get machine credential
if (data.related.credential) { if (data.related.credential) {
Rest.setUrl(data.related.credential); Rest.setUrl(data.related.credential);
@@ -186,14 +186,20 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
selectedCredentials.machine = data; selectedCredentials.machine = data;
}) })
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors( if (status === 403) {
null, data, status, null, /* User doesn't have read access to the machine credential, so use summary_fields */
{ selectedCredentials.machine = job_template_obj.summary_fields.credential;
hdr: 'Error!', selectedCredentials.machine.credential_type = job_template_obj.summary_fields.credential.credential_type_id;
msg: 'Failed to get machine credential. ' + } else {
'Get returned status: ' + ProcessErrors(
status null, data, status, null,
{
hdr: 'Error!',
msg: 'Failed to get machine credential. ' +
'Get returned status: ' +
status
}); });
}
})); }));
} }
@@ -204,14 +210,20 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
selectedCredentials.vault = data; selectedCredentials.vault = data;
}) })
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors( if (status === 403) {
null, data, status, null, /* User doesn't have read access to the vault credential, so use summary_fields */
{ selectedCredentials.vault = job_template_obj.summary_fields.vault_credential;
hdr: 'Error!', selectedCredentials.vault.credential_type = job_template_obj.summary_fields.vault_credential.credential_type_id;
msg: 'Failed to get machine credential. ' + } else {
'Get returned status: ' + ProcessErrors(
status null, data, status, null,
{
hdr: 'Error!',
msg: 'Failed to get machine credential. ' +
'Get returned status: ' +
status
}); });
}
})); }));
} }
@@ -223,13 +235,19 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
selectedCredentials.extra = data.results; selectedCredentials.extra = data.results;
}) })
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors(null, data, status, null, if (status === 403) {
{ /* User doesn't have read access to the extra credentials, so use summary_fields */
hdr: 'Error!', selectedCredentials.extra = job_template_obj.summary_fields.extra_credentials;
msg: 'Failed to get extra credentials. ' + _.map(selectedCredentials.extra, (cred) => {cred.credential_type = cred.credential_type_id;});
'Get returned status: ' + } else {
status ProcessErrors(null, data, status, null,
}); {
hdr: 'Error!',
msg: 'Failed to get extra credentials. ' +
'Get returned status: ' +
status
});
}
})); }));
} }