From c99aa8cbff2ffb87bedd6070fcf4e63d25ed202f Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Tue, 23 Sep 2025 17:11:10 +0100 Subject: [PATCH] dont allow cert to have same name if the same cert type in the UI (#33343) fixes #33246 This adds logic on the UI to show an error if a cert with the same types tries to create a new cert with an existing name --- .../CertificateAuthorities.tsx | 14 ++++++++------ .../AddCertAuthorityModal.tsx | 3 +++ .../components/CustomSCEPForm/helpers.ts | 8 +++++--- .../components/DigicertForm/helpers.ts | 6 ++++-- .../components/HydrantForm/helpers.ts | 5 +++-- .../components/NDESForm/NDESForm.tsx | 1 - 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/CertificateAuthorities.tsx b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/CertificateAuthorities.tsx index 09597adb81..14024a8bac 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/CertificateAuthorities.tsx +++ b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/CertificateAuthorities.tsx @@ -147,12 +147,14 @@ const CertificateAuthorities = () => { onExit={onAddedNewCertAuthority} /> )} - {showEditCertAuthorityModal && selectedCertAuthority && ( - - )} + {showEditCertAuthorityModal && + selectedCertAuthority && + certAuthorities && ( + + )} {showDeleteCertAuthorityModal && selectedCertAuthority && ( ; export const generateFormValidations = ( - customSCEPIntegrations: ICertificateAuthorityPartial[], + certAuthorities: ICertificateAuthorityPartial[], isEditing: boolean ) => { const FORM_VALIDATIONS: IFormValidations = { @@ -54,8 +54,10 @@ export const generateFormValidations = ( isValid: (formData: ICustomSCEPFormData) => { return ( isEditing || - customSCEPIntegrations.find( - (cert) => cert.name === formData.name + certAuthorities.find( + (cert) => + cert.type === "custom_scep_proxy" && + cert.name === formData.name ) === undefined ); }, diff --git a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/DigicertForm/helpers.ts b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/DigicertForm/helpers.ts index 7fc9971aa0..0683288887 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/DigicertForm/helpers.ts +++ b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/DigicertForm/helpers.ts @@ -57,8 +57,10 @@ export const generateFormValidations = ( isValid: (formData: IDigicertFormData) => { return ( isEditing || - certAuthorities.find((cert) => cert.name === formData.name) === - undefined + certAuthorities.find( + (cert) => + cert.type === "digicert" && cert.name === formData.name + ) === undefined ); }, message: "Name is already used by another DigiCert CA.", diff --git a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/HydrantForm/helpers.ts b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/HydrantForm/helpers.ts index c655fa62e8..e262f5cc01 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/HydrantForm/helpers.ts +++ b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/HydrantForm/helpers.ts @@ -59,8 +59,9 @@ export const generateFormValidations = ( isValid: (formData: IHydrantFormData) => { return ( isEditing || - certAuthorities.find((cert) => cert.name === formData.name) === - undefined + certAuthorities.find( + (cert) => cert.type === "hydrant" && cert.name === formData.name + ) === undefined ); }, message: "Name is already used by another Hydrant CA.", diff --git a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/NDESForm/NDESForm.tsx b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/NDESForm/NDESForm.tsx index c22e3eac79..e988dab9ca 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/NDESForm/NDESForm.tsx +++ b/frontend/pages/admin/IntegrationsPage/cards/CertificateAuthorities/components/NDESForm/NDESForm.tsx @@ -31,7 +31,6 @@ const NDESForm = ({ formData, submitBtnText, isSubmitting, - isEditing = false, isDirty = true, onChange, onSubmit,