From e093c15ea2738f132aa29693e9159eec96e71f5d Mon Sep 17 00:00:00 2001 From: mfrances Date: Tue, 9 Mar 2021 14:55:08 -0500 Subject: [PATCH 1/3] user cmds added --- .../UserFederationLdapSettings.tsx | 93 ++++++++++++++++--- src/user-federation/messages.json | 8 +- 2 files changed, 86 insertions(+), 15 deletions(-) diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index 45bc47396a..d42bbecbf0 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -48,6 +48,8 @@ const LdapSettingsHeader = ({ }: LdapSettingsHeaderProps) => { const { t } = useTranslation("user-federation"); const { id } = useParams<{ id: string }>(); + const adminClient = useAdminClient(); + const { addAlert } = useAlerts(); const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ titleKey: "user-federation:userFedDisableConfirmTitle", messageKey: "user-federation:userFedDisableConfirm", @@ -57,6 +59,68 @@ const LdapSettingsHeader = ({ save(); }, }); + + const syncChangedUsers = async () => { + try { + if (id) { + const response = await adminClient.userStorageProvider.sync({ + id: id, + action: "triggerChangedUsersSync", + }); + if (response.ignored) { + addAlert( + t("syncUsersSuccess") + ` ${response.status}.`, + AlertVariant.success + ); + } else { + addAlert( + t("syncUsersSuccess") + + ` ${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, + AlertVariant.success + ); + } + } + } catch (error) { + addAlert(t("syncUsersError", { error }), AlertVariant.danger); + } + }; + + const syncAllUsers = async () => { + try { + if (id) { + const response = await adminClient.userStorageProvider.sync({ + id: id, + action: "triggerFullSync", + }); + if (response.ignored) { + addAlert( + t("syncUsersSuccess") + ` ${response.status}.`, + AlertVariant.success + ); + } else { + addAlert( + t("syncUsersSuccess") + + ` ${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, + AlertVariant.success + ); + } + } + } catch (error) { + addAlert(t("syncUsersError", { error }), AlertVariant.danger); + } + }; + + const unlinkUsers = async () => { + try { + if (id) { + await adminClient.userStorageProvider.unlinkUsers({ id }); + } + addAlert(t("unlinkUsersSuccess"), AlertVariant.success); + } catch (error) { + addAlert(t("unlinkUsersError", { error }), AlertVariant.danger); + } + }; + return ( <> @@ -67,22 +131,13 @@ const LdapSettingsHeader = ({ titleKey="LDAP" subKey="" dropdownItems={[ - console.log("Sync users TBD")} - > + syncChangedUsers()}> {t("syncChangedUsers")} , - console.log("Sync all users TBD")} - > + syncAllUsers()}> {t("syncAllUsers")} , - console.log("Unlink users TBD")} - > + unlinkUsers()}> {t("unlinkUsers")} , { }); }; + const removeImportedUsers = async () => { + try { + if (id) { + await adminClient.userStorageProvider.removeImportedUsers({ id }); + } + addAlert(t("removeImportedUsersSuccess"), AlertVariant.success); + } catch (error) { + addAlert(t("removeImportedUsersError", { error }), AlertVariant.danger); + } + }; + const save = async (component: ComponentRepresentation) => { try { if (id) { @@ -176,8 +242,7 @@ export const UserFederationLdapSettings = () => { continueButtonLabel: "common:remove", onConfirm: async () => { try { - console.log("Remove imported TBD"); - // TODO await remove imported users command + removeImportedUsers(); addAlert(t("removeImportedUsersSuccess"), AlertVariant.success); } catch (error) { addAlert(t("removeImportedUsersError", { error }), AlertVariant.danger); diff --git a/src/user-federation/messages.json b/src/user-federation/messages.json index 885af7eb5c..13e6580a79 100644 --- a/src/user-federation/messages.json +++ b/src/user-federation/messages.json @@ -96,9 +96,15 @@ "removeImportedUsers": "Remove imported users?", "removeImportedUsersMessage": "Do you really want to remove all imported users? The option \"Unlink users\" makes sense just for the Edit Mode \"Unsynced\" and there should be a warning that \"unlinked\" users without the password in the Keycloak database won't be able to authenticate.", - "removeImportedUsersSuccess": "Imported users have been removed", + "removeImportedUsersSuccess": "Imported users have been removed.", "removeImportedUsersError": "Could not remove imported users: '{{error}}'", + "syncUsersSuccess": "Sync of users finished successfully.", + "syncUsersError": "Could not sync users: '{{error}}'", + + "unlinkUsersSuccess": "Unlink of users finished successfully.", + "unlinkUsersError": "Could not unlink users: '{{error}}'", + "validateName": "You must enter a name", "validateRealm":"You must enter a realm", "validateServerPrincipal":"You must enter a server principal", From e1678d6113b8e2a30f386afb5f0132266174d425 Mon Sep 17 00:00:00 2001 From: mfrances Date: Wed, 10 Mar 2021 10:42:31 -0500 Subject: [PATCH 2/3] pr review changes --- src/user-federation/UserFederationLdapSettings.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index d42bbecbf0..15421f9ca7 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -131,25 +131,22 @@ const LdapSettingsHeader = ({ titleKey="LDAP" subKey="" dropdownItems={[ - syncChangedUsers()}> + {t("syncChangedUsers")} , - syncAllUsers()}> + {t("syncAllUsers")} , - unlinkUsers()}> + {t("unlinkUsers")} , - toggleRemoveUsersDialog()} - > + {t("removeImported")} , , toggleDeleteDialog()} + onClick={toggleDeleteDialog} data-testid="delete-ldap-cmd" > {t("deleteProvider")} From 39cc1b998c24492cc29b44fa852c3f1ecca4276a Mon Sep 17 00:00:00 2001 From: mfrances Date: Wed, 10 Mar 2021 11:06:53 -0500 Subject: [PATCH 3/3] rm success string from ignored --- src/user-federation/UserFederationLdapSettings.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/user-federation/UserFederationLdapSettings.tsx b/src/user-federation/UserFederationLdapSettings.tsx index 15421f9ca7..9ebb83a628 100644 --- a/src/user-federation/UserFederationLdapSettings.tsx +++ b/src/user-federation/UserFederationLdapSettings.tsx @@ -68,14 +68,11 @@ const LdapSettingsHeader = ({ action: "triggerChangedUsersSync", }); if (response.ignored) { - addAlert( - t("syncUsersSuccess") + ` ${response.status}.`, - AlertVariant.success - ); + addAlert(`${response.status}.`, AlertVariant.warning); } else { addAlert( t("syncUsersSuccess") + - ` ${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, + `${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, AlertVariant.success ); } @@ -93,14 +90,11 @@ const LdapSettingsHeader = ({ action: "triggerFullSync", }); if (response.ignored) { - addAlert( - t("syncUsersSuccess") + ` ${response.status}.`, - AlertVariant.success - ); + addAlert(`${response.status}.`, AlertVariant.warning); } else { addAlert( t("syncUsersSuccess") + - ` ${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, + `${response.added} users added, ${response.updated} users updated, ${response.removed} users removed, ${response.failed} users failed.`, AlertVariant.success ); }