Don't send cred user with org

This commit is contained in:
Jake McDermott 2020-06-23 11:04:35 -04:00
parent a669db989c
commit 35e5c7f309
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F
5 changed files with 25 additions and 18 deletions

View File

@ -495,7 +495,10 @@ function AddEditCredentialsController (
}
function create (data) {
data.user = me.get('id');
// can send only one of org, user, team
if (!data.organization && !data.team) {
data.user = me.get('id');
}
if (_.get(data.inputs, gceFileInputSchema.id)) {
delete data.inputs[gceFileInputSchema.id];
@ -524,7 +527,11 @@ function AddEditCredentialsController (
* Otherwise inputs are merged together making the request invalid.
*/
function update (data) {
data.user = me.get('id');
// can send only one of org, user, team
if (!data.organization && !data.team) {
data.user = me.get('id');
}
credential.unset('inputs');
if (_.get(data.inputs, gceFileInputSchema.id)) {

View File

@ -52,14 +52,16 @@ function CredentialAdd({ me }) {
}
});
const modifiedData = { inputs: nonPluginInputs, ...remainingValues };
// can send only one of org, user, team
if (organization?.id) {
modifiedData.organization = organization.id;
} else if (me?.id) {
modifiedData.user = me.id;
}
const {
data: { id: newCredentialId },
} = await CredentialsAPI.create({
user: (me && me.id) || null,
organization: (organization && organization.id) || null,
inputs: nonPluginInputs,
...remainingValues,
});
} = await CredentialsAPI.create(modifiedData);
await Promise.all(
Object.entries(pluginInputs).map(([key, value]) =>

View File

@ -127,7 +127,6 @@ describe('<CredentialAdd />', () => {
await act(async () => {
wrapper.find('CredentialForm').prop('onSubmit')({
user: 1,
organization: null,
name: 'foo',
description: 'bar',
credential_type: '1',
@ -156,7 +155,6 @@ describe('<CredentialAdd />', () => {
});
expect(CredentialsAPI.create).toHaveBeenCalledWith({
user: 1,
organization: null,
name: 'foo',
description: 'bar',
credential_type: '1',

View File

@ -80,13 +80,15 @@ function CredentialEdit({ credential, me }) {
return null;
});
const modifiedData = { inputs: nonPluginInputs, ...remainingValues };
// can send only one of org, user, team
if (organization?.id) {
modifiedData.organization = organization.id;
} else if (me?.id) {
modifiedData.user = me.id;
}
const [{ data }] = await Promise.all([
CredentialsAPI.update(credential.id, {
user: (me && me.id) || null,
organization: (organization && organization.id) || null,
inputs: nonPluginInputs,
...remainingValues,
}),
CredentialsAPI.update(credential.id, modifiedData),
...destroyInputSources(),
]);

View File

@ -277,7 +277,6 @@ describe('<CredentialEdit />', () => {
await act(async () => {
wrapper.find('CredentialForm').prop('onSubmit')({
user: 1,
organization: null,
name: 'foo',
description: 'bar',
credential_type: '1',
@ -316,7 +315,6 @@ describe('<CredentialEdit />', () => {
});
expect(CredentialsAPI.update).toHaveBeenCalledWith(3, {
user: 1,
organization: null,
name: 'foo',
description: 'bar',
credential_type: '1',