user cmds added

This commit is contained in:
mfrances 2021-03-09 14:55:08 -05:00
parent 7bf85196e3
commit e093c15ea2
2 changed files with 86 additions and 15 deletions

View file

@ -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 (
<>
<DisableConfirm />
@ -67,22 +131,13 @@ const LdapSettingsHeader = ({
titleKey="LDAP"
subKey=""
dropdownItems={[
<DropdownItem
key="sync"
onClick={() => console.log("Sync users TBD")}
>
<DropdownItem key="sync" onClick={() => syncChangedUsers()}>
{t("syncChangedUsers")}
</DropdownItem>,
<DropdownItem
key="syncall"
onClick={() => console.log("Sync all users TBD")}
>
<DropdownItem key="syncall" onClick={() => syncAllUsers()}>
{t("syncAllUsers")}
</DropdownItem>,
<DropdownItem
key="unlink"
onClick={() => console.log("Unlink users TBD")}
>
<DropdownItem key="unlink" onClick={() => unlinkUsers()}>
{t("unlinkUsers")}
</DropdownItem>,
<DropdownItem
@ -147,6 +202,17 @@ export const UserFederationLdapSettings = () => {
});
};
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);

View file

@ -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",