diff --git a/awx/ui/client/features/credentials/add-edit-credentials.controller.js b/awx/ui/client/features/credentials/add-edit-credentials.controller.js index ad8db51751..f82fd6e3df 100644 --- a/awx/ui/client/features/credentials/add-edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/add-edit-credentials.controller.js @@ -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)) { diff --git a/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.jsx b/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.jsx index 3b75634928..868878832a 100644 --- a/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.jsx +++ b/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.jsx @@ -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]) => diff --git a/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.test.jsx b/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.test.jsx index 24c7e9df0a..41d78f6a7d 100644 --- a/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.test.jsx +++ b/awx/ui_next/src/screens/Credential/CredentialAdd/CredentialAdd.test.jsx @@ -127,7 +127,6 @@ describe('', () => { await act(async () => { wrapper.find('CredentialForm').prop('onSubmit')({ user: 1, - organization: null, name: 'foo', description: 'bar', credential_type: '1', @@ -156,7 +155,6 @@ describe('', () => { }); expect(CredentialsAPI.create).toHaveBeenCalledWith({ user: 1, - organization: null, name: 'foo', description: 'bar', credential_type: '1', diff --git a/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.jsx b/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.jsx index 79fe6c5f7c..965746109c 100644 --- a/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.jsx +++ b/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.jsx @@ -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(), ]); diff --git a/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.test.jsx b/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.test.jsx index daa772cd3b..0eab894a85 100644 --- a/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.test.jsx +++ b/awx/ui_next/src/screens/Credential/CredentialEdit/CredentialEdit.test.jsx @@ -277,7 +277,6 @@ describe('', () => { await act(async () => { wrapper.find('CredentialForm').prop('onSubmit')({ user: 1, - organization: null, name: 'foo', description: 'bar', credential_type: '1', @@ -316,7 +315,6 @@ describe('', () => { }); expect(CredentialsAPI.update).toHaveBeenCalledWith(3, { user: 1, - organization: null, name: 'foo', description: 'bar', credential_type: '1',