mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
properly validates credential password fields
This commit is contained in:
committed by
Shane McDonald
parent
d3c5397721
commit
28a62ea774
@@ -12,7 +12,15 @@ import {
|
|||||||
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';
|
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';
|
||||||
|
|
||||||
function PasswordInput(props) {
|
function PasswordInput(props) {
|
||||||
const { autocomplete, id, name, validate, isRequired, isDisabled } = props;
|
const {
|
||||||
|
autocomplete,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
validate,
|
||||||
|
isFieldGroupValid,
|
||||||
|
isRequired,
|
||||||
|
isDisabled,
|
||||||
|
} = props;
|
||||||
const [inputType, setInputType] = useState('password');
|
const [inputType, setInputType] = useState('password');
|
||||||
const [field, meta] = useField({ name, validate });
|
const [field, meta] = useField({ name, validate });
|
||||||
|
|
||||||
@@ -44,7 +52,7 @@ function PasswordInput(props) {
|
|||||||
value={field.value === '$encrypted$' ? '' : field.value}
|
value={field.value === '$encrypted$' ? '' : field.value}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
isRequired={isRequired}
|
isRequired={isRequired}
|
||||||
validated={isValid ? 'default' : 'error'}
|
validated={isValid || isFieldGroupValid ? 'default' : 'error'}
|
||||||
type={inputType}
|
type={inputType}
|
||||||
onChange={(_, event) => {
|
onChange={(_, event) => {
|
||||||
field.onChange(event);
|
field.onChange(event);
|
||||||
|
|||||||
@@ -26,7 +26,12 @@ const FileUpload = styled(PFFileUpload)`
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function CredentialInput({ fieldOptions, credentialKind, ...rest }) {
|
function CredentialInput({
|
||||||
|
fieldOptions,
|
||||||
|
isFieldGroupValid,
|
||||||
|
credentialKind,
|
||||||
|
...rest
|
||||||
|
}) {
|
||||||
const [fileName, setFileName] = useState('');
|
const [fileName, setFileName] = useState('');
|
||||||
const [fileIsUploading, setFileIsUploading] = useState(false);
|
const [fileIsUploading, setFileIsUploading] = useState(false);
|
||||||
const [subFormField, meta, helpers] = useField(`inputs.${fieldOptions.id}`);
|
const [subFormField, meta, helpers] = useField(`inputs.${fieldOptions.id}`);
|
||||||
@@ -116,6 +121,7 @@ function CredentialInput({ fieldOptions, credentialKind, ...rest }) {
|
|||||||
<>
|
<>
|
||||||
{RevertReplaceButton}
|
{RevertReplaceButton}
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
|
isFieldGroupValid={isFieldGroupValid}
|
||||||
{...subFormField}
|
{...subFormField}
|
||||||
id={`credential-${fieldOptions.id}`}
|
id={`credential-${fieldOptions.id}`}
|
||||||
{...rest}
|
{...rest}
|
||||||
@@ -169,7 +175,9 @@ function CredentialField({ credentialType, fieldOptions }) {
|
|||||||
name: `inputs.${fieldOptions.id}`,
|
name: `inputs.${fieldOptions.id}`,
|
||||||
validate: validateField(),
|
validate: validateField(),
|
||||||
});
|
});
|
||||||
const isValid = !(meta.touched && meta.error);
|
const isValid =
|
||||||
|
!(meta.touched && meta.error) ||
|
||||||
|
formikValues.passwordPrompts[fieldOptions.id];
|
||||||
|
|
||||||
if (fieldOptions.choices) {
|
if (fieldOptions.choices) {
|
||||||
const selectOptions = fieldOptions.choices.map(choice => {
|
const selectOptions = fieldOptions.choices.map(choice => {
|
||||||
@@ -235,7 +243,10 @@ function CredentialField({ credentialType, fieldOptions }) {
|
|||||||
isRequired={isRequired}
|
isRequired={isRequired}
|
||||||
validated={isValid ? 'default' : 'error'}
|
validated={isValid ? 'default' : 'error'}
|
||||||
>
|
>
|
||||||
<CredentialInput fieldOptions={fieldOptions} />
|
<CredentialInput
|
||||||
|
isFieldGroupValid={isValid}
|
||||||
|
fieldOptions={fieldOptions}
|
||||||
|
/>
|
||||||
</CredentialPluginField>
|
</CredentialPluginField>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,15 +98,23 @@ function CredentialPluginField(props) {
|
|||||||
const [, meta, helpers] = useField(`inputs.${fieldOptions.id}`);
|
const [, meta, helpers] = useField(`inputs.${fieldOptions.id}`);
|
||||||
const [passwordPromptField] = useField(`passwordPrompts.${fieldOptions.id}`);
|
const [passwordPromptField] = useField(`passwordPrompts.${fieldOptions.id}`);
|
||||||
|
|
||||||
const invalidHelperTextToDisplay = meta.error && meta.touched && (
|
let invalidHelperTextToDisplay;
|
||||||
<div
|
|
||||||
className={css(styles.formHelperText, styles.modifiers.error)}
|
if (meta.error && meta.touched) {
|
||||||
id={`${fieldOptions.id}-helper`}
|
invalidHelperTextToDisplay = (
|
||||||
aria-live="polite"
|
<div
|
||||||
>
|
className={css(styles.formHelperText, styles.modifiers.error)}
|
||||||
{meta.error}
|
id={`${fieldOptions.id}-helper`}
|
||||||
</div>
|
aria-live="polite"
|
||||||
);
|
>
|
||||||
|
{meta.error}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.id === 'vault_password' && passwordPromptField.value) {
|
||||||
|
invalidHelperTextToDisplay = null;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (passwordPromptField.value) {
|
if (passwordPromptField.value) {
|
||||||
@@ -119,8 +127,6 @@ function CredentialPluginField(props) {
|
|||||||
<>
|
<>
|
||||||
{fieldOptions.ask_at_runtime ? (
|
{fieldOptions.ask_at_runtime ? (
|
||||||
<FieldWithPrompt
|
<FieldWithPrompt
|
||||||
fieldId={`credential-${fieldOptions.id}`}
|
|
||||||
helperTextInvalid={meta.error}
|
|
||||||
isRequired={isRequired}
|
isRequired={isRequired}
|
||||||
label={fieldOptions.label}
|
label={fieldOptions.label}
|
||||||
promptId={`credential-prompt-${fieldOptions.id}`}
|
promptId={`credential-prompt-${fieldOptions.id}`}
|
||||||
|
|||||||
Reference in New Issue
Block a user