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);
|
||||
};
|
||||
Reference in New Issue
Block a user