From c475a7b6c073a0cab214d1b8a772474267e633a0 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Wed, 24 Aug 2022 11:30:54 -0500 Subject: [PATCH] [ui] make signature cred. field be project-global (#12695) Rather than only allowing the signature credential to be specified on project using git, allow it to be specified on any project at all. This moves the field to always show, and moves it out of the git subform. Signed-off-by: Rick Elrod --- .../screens/Project/ProjectAdd/ProjectAdd.js | 14 ++++------ .../Project/ProjectEdit/ProjectEdit.js | 14 ++++------ .../src/screens/Project/shared/ProjectForm.js | 27 ++++++++++++++----- .../Project/shared/ProjectForm.test.js | 14 +++++++--- .../shared/ProjectSubForms/GitSubForm.js | 24 +---------------- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/awx/ui/src/screens/Project/ProjectAdd/ProjectAdd.js b/awx/ui/src/screens/Project/ProjectAdd/ProjectAdd.js index 9c95052e24..baf052ef09 100644 --- a/awx/ui/src/screens/Project/ProjectAdd/ProjectAdd.js +++ b/awx/ui/src/screens/Project/ProjectAdd/ProjectAdd.js @@ -22,15 +22,11 @@ function ProjectAdd() { } else if (typeof values.credential.id === 'number') { values.credential = values.credential.id; } - if (values.scm_type === 'git') { - if (!values.signature_validation_credential) { - values.signature_validation_credential = null; - } else if ( - typeof values.signature_validation_credential.id === 'number' - ) { - values.signature_validation_credential = - values.signature_validation_credential.id; - } + if (!values.signature_validation_credential) { + values.signature_validation_credential = null; + } else if (typeof values.signature_validation_credential.id === 'number') { + values.signature_validation_credential = + values.signature_validation_credential.id; } setFormSubmitError(null); try { diff --git a/awx/ui/src/screens/Project/ProjectEdit/ProjectEdit.js b/awx/ui/src/screens/Project/ProjectEdit/ProjectEdit.js index dd3c6b85e0..f2ed08cbe8 100644 --- a/awx/ui/src/screens/Project/ProjectEdit/ProjectEdit.js +++ b/awx/ui/src/screens/Project/ProjectEdit/ProjectEdit.js @@ -22,15 +22,11 @@ function ProjectEdit({ project }) { } else if (typeof values.credential.id === 'number') { values.credential = values.credential.id; } - if (values.scm_type === 'git') { - if (!values.signature_validation_credential) { - values.signature_validation_credential = null; - } else if ( - typeof values.signature_validation_credential.id === 'number' - ) { - values.signature_validation_credential = - values.signature_validation_credential.id; - } + if (!values.signature_validation_credential) { + values.signature_validation_credential = null; + } else if (typeof values.signature_validation_credential.id === 'number') { + values.signature_validation_credential = + values.signature_validation_credential.id; } try { diff --git a/awx/ui/src/screens/Project/shared/ProjectForm.js b/awx/ui/src/screens/Project/shared/ProjectForm.js index c968a7ac5a..66a0aa8cd5 100644 --- a/awx/ui/src/screens/Project/shared/ProjectForm.js +++ b/awx/ui/src/screens/Project/shared/ProjectForm.js @@ -9,6 +9,7 @@ import { useConfig } from 'contexts/Config'; import AnsibleSelect from 'components/AnsibleSelect'; import ContentError from 'components/ContentError'; import ContentLoading from 'components/ContentLoading'; +import CredentialLookup from 'components/Lookup/CredentialLookup'; import FormActionGroup from 'components/FormActionGroup/FormActionGroup'; import FormField, { FormSubmitError } from 'components/FormField'; import OrganizationLookup from 'components/Lookup/OrganizationLookup'; @@ -176,6 +177,19 @@ function ProjectFormFields({ [signatureValidationCredentials, setSignatureValidationCredentials] ); + const handleSignatureValidationCredentialChange = useCallback( + (value) => { + handleSignatureValidationCredentialSelection('cryptography', value); + setFieldValue('signature_validation_credential', value); + setFieldTouched('signature_validation_credential', true, false); + }, + [ + handleSignatureValidationCredentialSelection, + setFieldValue, + setFieldTouched, + ] + ); + const handleOrganizationUpdate = useCallback( (value) => { setFieldValue('organization', value); @@ -270,6 +284,13 @@ function ProjectFormFields({ }} /> + {formik.values.scm_type !== '' && ( @@ -288,13 +309,7 @@ function ProjectFormFields({ git: ( <GitSubForm credential={credentials.scm} - signature_validation_credential={ - signatureValidationCredentials.cryptography - } onCredentialSelection={handleCredentialSelection} - onSignatureValidationCredentialSelection={ - handleSignatureValidationCredentialSelection - } scmUpdateOnLaunch={formik.values.scm_update_on_launch} /> ), diff --git a/awx/ui/src/screens/Project/shared/ProjectForm.test.js b/awx/ui/src/screens/Project/shared/ProjectForm.test.js index 342634cf5f..d75047be4f 100644 --- a/awx/ui/src/screens/Project/shared/ProjectForm.test.js +++ b/awx/ui/src/screens/Project/shared/ProjectForm.test.js @@ -276,14 +276,22 @@ describe('<ProjectForm />', () => { 1 ); await act(async () => { - wrapper.find('CredentialLookup').invoke('onBlur')(); - wrapper.find('CredentialLookup').invoke('onChange')({ + wrapper + .find('CredentialLookup[label="Insights Credential"]') + .invoke('onBlur')(); + wrapper + .find('CredentialLookup[label="Insights Credential"]') + .invoke('onChange')({ id: 123, name: 'credential', }); }); wrapper.update(); - expect(wrapper.find('CredentialLookup').prop('value')).toEqual({ + expect( + wrapper + .find('CredentialLookup[label="Insights Credential"]') + .prop('value') + ).toEqual({ id: 123, name: 'credential', }); diff --git a/awx/ui/src/screens/Project/shared/ProjectSubForms/GitSubForm.js b/awx/ui/src/screens/Project/shared/ProjectSubForms/GitSubForm.js index b1b4f956b6..533aa05aef 100644 --- a/awx/ui/src/screens/Project/shared/ProjectSubForms/GitSubForm.js +++ b/awx/ui/src/screens/Project/shared/ProjectSubForms/GitSubForm.js @@ -1,8 +1,6 @@ import 'styled-components/macro'; -import React, { useCallback } from 'react'; +import React from 'react'; import { t } from '@lingui/macro'; -import { useFormikContext } from 'formik'; -import CredentialLookup from 'components/Lookup/CredentialLookup'; import FormField from 'components/FormField'; import getDocsBaseUrl from 'util/getDocsBaseUrl'; import { useConfig } from 'contexts/Config'; @@ -18,22 +16,9 @@ import projectHelpStrings from '../Project.helptext'; const GitSubForm = ({ credential, - signature_validation_credential, onCredentialSelection, - onSignatureValidationCredentialSelection, scmUpdateOnLaunch, }) => { - const { setFieldValue, setFieldTouched } = useFormikContext(); - - const onCredentialChange = useCallback( - (value) => { - onSignatureValidationCredentialSelection('cryptography', value); - setFieldValue('signature_validation_credential', value); - setFieldTouched('signature_validation_credential', true, false); - }, - [onSignatureValidationCredentialSelection, setFieldValue, setFieldTouched] - ); - const docsURL = `${getDocsBaseUrl( useConfig() )}/html/userguide/projects.html#manage-playbooks-using-source-control`; @@ -50,13 +35,6 @@ const GitSubForm = ({ tooltipMaxWidth="400px" tooltip={projectHelpStrings.sourceControlRefspec(docsURL)} /> - <CredentialLookup - credentialTypeId={signature_validation_credential.typeId} - label={t`Content Signature Validation Credential`} - onChange={onCredentialChange} - value={signature_validation_credential.value} - tooltip={projectHelpStrings.signatureValidation} - /> <ScmCredentialFormField credential={credential} onCredentialSelection={onCredentialSelection}