From 733d5f4b6f9f317c6707c5741eada2a815ab0f90 Mon Sep 17 00:00:00 2001 From: mfrances Date: Fri, 19 Feb 2021 18:13:07 -0500 Subject: [PATCH] ldap saves working --- .../UserFederationLdapSettings.tsx | 108 +++++++++++------- src/user-federation/UserFederationSection.tsx | 6 +- .../ldap/LdapSettingsAdvanced.tsx | 4 +- .../ldap/LdapSettingsConnection.tsx | 2 +- .../ldap/LdapSettingsGeneral.tsx | 50 ++++---- .../ldap/LdapSettingsKerberosIntegration.tsx | 4 +- .../ldap/LdapSettingsSearching.tsx | 2 +- .../ldap/LdapSettingsSynchronization.tsx | 2 +- 8 files changed, 104 insertions(+), 74 deletions(-) diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index 893572a094..c67781f2b2 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -47,6 +47,7 @@ const LdapSettingsHeader = ({ toggleRemoveUsersDialog, }: LdapSettingsHeaderProps) => { const { t } = useTranslation("user-federation"); + const { id } = useParams<{ id: string }>(); const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ titleKey: "user-federation:userFedDisableConfirmTitle", messageKey: "user-federation:userFedDisableConfirm", @@ -59,46 +60,53 @@ const LdapSettingsHeader = ({ return ( <> - console.log("Sync users TBD")} - > - {t("syncChangedUsers")} - , - console.log("Sync all users TBD")} - > - {t("syncAllUsers")} - , - console.log("Unlink users TBD")} - > - {t("unlinkUsers")} - , - toggleRemoveUsersDialog()}> - {t("removeImported")} - , - , - toggleDeleteDialog()}> - {t("deleteProvider")} - , - ]} - isEnabled={value === "true"} - onToggle={(value) => { - if (!value) { - toggleDisableDialog(); - } else { - onChange("" + value); - save(); - } - }} - /> + {id === "new" ? ( + + ) : ( + console.log("Sync users TBD")} + > + {t("syncChangedUsers")} + , + console.log("Sync all users TBD")} + > + {t("syncAllUsers")} + , + console.log("Unlink users TBD")} + > + {t("unlinkUsers")} + , + toggleRemoveUsersDialog()} + > + {t("removeImported")} + , + , + toggleDeleteDialog()}> + {t("deleteProvider")} + , + ]} + isEnabled={value === "true"} + onToggle={(value) => { + if (!value) { + toggleDisableDialog(); + } else { + onChange("" + value); + save(); + } + }} + /> + )} ); }; @@ -134,11 +142,23 @@ export const UserFederationLdapSettings = () => { const save = async (component: ComponentRepresentation) => { try { - await adminClient.components.update({ id }, component); + if (id) { + if (id === "new") { + await adminClient.components.create(component); + } else { + await adminClient.components.update({ id }, component); + } + } setupForm(component as ComponentRepresentation); - addAlert(t("saveSuccess"), AlertVariant.success); + addAlert( + t(id === "new" ? "createSuccess" : "saveSuccess"), + AlertVariant.success + ); } catch (error) { - addAlert(`${t("saveError")} '${error}'`, AlertVariant.danger); + addAlert( + `${t(id === "new" ? "createError" : "saveError")} '${error}'`, + AlertVariant.danger + ); } }; @@ -179,7 +199,7 @@ export const UserFederationLdapSettings = () => { ( { - + history.push(`${url}/ldap/new`)} + data-testid="ldap-card" + > diff --git a/src/user-federation/ldap/LdapSettingsAdvanced.tsx b/src/user-federation/ldap/LdapSettingsAdvanced.tsx index 139d174e3a..f10fdd566e 100644 --- a/src/user-federation/ldap/LdapSettingsAdvanced.tsx +++ b/src/user-federation/ldap/LdapSettingsAdvanced.tsx @@ -74,7 +74,7 @@ export const LdapSettingsAdvanced = ({ > ( ( ( { const { t } = useTranslation("user-federation"); const helpText = useTranslation("user-federation-help").t; + const { realm } = useRealm(); const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false); @@ -51,12 +54,36 @@ export const LdapSettingsGeneral = ({ isRequired > {/* These hidden fields are required so data object written back matches data retrieved */} -