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
5 changed files with 25 additions and 18 deletions

View File

@@ -495,7 +495,10 @@ function AddEditCredentialsController (
} }
function create (data) { 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)) { if (_.get(data.inputs, gceFileInputSchema.id)) {
delete data.inputs[gceFileInputSchema.id]; delete data.inputs[gceFileInputSchema.id];
@@ -524,7 +527,11 @@ function AddEditCredentialsController (
* Otherwise inputs are merged together making the request invalid. * Otherwise inputs are merged together making the request invalid.
*/ */
function update (data) { 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'); credential.unset('inputs');
if (_.get(data.inputs, gceFileInputSchema.id)) { 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 { const {
data: { id: newCredentialId }, data: { id: newCredentialId },
} = await CredentialsAPI.create({ } = await CredentialsAPI.create(modifiedData);
user: (me && me.id) || null,
organization: (organization && organization.id) || null,
inputs: nonPluginInputs,
...remainingValues,
});
await Promise.all( await Promise.all(
Object.entries(pluginInputs).map(([key, value]) => Object.entries(pluginInputs).map(([key, value]) =>

View File

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

View File

@@ -80,13 +80,15 @@ function CredentialEdit({ credential, me }) {
return null; 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([ const [{ data }] = await Promise.all([
CredentialsAPI.update(credential.id, { CredentialsAPI.update(credential.id, modifiedData),
user: (me && me.id) || null,
organization: (organization && organization.id) || null,
inputs: nonPluginInputs,
...remainingValues,
}),
...destroyInputSources(), ...destroyInputSources(),
]); ]);

View File

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