snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import type { IconProps } from '@rocket.chat/fuselage';
|
||||
import type { GenericMenuItemProps } from '@rocket.chat/ui-client';
|
||||
import { usePermission, useRoute } from '@rocket.chat/ui-contexts';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AdminUsersTab } from '../AdminUsersPage';
|
||||
import { useChangeAdminStatusAction } from './useChangeAdminStatusAction';
|
||||
import { useChangeUserStatusAction } from './useChangeUserStatusAction';
|
||||
import { useDeleteUserAction } from './useDeleteUserAction';
|
||||
import { useResetE2EEKeyAction } from './useResetE2EEKeyAction';
|
||||
import { useResetTOTPAction } from './useResetTOTPAction';
|
||||
|
||||
export type AdminUserAction = {
|
||||
type?: string;
|
||||
content: string;
|
||||
icon?: IconProps['name'];
|
||||
title?: string;
|
||||
variant?: 'danger';
|
||||
onClick: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
type AdminUserMenuAction = {
|
||||
id: string;
|
||||
title: string;
|
||||
items: GenericMenuItemProps[];
|
||||
}[];
|
||||
|
||||
export type AdminUserInfoActionsProps = {
|
||||
username: IUser['username'];
|
||||
userId: IUser['_id'];
|
||||
isFederatedUser: IUser['federated'];
|
||||
isActive: boolean;
|
||||
isAdmin: boolean;
|
||||
tab: AdminUsersTab;
|
||||
onChange: () => void;
|
||||
onReload: () => void;
|
||||
};
|
||||
|
||||
const useAdminUserInfoActionsSpread = (actions: Record<string, AdminUserAction>, size = 2) => {
|
||||
const actionSpread = useMemo(() => {
|
||||
const entries = Object.entries(actions);
|
||||
|
||||
const options = entries.slice(0, size);
|
||||
const slicedOptions = entries.slice(size, entries.length);
|
||||
|
||||
const menuActions = slicedOptions.reduce((acc, [_key, item]) => {
|
||||
const group = item.type ? item.type : '';
|
||||
const section = acc.find((section: { id: string }) => section.id === group);
|
||||
|
||||
const newItem = {
|
||||
...item,
|
||||
id: item.content || item.title || '',
|
||||
content: item.content || item.title,
|
||||
};
|
||||
|
||||
if (section) {
|
||||
section.items.push(newItem);
|
||||
return acc;
|
||||
}
|
||||
|
||||
const newSection = { id: group, title: '', items: [newItem] };
|
||||
acc.push(newSection);
|
||||
|
||||
return acc;
|
||||
}, [] as AdminUserMenuAction);
|
||||
|
||||
return { actions: options, menuActions };
|
||||
}, [size, actions]);
|
||||
|
||||
return actionSpread;
|
||||
};
|
||||
|
||||
export const useAdminUserInfoActions = ({
|
||||
username,
|
||||
userId,
|
||||
isFederatedUser,
|
||||
isActive,
|
||||
isAdmin,
|
||||
tab,
|
||||
onChange,
|
||||
onReload,
|
||||
}: AdminUserInfoActionsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const directRoute = useRoute('direct');
|
||||
const userRoute = useRoute('admin-users');
|
||||
|
||||
const canDirectMessage = usePermission('create-d');
|
||||
const canEditOtherUserInfo = usePermission('edit-other-user-info');
|
||||
|
||||
const changeAdminStatusAction = useChangeAdminStatusAction(username, isAdmin, onChange);
|
||||
const changeUserStatusAction = useChangeUserStatusAction(userId, isActive, onChange);
|
||||
const deleteUserAction = useDeleteUserAction(userId, onChange, onReload);
|
||||
const resetTOTPAction = useResetTOTPAction(userId);
|
||||
const resetE2EKeyAction = useResetE2EEKeyAction(userId);
|
||||
|
||||
const directMessageClick = useCallback(
|
||||
() =>
|
||||
username &&
|
||||
directRoute.push({
|
||||
rid: username,
|
||||
}),
|
||||
[directRoute, username],
|
||||
);
|
||||
|
||||
const editUserClick = useCallback(
|
||||
() =>
|
||||
userRoute.push({
|
||||
context: 'edit',
|
||||
id: userId,
|
||||
}),
|
||||
[userId, userRoute],
|
||||
);
|
||||
|
||||
const isNotPendingDeactivatedNorFederated = tab !== 'pending' && tab !== 'deactivated' && !isFederatedUser;
|
||||
|
||||
const options = useMemo(
|
||||
() => ({
|
||||
...(canDirectMessage && {
|
||||
directMessage: {
|
||||
icon: 'balloon',
|
||||
content: t('Direct_Message'),
|
||||
onClick: directMessageClick,
|
||||
} as AdminUserAction,
|
||||
}),
|
||||
...(canEditOtherUserInfo && {
|
||||
editUsereditUser: {
|
||||
icon: 'edit',
|
||||
content: t('Edit'),
|
||||
title: isFederatedUser ? t('Edit_Federated_User_Not_Allowed') : t('Edit'),
|
||||
onClick: editUserClick,
|
||||
disabled: isFederatedUser,
|
||||
} as AdminUserAction,
|
||||
}),
|
||||
...(isNotPendingDeactivatedNorFederated && changeAdminStatusAction && { changeAdminStatusAction }),
|
||||
...(isNotPendingDeactivatedNorFederated && resetE2EKeyAction && { resetE2EKeyAction }),
|
||||
...(isNotPendingDeactivatedNorFederated && resetTOTPAction && { resetTOTPAction }),
|
||||
...(changeUserStatusAction && !isFederatedUser && { changeUserStatusAction }),
|
||||
...(deleteUserAction && { deleteUserAction }),
|
||||
}),
|
||||
[
|
||||
canDirectMessage,
|
||||
canEditOtherUserInfo,
|
||||
changeAdminStatusAction,
|
||||
changeUserStatusAction,
|
||||
deleteUserAction,
|
||||
directMessageClick,
|
||||
editUserClick,
|
||||
isFederatedUser,
|
||||
isNotPendingDeactivatedNorFederated,
|
||||
resetE2EKeyAction,
|
||||
resetTOTPAction,
|
||||
t,
|
||||
],
|
||||
);
|
||||
|
||||
return useAdminUserInfoActionsSpread(options);
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { useToastMessageDispatch, usePermission, useEndpoint } from '@rocket.chat/ui-contexts';
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AdminUserAction } from './useAdminUserInfoActions';
|
||||
|
||||
export const useChangeAdminStatusAction = (
|
||||
username: IUser['username'] = '',
|
||||
isAdmin: boolean,
|
||||
onChange: () => void,
|
||||
): AdminUserAction | undefined => {
|
||||
const { t } = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const addUserToRoleEndpoint = useEndpoint('POST', '/v1/roles.addUserToRole');
|
||||
const removeUserFromRoleEndpoint = useEndpoint('POST', '/v1/roles.removeUserFromRole');
|
||||
|
||||
const canAssignAdminRole = usePermission('assign-admin-role');
|
||||
|
||||
const changeAdminStatus = useCallback(async () => {
|
||||
try {
|
||||
if (isAdmin) {
|
||||
await removeUserFromRoleEndpoint({ roleId: 'admin', username });
|
||||
dispatchToastMessage({ type: 'success', message: t('User_is_no_longer_an_admin') });
|
||||
onChange();
|
||||
return;
|
||||
}
|
||||
await addUserToRoleEndpoint({ roleId: 'admin', username });
|
||||
dispatchToastMessage({ type: 'success', message: t('User_is_now_an_admin') });
|
||||
onChange();
|
||||
} catch (error) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
}
|
||||
}, [isAdmin, removeUserFromRoleEndpoint, username, dispatchToastMessage, addUserToRoleEndpoint, t, onChange]);
|
||||
|
||||
return canAssignAdminRole
|
||||
? {
|
||||
icon: 'key',
|
||||
content: isAdmin ? t('Remove_Admin') : t('Make_Admin'),
|
||||
onClick: changeAdminStatus,
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { useToastMessageDispatch, useTranslation, useEndpoint, usePermission } from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { AdminUserAction } from './useAdminUserInfoActions';
|
||||
import { useConfirmOwnerChanges } from './useConfirmOwnerChanges';
|
||||
|
||||
export const useChangeUserStatusAction = (userId: IUser['_id'], isActive: boolean, onChange: () => void): AdminUserAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const confirmOwnerChanges = useConfirmOwnerChanges();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const changeActiveStatusRequest = useEndpoint('POST', '/v1/users.setActiveStatus');
|
||||
const canEditOtherUserActiveStatus = usePermission('edit-other-user-active-status');
|
||||
const changeActiveStatusMessage = isActive ? 'User_has_been_deactivated' : 'User_has_been_activated';
|
||||
|
||||
const activeStatusQuery = useMemo(
|
||||
() => ({
|
||||
userId,
|
||||
activeStatus: !isActive,
|
||||
confirmRelinquish: false,
|
||||
}),
|
||||
[userId, isActive],
|
||||
);
|
||||
|
||||
const changeActiveStatus = (): Promise<void> =>
|
||||
confirmOwnerChanges(
|
||||
async (confirm = false) => {
|
||||
if (confirm) {
|
||||
activeStatusQuery.confirmRelinquish = confirm;
|
||||
}
|
||||
|
||||
try {
|
||||
await changeActiveStatusRequest(activeStatusQuery);
|
||||
dispatchToastMessage({ type: 'success', message: t(changeActiveStatusMessage) });
|
||||
onChange();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
confirmText: t('Yes_deactivate_it'),
|
||||
},
|
||||
onChange,
|
||||
);
|
||||
|
||||
return canEditOtherUserActiveStatus
|
||||
? {
|
||||
icon: 'user',
|
||||
content: isActive ? t('Deactivate') : t('Activate'),
|
||||
onClick: changeActiveStatus,
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useSetModal, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import type { ComponentProps } from 'react';
|
||||
|
||||
import ConfirmOwnerChangeWarningModal from '../../../../components/ConfirmOwnerChangeModal';
|
||||
|
||||
export const useConfirmOwnerChanges = (): ((
|
||||
action: (confirm?: boolean) => Promise<void>,
|
||||
modalProps: Pick<ComponentProps<typeof ConfirmOwnerChangeWarningModal>, 'contentTitle' | 'confirmText'>,
|
||||
onChange: () => void,
|
||||
) => Promise<void>) => {
|
||||
const setModal = useSetModal();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
return async (action, modalProps, onChange): Promise<void> => {
|
||||
try {
|
||||
return await action();
|
||||
} catch (error: any) {
|
||||
if (error.errorType === 'user-last-owner') {
|
||||
const { shouldChangeOwner, shouldBeRemoved } = error.details;
|
||||
|
||||
const handleConfirm = async (): Promise<void> => {
|
||||
await action(true);
|
||||
setModal();
|
||||
onChange();
|
||||
};
|
||||
|
||||
return setModal(
|
||||
<ConfirmOwnerChangeWarningModal
|
||||
{...modalProps}
|
||||
shouldChangeOwner={shouldChangeOwner}
|
||||
shouldBeRemoved={shouldBeRemoved}
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={(): void => setModal()}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import type { TranslationKey } from '@rocket.chat/ui-contexts';
|
||||
import {
|
||||
useSetModal,
|
||||
useToastMessageDispatch,
|
||||
useRoute,
|
||||
useSetting,
|
||||
usePermission,
|
||||
useEndpoint,
|
||||
useTranslation,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { AdminUserAction } from './useAdminUserInfoActions';
|
||||
import { useConfirmOwnerChanges } from './useConfirmOwnerChanges';
|
||||
|
||||
export const useDeleteUserAction = (userId: IUser['_id'], onChange: () => void, onReload: () => void): AdminUserAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const setModal = useSetModal();
|
||||
const userRoute = useRoute('admin-users');
|
||||
const canDeleteUser = usePermission('delete-user');
|
||||
const erasureType = useSetting('Message_ErasureType');
|
||||
const confirmOwnerChanges = useConfirmOwnerChanges();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const handleDeletedUser = (): void => {
|
||||
setModal();
|
||||
userRoute.push({});
|
||||
onReload();
|
||||
};
|
||||
|
||||
const deleteUserQuery = useMemo(() => ({ userId, confirmRelinquish: false }), [userId]);
|
||||
const deleteUserEndpoint = useEndpoint('POST', '/v1/users.delete');
|
||||
|
||||
const deleteUser = (): Promise<void> =>
|
||||
confirmOwnerChanges(
|
||||
async (confirm = false) => {
|
||||
if (confirm) {
|
||||
deleteUserQuery.confirmRelinquish = confirm;
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteUserEndpoint(deleteUserQuery);
|
||||
dispatchToastMessage({ type: 'success', message: t('User_has_been_deleted') });
|
||||
handleDeletedUser();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
contentTitle: t(`Delete_User_Warning_${erasureType}` as TranslationKey),
|
||||
confirmText: t('Delete'),
|
||||
},
|
||||
onChange,
|
||||
);
|
||||
|
||||
const confirmDeleteUser = useStableCallback(() => {
|
||||
setModal(
|
||||
<GenericModal variant='danger' onConfirm={deleteUser} onCancel={(): void => setModal()} confirmText={t('Delete')}>
|
||||
{t(`Delete_User_Warning_${erasureType}` as TranslationKey)}
|
||||
</GenericModal>,
|
||||
);
|
||||
});
|
||||
|
||||
return canDeleteUser
|
||||
? {
|
||||
icon: 'trash',
|
||||
content: t('Delete'),
|
||||
onClick: confirmDeleteUser,
|
||||
variant: 'danger',
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import type { UsersListStatusParamsGET } from '@rocket.chat/rest-typings';
|
||||
import type { usePagination, useSort } from '@rocket.chat/ui-client';
|
||||
import { useEndpoint } from '@rocket.chat/ui-contexts';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { MutableRefObject } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { AdminUsersTab, UsersTableSortingOption } from '../AdminUsersPage';
|
||||
|
||||
type UseFilteredUsersOptions = {
|
||||
searchTerm: string;
|
||||
prevSearchTerm: MutableRefObject<string>;
|
||||
tab: AdminUsersTab;
|
||||
paginationData: ReturnType<typeof usePagination>;
|
||||
sortData: ReturnType<typeof useSort<UsersTableSortingOption>>;
|
||||
selectedRoles: string[];
|
||||
};
|
||||
|
||||
const useFilteredUsers = ({ searchTerm, prevSearchTerm, sortData, paginationData, tab, selectedRoles }: UseFilteredUsersOptions) => {
|
||||
const { setCurrent, itemsPerPage, current } = paginationData;
|
||||
const { sortBy, sortDirection } = sortData;
|
||||
|
||||
const payload = useMemo(() => {
|
||||
if (searchTerm !== prevSearchTerm.current) {
|
||||
setCurrent(0);
|
||||
}
|
||||
|
||||
const listUsersPayload: Partial<Record<AdminUsersTab, UsersListStatusParamsGET>> = {
|
||||
all: {},
|
||||
pending: {
|
||||
type: 'user',
|
||||
status: 'deactivated',
|
||||
inactiveReason: ['pending_approval'],
|
||||
},
|
||||
active: {
|
||||
status: 'active',
|
||||
},
|
||||
deactivated: {
|
||||
status: 'deactivated',
|
||||
inactiveReason: ['deactivated', 'idle_too_long'],
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
...listUsersPayload[tab],
|
||||
searchTerm,
|
||||
roles: selectedRoles,
|
||||
sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`,
|
||||
count: itemsPerPage,
|
||||
offset: searchTerm === prevSearchTerm.current ? current : 0,
|
||||
};
|
||||
}, [current, itemsPerPage, prevSearchTerm, searchTerm, selectedRoles, setCurrent, sortBy, sortDirection, tab]);
|
||||
const getUsers = useEndpoint('GET', '/v1/users.listByStatus');
|
||||
const usersListQueryResult = useQuery({
|
||||
queryKey: ['users.list', payload, tab],
|
||||
queryFn: async () => getUsers(payload),
|
||||
meta: {
|
||||
apiErrorToastMessage: true,
|
||||
},
|
||||
});
|
||||
return usersListQueryResult;
|
||||
};
|
||||
export default useFilteredUsers;
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { Serialized } from '@rocket.chat/core-typings';
|
||||
import type { DefaultUserInfo, UsersListStatusParamsGET } from '@rocket.chat/rest-typings';
|
||||
import { useEndpoint } from '@rocket.chat/ui-contexts';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
const usePendingUsersCount = (users: Serialized<DefaultUserInfo[]> | undefined) => {
|
||||
const getUsers = useEndpoint('GET', '/v1/users.listByStatus');
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['pendingUsersCount', users],
|
||||
|
||||
queryFn: async () => {
|
||||
const payload: UsersListStatusParamsGET = {
|
||||
status: 'deactivated',
|
||||
inactiveReason: ['pending_approval'],
|
||||
type: 'user',
|
||||
count: 1,
|
||||
};
|
||||
|
||||
return getUsers(payload);
|
||||
},
|
||||
|
||||
enabled: !!users,
|
||||
select: (data) => data?.total,
|
||||
});
|
||||
};
|
||||
|
||||
export default usePendingUsersCount;
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import { useSetModal, usePermission, useEndpoint, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import type { AdminUserAction } from './useAdminUserInfoActions';
|
||||
|
||||
export const useResetE2EEKeyAction = (userId: IUser['_id']): AdminUserAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const setModal = useSetModal();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const canResetE2EEKey = usePermission('edit-other-user-e2ee');
|
||||
const resetE2EEKeyRequest = useEndpoint('POST', '/v1/users.resetE2EKey');
|
||||
|
||||
const resetE2EEKey = useCallback(async () => {
|
||||
try {
|
||||
await resetE2EEKeyRequest({ userId });
|
||||
dispatchToastMessage({ type: 'success', message: t('Users_key_has_been_reset') });
|
||||
} catch (error) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
} finally {
|
||||
setModal();
|
||||
}
|
||||
}, [resetE2EEKeyRequest, setModal, t, userId, dispatchToastMessage]);
|
||||
|
||||
const confirmResetE2EEKey = useCallback(() => {
|
||||
setModal(
|
||||
<GenericModal variant='danger' onConfirm={resetE2EEKey} onCancel={(): void => setModal()} confirmText={t('Reset')}>
|
||||
{t('E2E_Reset_Other_Key_Warning')}
|
||||
</GenericModal>,
|
||||
);
|
||||
}, [resetE2EEKey, t, setModal]);
|
||||
|
||||
return canResetE2EEKey
|
||||
? {
|
||||
icon: 'key',
|
||||
content: t('Reset_E2EE_password'),
|
||||
onClick: confirmResetE2EEKey,
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import { useSetModal, usePermission, useSetting, useEndpoint, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import type { AdminUserAction } from './useAdminUserInfoActions';
|
||||
|
||||
export const useResetTOTPAction = (userId: IUser['_id']): AdminUserAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const setModal = useSetModal();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const canResetTOTP = usePermission('edit-other-user-totp');
|
||||
const twoFactorEnabled = useSetting('Accounts_TwoFactorAuthentication_Enabled');
|
||||
const resetTOTPRequest = useEndpoint('POST', '/v1/users.resetTOTP');
|
||||
|
||||
const resetTOTP = useCallback(async () => {
|
||||
try {
|
||||
await resetTOTPRequest({ userId });
|
||||
dispatchToastMessage({ type: 'success', message: t('Users_TOTP_has_been_reset') });
|
||||
} catch (error) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
} finally {
|
||||
setModal();
|
||||
}
|
||||
}, [resetTOTPRequest, setModal, t, userId, dispatchToastMessage]);
|
||||
|
||||
const confirmResetTOTP = useCallback(() => {
|
||||
setModal(
|
||||
<GenericModal variant='danger' onConfirm={resetTOTP} onCancel={(): void => setModal()} confirmText={t('Reset')}>
|
||||
{t('TOTP_Reset_Other_Key_Warning')}
|
||||
</GenericModal>,
|
||||
);
|
||||
}, [resetTOTP, t, setModal]);
|
||||
|
||||
return canResetTOTP && twoFactorEnabled
|
||||
? {
|
||||
icon: 'key',
|
||||
content: t('Reset_TOTP'),
|
||||
onClick: confirmResetTOTP,
|
||||
}
|
||||
: undefined;
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
type UseSendInvitationEmailMutationVariables = {
|
||||
emails: string[];
|
||||
};
|
||||
|
||||
export const useSendInvitationEmailMutation = (): UseMutationResult<
|
||||
{ success: boolean },
|
||||
Error,
|
||||
UseSendInvitationEmailMutationVariables
|
||||
> => {
|
||||
const { t } = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const sendInvites = useEndpoint('POST', '/v1/sendInvitationEmail');
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ emails }) => {
|
||||
const result = await sendInvites({ emails });
|
||||
return result;
|
||||
},
|
||||
|
||||
onSuccess: () => dispatchToastMessage({ type: 'success', message: t('Sending_Invitations') }),
|
||||
onError: (error) => dispatchToastMessage({ type: 'error', message: error }),
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
type useSendWelcomeEmailMutationProps = {
|
||||
email: string | undefined;
|
||||
};
|
||||
|
||||
export const useSendWelcomeEmailMutation = (): UseMutationResult<null, Error, useSendWelcomeEmailMutationProps> => {
|
||||
const { t } = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const sendWelcomeEmail = useEndpoint('POST', '/v1/users.sendWelcomeEmail');
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ email }) => {
|
||||
if (!email) {
|
||||
dispatchToastMessage({ type: 'error', message: t('Welcome_email_failed') });
|
||||
return null;
|
||||
}
|
||||
|
||||
return sendWelcomeEmail({ email });
|
||||
},
|
||||
|
||||
onSuccess: () => dispatchToastMessage({ type: 'success', message: t('Welcome_email_resent') }),
|
||||
onError: (error) => dispatchToastMessage({ type: 'error', message: error }),
|
||||
});
|
||||
};
|
||||
10
apps/meteor/client/views/admin/users/hooks/useSmtpQuery.ts
Normal file
10
apps/meteor/client/views/admin/users/hooks/useSmtpQuery.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { useEndpoint } from '@rocket.chat/ui-contexts';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
export const useSmtpQuery = () => {
|
||||
const getSmtpConfig = useEndpoint('GET', '/v1/smtp.check');
|
||||
return useQuery({
|
||||
queryKey: ['smtp.check'],
|
||||
queryFn: async () => getSmtpConfig(),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user