Merge pull request #427 from mfrances17/user-menu-cmds
Action menu commands for User Fed LDAP settings
This commit is contained in:
commit
27a9c9b650
2 changed files with 82 additions and 20 deletions
|
@ -48,6 +48,8 @@ const LdapSettingsHeader = ({
|
||||||
}: LdapSettingsHeaderProps) => {
|
}: LdapSettingsHeaderProps) => {
|
||||||
const { t } = useTranslation("user-federation");
|
const { t } = useTranslation("user-federation");
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const adminClient = useAdminClient();
|
||||||
|
const { addAlert } = useAlerts();
|
||||||
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
||||||
titleKey: "user-federation:userFedDisableConfirmTitle",
|
titleKey: "user-federation:userFedDisableConfirmTitle",
|
||||||
messageKey: "user-federation:userFedDisableConfirm",
|
messageKey: "user-federation:userFedDisableConfirm",
|
||||||
|
@ -57,6 +59,62 @@ const LdapSettingsHeader = ({
|
||||||
save();
|
save();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const syncChangedUsers = async () => {
|
||||||
|
try {
|
||||||
|
if (id) {
|
||||||
|
const response = await adminClient.userStorageProvider.sync({
|
||||||
|
id: id,
|
||||||
|
action: "triggerChangedUsersSync",
|
||||||
|
});
|
||||||
|
if (response.ignored) {
|
||||||
|
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.`,
|
||||||
|
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(`${response.status}.`, AlertVariant.warning);
|
||||||
|
} 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<DisableConfirm />
|
<DisableConfirm />
|
||||||
|
@ -67,34 +125,22 @@ const LdapSettingsHeader = ({
|
||||||
titleKey="LDAP"
|
titleKey="LDAP"
|
||||||
subKey=""
|
subKey=""
|
||||||
dropdownItems={[
|
dropdownItems={[
|
||||||
<DropdownItem
|
<DropdownItem key="sync" onClick={syncChangedUsers}>
|
||||||
key="sync"
|
|
||||||
onClick={() => console.log("Sync users TBD")}
|
|
||||||
>
|
|
||||||
{t("syncChangedUsers")}
|
{t("syncChangedUsers")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem
|
<DropdownItem key="syncall" onClick={syncAllUsers}>
|
||||||
key="syncall"
|
|
||||||
onClick={() => console.log("Sync all users TBD")}
|
|
||||||
>
|
|
||||||
{t("syncAllUsers")}
|
{t("syncAllUsers")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem
|
<DropdownItem key="unlink" onClick={unlinkUsers}>
|
||||||
key="unlink"
|
|
||||||
onClick={() => console.log("Unlink users TBD")}
|
|
||||||
>
|
|
||||||
{t("unlinkUsers")}
|
{t("unlinkUsers")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem
|
<DropdownItem key="remove" onClick={toggleRemoveUsersDialog}>
|
||||||
key="remove"
|
|
||||||
onClick={() => toggleRemoveUsersDialog()}
|
|
||||||
>
|
|
||||||
{t("removeImported")}
|
{t("removeImported")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownSeparator key="separator" />,
|
<DropdownSeparator key="separator" />,
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="delete"
|
key="delete"
|
||||||
onClick={() => toggleDeleteDialog()}
|
onClick={toggleDeleteDialog}
|
||||||
data-testid="delete-ldap-cmd"
|
data-testid="delete-ldap-cmd"
|
||||||
>
|
>
|
||||||
{t("deleteProvider")}
|
{t("deleteProvider")}
|
||||||
|
@ -147,6 +193,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) => {
|
const save = async (component: ComponentRepresentation) => {
|
||||||
try {
|
try {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -176,8 +233,7 @@ export const UserFederationLdapSettings = () => {
|
||||||
continueButtonLabel: "common:remove",
|
continueButtonLabel: "common:remove",
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
try {
|
try {
|
||||||
console.log("Remove imported TBD");
|
removeImportedUsers();
|
||||||
// TODO await remove imported users command
|
|
||||||
addAlert(t("removeImportedUsersSuccess"), AlertVariant.success);
|
addAlert(t("removeImportedUsersSuccess"), AlertVariant.success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addAlert(t("removeImportedUsersError", { error }), AlertVariant.danger);
|
addAlert(t("removeImportedUsersError", { error }), AlertVariant.danger);
|
||||||
|
|
|
@ -96,9 +96,15 @@
|
||||||
|
|
||||||
"removeImportedUsers": "Remove imported users?",
|
"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.",
|
"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}}'",
|
"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",
|
"validateName": "You must enter a name",
|
||||||
"validateRealm":"You must enter a realm",
|
"validateRealm":"You must enter a realm",
|
||||||
"validateServerPrincipal":"You must enter a server principal",
|
"validateServerPrincipal":"You must enter a server principal",
|
||||||
|
|
Loading…
Reference in a new issue