mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
[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 <rick@elrod.me>
This commit is contained in:
@@ -22,15 +22,11 @@ function ProjectAdd() {
|
|||||||
} else if (typeof values.credential.id === 'number') {
|
} else if (typeof values.credential.id === 'number') {
|
||||||
values.credential = values.credential.id;
|
values.credential = values.credential.id;
|
||||||
}
|
}
|
||||||
if (values.scm_type === 'git') {
|
if (!values.signature_validation_credential) {
|
||||||
if (!values.signature_validation_credential) {
|
values.signature_validation_credential = null;
|
||||||
values.signature_validation_credential = null;
|
} else if (typeof values.signature_validation_credential.id === 'number') {
|
||||||
} else if (
|
values.signature_validation_credential =
|
||||||
typeof values.signature_validation_credential.id === 'number'
|
values.signature_validation_credential.id;
|
||||||
) {
|
|
||||||
values.signature_validation_credential =
|
|
||||||
values.signature_validation_credential.id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setFormSubmitError(null);
|
setFormSubmitError(null);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -22,15 +22,11 @@ function ProjectEdit({ project }) {
|
|||||||
} else if (typeof values.credential.id === 'number') {
|
} else if (typeof values.credential.id === 'number') {
|
||||||
values.credential = values.credential.id;
|
values.credential = values.credential.id;
|
||||||
}
|
}
|
||||||
if (values.scm_type === 'git') {
|
if (!values.signature_validation_credential) {
|
||||||
if (!values.signature_validation_credential) {
|
values.signature_validation_credential = null;
|
||||||
values.signature_validation_credential = null;
|
} else if (typeof values.signature_validation_credential.id === 'number') {
|
||||||
} else if (
|
values.signature_validation_credential =
|
||||||
typeof values.signature_validation_credential.id === 'number'
|
values.signature_validation_credential.id;
|
||||||
) {
|
|
||||||
values.signature_validation_credential =
|
|
||||||
values.signature_validation_credential.id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { useConfig } from 'contexts/Config';
|
|||||||
import AnsibleSelect from 'components/AnsibleSelect';
|
import AnsibleSelect from 'components/AnsibleSelect';
|
||||||
import ContentError from 'components/ContentError';
|
import ContentError from 'components/ContentError';
|
||||||
import ContentLoading from 'components/ContentLoading';
|
import ContentLoading from 'components/ContentLoading';
|
||||||
|
import CredentialLookup from 'components/Lookup/CredentialLookup';
|
||||||
import FormActionGroup from 'components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from 'components/FormActionGroup/FormActionGroup';
|
||||||
import FormField, { FormSubmitError } from 'components/FormField';
|
import FormField, { FormSubmitError } from 'components/FormField';
|
||||||
import OrganizationLookup from 'components/Lookup/OrganizationLookup';
|
import OrganizationLookup from 'components/Lookup/OrganizationLookup';
|
||||||
@@ -176,6 +177,19 @@ function ProjectFormFields({
|
|||||||
[signatureValidationCredentials, setSignatureValidationCredentials]
|
[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(
|
const handleOrganizationUpdate = useCallback(
|
||||||
(value) => {
|
(value) => {
|
||||||
setFieldValue('organization', value);
|
setFieldValue('organization', value);
|
||||||
@@ -270,6 +284,13 @@ function ProjectFormFields({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
<CredentialLookup
|
||||||
|
credentialTypeId={signatureValidationCredentials.cryptography.typeId}
|
||||||
|
label={t`Content Signature Validation Credential`}
|
||||||
|
onChange={handleSignatureValidationCredentialChange}
|
||||||
|
value={signatureValidationCredentials.cryptography.value}
|
||||||
|
tooltip={projectHelpText.signatureValidation}
|
||||||
|
/>
|
||||||
{formik.values.scm_type !== '' && (
|
{formik.values.scm_type !== '' && (
|
||||||
<SubFormLayout>
|
<SubFormLayout>
|
||||||
<Title size="md" headingLevel="h4">
|
<Title size="md" headingLevel="h4">
|
||||||
@@ -288,13 +309,7 @@ function ProjectFormFields({
|
|||||||
git: (
|
git: (
|
||||||
<GitSubForm
|
<GitSubForm
|
||||||
credential={credentials.scm}
|
credential={credentials.scm}
|
||||||
signature_validation_credential={
|
|
||||||
signatureValidationCredentials.cryptography
|
|
||||||
}
|
|
||||||
onCredentialSelection={handleCredentialSelection}
|
onCredentialSelection={handleCredentialSelection}
|
||||||
onSignatureValidationCredentialSelection={
|
|
||||||
handleSignatureValidationCredentialSelection
|
|
||||||
}
|
|
||||||
scmUpdateOnLaunch={formik.values.scm_update_on_launch}
|
scmUpdateOnLaunch={formik.values.scm_update_on_launch}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -276,14 +276,22 @@ describe('<ProjectForm />', () => {
|
|||||||
1
|
1
|
||||||
);
|
);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper.find('CredentialLookup').invoke('onBlur')();
|
wrapper
|
||||||
wrapper.find('CredentialLookup').invoke('onChange')({
|
.find('CredentialLookup[label="Insights Credential"]')
|
||||||
|
.invoke('onBlur')();
|
||||||
|
wrapper
|
||||||
|
.find('CredentialLookup[label="Insights Credential"]')
|
||||||
|
.invoke('onChange')({
|
||||||
id: 123,
|
id: 123,
|
||||||
name: 'credential',
|
name: 'credential',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('CredentialLookup').prop('value')).toEqual({
|
expect(
|
||||||
|
wrapper
|
||||||
|
.find('CredentialLookup[label="Insights Credential"]')
|
||||||
|
.prop('value')
|
||||||
|
).toEqual({
|
||||||
id: 123,
|
id: 123,
|
||||||
name: 'credential',
|
name: 'credential',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import 'styled-components/macro';
|
import 'styled-components/macro';
|
||||||
import React, { useCallback } from 'react';
|
import React from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { useFormikContext } from 'formik';
|
|
||||||
import CredentialLookup from 'components/Lookup/CredentialLookup';
|
|
||||||
import FormField from 'components/FormField';
|
import FormField from 'components/FormField';
|
||||||
import getDocsBaseUrl from 'util/getDocsBaseUrl';
|
import getDocsBaseUrl from 'util/getDocsBaseUrl';
|
||||||
import { useConfig } from 'contexts/Config';
|
import { useConfig } from 'contexts/Config';
|
||||||
@@ -18,22 +16,9 @@ import projectHelpStrings from '../Project.helptext';
|
|||||||
|
|
||||||
const GitSubForm = ({
|
const GitSubForm = ({
|
||||||
credential,
|
credential,
|
||||||
signature_validation_credential,
|
|
||||||
onCredentialSelection,
|
onCredentialSelection,
|
||||||
onSignatureValidationCredentialSelection,
|
|
||||||
scmUpdateOnLaunch,
|
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(
|
const docsURL = `${getDocsBaseUrl(
|
||||||
useConfig()
|
useConfig()
|
||||||
)}/html/userguide/projects.html#manage-playbooks-using-source-control`;
|
)}/html/userguide/projects.html#manage-playbooks-using-source-control`;
|
||||||
@@ -50,13 +35,6 @@ const GitSubForm = ({
|
|||||||
tooltipMaxWidth="400px"
|
tooltipMaxWidth="400px"
|
||||||
tooltip={projectHelpStrings.sourceControlRefspec(docsURL)}
|
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
|
<ScmCredentialFormField
|
||||||
credential={credential}
|
credential={credential}
|
||||||
onCredentialSelection={onCredentialSelection}
|
onCredentialSelection={onCredentialSelection}
|
||||||
|
|||||||
Reference in New Issue
Block a user