Ask for confirmation before unlinking users (#1477)
* Ask for confirmation before unlinking users * Refresh data after saving
This commit is contained in:
parent
16042dd1f6
commit
c31b357429
2 changed files with 29 additions and 3 deletions
|
@ -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 (
|
||||
<>
|
||||
<DisableConfirm />
|
||||
<UnlinkUsersDialog />
|
||||
{!id ? (
|
||||
<ViewHeader titleKey={t("addOneLdap")} />
|
||||
) : (
|
||||
|
@ -142,7 +152,11 @@ const LdapSettingsHeader = ({
|
|||
<DropdownItem key="syncall" onClick={syncAllUsers}>
|
||||
{t("syncAllUsers")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem key="unlink" onClick={unlinkUsers}>
|
||||
<DropdownItem
|
||||
key="unlink"
|
||||
isDisabled={editMode ? !editMode.includes("UNSYNCED") : false}
|
||||
onClick={toggleUnlinkUsersDialog}
|
||||
>
|
||||
{t("unlinkUsers")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem key="remove" onClick={toggleRemoveUsersDialog}>
|
||||
|
@ -181,6 +195,11 @@ export default function UserFederationLdapSettings() {
|
|||
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { addAlert, addError } = useAlerts();
|
||||
const [component, setComponent] = useState<ComponentRepresentation>();
|
||||
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 }) => (
|
||||
<LdapSettingsHeader
|
||||
editMode={editMode}
|
||||
value={value}
|
||||
save={() => save(form.getValues())}
|
||||
onChange={onChange}
|
||||
|
|
|
@ -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?",
|
||||
|
|
Loading…
Reference in a new issue