diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index d894b71bbe..62ed375fcd 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { ActionGroup, AlertVariant, @@ -46,6 +46,7 @@ type ldapComponentRepresentation = ComponentRepresentation & { type LdapSettingsHeaderProps = { onChange: (value: string) => void; value: string; + editMode?: string | string[]; save: () => void; toggleDeleteDialog: () => void; toggleRemoveUsersDialog: () => void; @@ -54,6 +55,7 @@ type LdapSettingsHeaderProps = { const LdapSettingsHeader = ({ onChange, value, + editMode, save, toggleDeleteDialog, toggleRemoveUsersDialog, @@ -72,6 +74,13 @@ const LdapSettingsHeader = ({ }, }); + const [toggleUnlinkUsersDialog, UnlinkUsersDialog] = useConfirmDialog({ + titleKey: "user-federation:userFedUnlinkUsersConfirmTitle", + messageKey: "user-federation:userFedUnlinkUsersConfirm", + continueButtonLabel: "user-federation:unlinkUsers", + onConfirm: () => unlinkUsers(), + }); + const syncChangedUsers = async () => { try { if (id) { @@ -130,6 +139,7 @@ const LdapSettingsHeader = ({ return ( <> + {!id ? ( ) : ( @@ -142,7 +152,11 @@ const LdapSettingsHeader = ({ {t("syncAllUsers")} , - + {t("unlinkUsers")} , @@ -181,6 +195,11 @@ export default function UserFederationLdapSettings() { const { id } = useParams<{ id: string }>(); const { addAlert, addError } = useAlerts(); + const [component, setComponent] = useState(); + const [refreshCount, setRefreshCount] = useState(0); + + const editMode = component?.config?.editMode; + const refresh = () => setRefreshCount((count) => count + 1); useFetch( async () => { @@ -192,11 +211,12 @@ export default function UserFederationLdapSettings() { (fetchedComponent) => { if (fetchedComponent) { setupForm(fetchedComponent); + setComponent(fetchedComponent); } else if (id) { throw new Error(t("common:notFound")); } }, - [] + [refreshCount] ); const setupForm = (component: ComponentRepresentation) => { @@ -250,6 +270,7 @@ export default function UserFederationLdapSettings() { await adminClient.components.update({ id }, component); } addAlert(t(id ? "saveSuccess" : "createSuccess"), AlertVariant.success); + refresh(); } catch (error) { addError(`user-federation:${id ? "saveError" : "createError"}`, error); } @@ -340,6 +361,7 @@ export default function UserFederationLdapSettings() { control={form.control} render={({ onChange, value }) => ( save(form.getValues())} onChange={onChange} diff --git a/src/user-federation/messages.ts b/src/user-federation/messages.ts index 512b9a3606..904d445174 100644 --- a/src/user-federation/messages.ts +++ b/src/user-federation/messages.ts @@ -107,6 +107,10 @@ export default { userFedDisableConfirm: "If you disable this user federation provider, it will not be considered for queries and imported users will be disabled and read-only until the provider is enabled again.", + userFedUnlinkUsersConfirmTitle: "Unlink all users?", + userFedUnlinkUsersConfirm: + "Do you want to unlink all the users? Any users without a password in the database will not be able to authenticate anymore.", + removeImportedUsers: "Remove imported users?", removeImportedUsersMessage: "Do you really want to remove all imported users?",