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 {
|
import {
|
||||||
ActionGroup,
|
ActionGroup,
|
||||||
AlertVariant,
|
AlertVariant,
|
||||||
|
@ -46,6 +46,7 @@ type ldapComponentRepresentation = ComponentRepresentation & {
|
||||||
type LdapSettingsHeaderProps = {
|
type LdapSettingsHeaderProps = {
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
value: string;
|
value: string;
|
||||||
|
editMode?: string | string[];
|
||||||
save: () => void;
|
save: () => void;
|
||||||
toggleDeleteDialog: () => void;
|
toggleDeleteDialog: () => void;
|
||||||
toggleRemoveUsersDialog: () => void;
|
toggleRemoveUsersDialog: () => void;
|
||||||
|
@ -54,6 +55,7 @@ type LdapSettingsHeaderProps = {
|
||||||
const LdapSettingsHeader = ({
|
const LdapSettingsHeader = ({
|
||||||
onChange,
|
onChange,
|
||||||
value,
|
value,
|
||||||
|
editMode,
|
||||||
save,
|
save,
|
||||||
toggleDeleteDialog,
|
toggleDeleteDialog,
|
||||||
toggleRemoveUsersDialog,
|
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 () => {
|
const syncChangedUsers = async () => {
|
||||||
try {
|
try {
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -130,6 +139,7 @@ const LdapSettingsHeader = ({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DisableConfirm />
|
<DisableConfirm />
|
||||||
|
<UnlinkUsersDialog />
|
||||||
{!id ? (
|
{!id ? (
|
||||||
<ViewHeader titleKey={t("addOneLdap")} />
|
<ViewHeader titleKey={t("addOneLdap")} />
|
||||||
) : (
|
) : (
|
||||||
|
@ -142,7 +152,11 @@ const LdapSettingsHeader = ({
|
||||||
<DropdownItem key="syncall" onClick={syncAllUsers}>
|
<DropdownItem key="syncall" onClick={syncAllUsers}>
|
||||||
{t("syncAllUsers")}
|
{t("syncAllUsers")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem key="unlink" onClick={unlinkUsers}>
|
<DropdownItem
|
||||||
|
key="unlink"
|
||||||
|
isDisabled={editMode ? !editMode.includes("UNSYNCED") : false}
|
||||||
|
onClick={toggleUnlinkUsersDialog}
|
||||||
|
>
|
||||||
{t("unlinkUsers")}
|
{t("unlinkUsers")}
|
||||||
</DropdownItem>,
|
</DropdownItem>,
|
||||||
<DropdownItem key="remove" onClick={toggleRemoveUsersDialog}>
|
<DropdownItem key="remove" onClick={toggleRemoveUsersDialog}>
|
||||||
|
@ -181,6 +195,11 @@ export default function UserFederationLdapSettings() {
|
||||||
|
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
const { addAlert, addError } = useAlerts();
|
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(
|
useFetch(
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -192,11 +211,12 @@ export default function UserFederationLdapSettings() {
|
||||||
(fetchedComponent) => {
|
(fetchedComponent) => {
|
||||||
if (fetchedComponent) {
|
if (fetchedComponent) {
|
||||||
setupForm(fetchedComponent);
|
setupForm(fetchedComponent);
|
||||||
|
setComponent(fetchedComponent);
|
||||||
} else if (id) {
|
} else if (id) {
|
||||||
throw new Error(t("common:notFound"));
|
throw new Error(t("common:notFound"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[]
|
[refreshCount]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setupForm = (component: ComponentRepresentation) => {
|
const setupForm = (component: ComponentRepresentation) => {
|
||||||
|
@ -250,6 +270,7 @@ export default function UserFederationLdapSettings() {
|
||||||
await adminClient.components.update({ id }, component);
|
await adminClient.components.update({ id }, component);
|
||||||
}
|
}
|
||||||
addAlert(t(id ? "saveSuccess" : "createSuccess"), AlertVariant.success);
|
addAlert(t(id ? "saveSuccess" : "createSuccess"), AlertVariant.success);
|
||||||
|
refresh();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addError(`user-federation:${id ? "saveError" : "createError"}`, error);
|
addError(`user-federation:${id ? "saveError" : "createError"}`, error);
|
||||||
}
|
}
|
||||||
|
@ -340,6 +361,7 @@ export default function UserFederationLdapSettings() {
|
||||||
control={form.control}
|
control={form.control}
|
||||||
render={({ onChange, value }) => (
|
render={({ onChange, value }) => (
|
||||||
<LdapSettingsHeader
|
<LdapSettingsHeader
|
||||||
|
editMode={editMode}
|
||||||
value={value}
|
value={value}
|
||||||
save={() => save(form.getValues())}
|
save={() => save(form.getValues())}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|
|
@ -107,6 +107,10 @@ export default {
|
||||||
userFedDisableConfirm:
|
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.",
|
"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?",
|
removeImportedUsers: "Remove imported users?",
|
||||||
removeImportedUsersMessage:
|
removeImportedUsersMessage:
|
||||||
"Do you really want to remove all imported users?",
|
"Do you really want to remove all imported users?",
|
||||||
|
|
Loading…
Reference in a new issue