mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
feat: mfa reset - wip
This commit is contained in:
@@ -59,3 +59,10 @@ export async function validateMfaAccess(): Promise<MfaAccessValidationResponse>
|
|||||||
return { valid: false };
|
return { valid: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resetUserMfa(
|
||||||
|
userId: string,
|
||||||
|
): Promise<{ success: boolean }> {
|
||||||
|
const req = await api.post<{ success: boolean }>('/mfa/reset', { userId });
|
||||||
|
return req.data;
|
||||||
|
}
|
||||||
|
|||||||
+46
-4
@@ -1,23 +1,41 @@
|
|||||||
import { Menu, ActionIcon, Text } from "@mantine/core";
|
import { Menu, ActionIcon, Text } from "@mantine/core";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { IconDots, IconTrash } from "@tabler/icons-react";
|
import { IconDots, IconTrash, IconShieldOff } from "@tabler/icons-react";
|
||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
import { useDeleteWorkspaceMemberMutation } from "@/features/workspace/queries/workspace-query.ts";
|
import {
|
||||||
|
useDeleteWorkspaceMemberMutation,
|
||||||
|
useResetUserMfaMutation
|
||||||
|
} from "@/features/workspace/queries/workspace-query.ts";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useUserRole from "@/hooks/use-user-role.tsx";
|
import useUserRole from "@/hooks/use-user-role.tsx";
|
||||||
|
import { useLicense } from "@/ee/hooks/use-license.tsx";
|
||||||
|
import { isCloud } from "@/lib/config.ts";
|
||||||
|
import { UserRole } from "@/lib/types.ts";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
userRole: string;
|
||||||
}
|
}
|
||||||
export default function MemberActionMenu({ userId }: Props) {
|
export default function MemberActionMenu({ userId, userRole }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const deleteWorkspaceMemberMutation = useDeleteWorkspaceMemberMutation();
|
const deleteWorkspaceMemberMutation = useDeleteWorkspaceMemberMutation();
|
||||||
const { isAdmin } = useUserRole();
|
const resetUserMfaMutation = useResetUserMfaMutation();
|
||||||
|
const { isAdmin, isOwner } = useUserRole();
|
||||||
|
const { hasLicenseKey } = useLicense();
|
||||||
|
|
||||||
|
// Show MFA reset only for self-hosted enterprise edition
|
||||||
|
// Admins cannot reset MFA for owners
|
||||||
|
const canResetMfa = isOwner || (isAdmin && userRole !== UserRole.OWNER);
|
||||||
|
const showMfaReset = !isCloud() && hasLicenseKey && canResetMfa;
|
||||||
|
|
||||||
const onRevoke = async () => {
|
const onRevoke = async () => {
|
||||||
await deleteWorkspaceMemberMutation.mutateAsync({ userId });
|
await deleteWorkspaceMemberMutation.mutateAsync({ userId });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onResetMfa = async () => {
|
||||||
|
await resetUserMfaMutation.mutateAsync({ userId });
|
||||||
|
};
|
||||||
|
|
||||||
const openRevokeModal = () =>
|
const openRevokeModal = () =>
|
||||||
modals.openConfirmModal({
|
modals.openConfirmModal({
|
||||||
title: t("Delete member"),
|
title: t("Delete member"),
|
||||||
@@ -34,6 +52,22 @@ export default function MemberActionMenu({ userId }: Props) {
|
|||||||
onConfirm: onRevoke,
|
onConfirm: onRevoke,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const openResetMfaModal = () =>
|
||||||
|
modals.openConfirmModal({
|
||||||
|
title: t("Reset MFA"),
|
||||||
|
children: (
|
||||||
|
<Text size="sm">
|
||||||
|
{t(
|
||||||
|
"Are you sure you want to reset MFA for this user? They will need to set up MFA again.",
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
),
|
||||||
|
centered: true,
|
||||||
|
labels: { confirm: t("Reset"), cancel: t("Cancel") },
|
||||||
|
confirmProps: { color: "red" },
|
||||||
|
onConfirm: onResetMfa,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Menu
|
<Menu
|
||||||
@@ -51,6 +85,14 @@ export default function MemberActionMenu({ userId }: Props) {
|
|||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
|
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
|
{showMfaReset && (
|
||||||
|
<Menu.Item
|
||||||
|
onClick={openResetMfaModal}
|
||||||
|
leftSection={<IconShieldOff size={16} />}
|
||||||
|
>
|
||||||
|
{t("Reset MFA")}
|
||||||
|
</Menu.Item>
|
||||||
|
)}
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
c="red"
|
c="red"
|
||||||
onClick={openRevokeModal}
|
onClick={openRevokeModal}
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ export default function WorkspaceMembersTable() {
|
|||||||
/>
|
/>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
{isAdmin && <MemberActionMenu userId={user.id} />}
|
{isAdmin && <MemberActionMenu userId={user.id} userRole={user.role} />}
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
getAppVersion,
|
getAppVersion,
|
||||||
deleteWorkspaceMember,
|
deleteWorkspaceMember,
|
||||||
} from "@/features/workspace/services/workspace-service";
|
} from "@/features/workspace/services/workspace-service";
|
||||||
|
import { resetUserMfa } from "@/ee/mfa";
|
||||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
import { IPagination, QueryParams } from "@/lib/types.ts";
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
import {
|
import {
|
||||||
@@ -192,3 +193,29 @@ export function useAppVersion(
|
|||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useResetUserMfaMutation() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<
|
||||||
|
{ success: boolean },
|
||||||
|
Error,
|
||||||
|
{ userId: string }
|
||||||
|
>({
|
||||||
|
mutationFn: ({ userId }) => resetUserMfa(userId),
|
||||||
|
onSuccess: () => {
|
||||||
|
notifications.show({
|
||||||
|
message: t("MFA has been reset successfully"),
|
||||||
|
color: "green"
|
||||||
|
});
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["workspaceMembers"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
const errorMessage = error["response"]?.data?.message || t("Failed to reset MFA");
|
||||||
|
notifications.show({ message: errorMessage, color: "red" });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
Submodule apps/server/src/ee updated: c889c88001...2f4ed49609
Reference in New Issue
Block a user