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

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { usePermission } from '@rocket.chat/ui-contexts';
export type ABACTab = 'settings' | 'room-attributes' | 'rooms' | 'logs';
export const ABAC_TAB_ORDER: ABACTab[] = ['settings', 'room-attributes', 'rooms', 'logs'];
export const useABACTabPermissions = (): Record<ABACTab, boolean> => {
return {
'settings': usePermission('manage-abac-admin-settings'),
'room-attributes': usePermission('manage-abac-admin-room-attributes'),
'rooms': usePermission('manage-abac-admin-rooms'),
'logs': usePermission('view-abac-admin-audit'),
};
};

View File

@@ -0,0 +1,41 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useIsABACAvailable } from './useIsABACAvailable';
import { ABACQueryKeys } from '../../../../lib/queryKeys';
const COUNT = 150;
const ATTRIBUTE_LIST_STALE_TIME = 15_000;
export const useAttributeList = () => {
const attributesAutoCompleteEndpoint = useEndpoint('GET', '/v1/abac/attributes');
const isABACAvailable = useIsABACAvailable();
return useQuery({
enabled: isABACAvailable,
staleTime: ATTRIBUTE_LIST_STALE_TIME,
queryKey: ABACQueryKeys.roomAttributes.list(),
queryFn: async () => {
const firstPage = await attributesAutoCompleteEndpoint({ offset: 0, count: COUNT });
const { attributes: firstPageAttributes, total } = firstPage;
let currentPage = COUNT;
const pages = [];
while (currentPage < total) {
pages.push(attributesAutoCompleteEndpoint({ offset: currentPage, count: COUNT }));
currentPage += COUNT;
}
const remainingPages = await Promise.all(pages);
return {
attributes: [...firstPageAttributes, ...remainingPages.flatMap((page) => page.attributes)].map((attribute) => ({
_id: attribute._id,
label: attribute.key,
value: attribute.key,
attributeValues: attribute.values,
})),
};
},
});
};

View File

@@ -0,0 +1,267 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook, waitFor } from '@testing-library/react';
import { useAttributeOptions } from './useAttributeOptions';
import { createFakeLicenseInfo } from '../../../../../tests/mocks/data';
const mockNavigate = jest.fn();
const mockSetModal = jest.fn();
const mockDispatchToastMessage = jest.fn();
const useIsABACAvailableMock = jest.fn(() => true);
jest.mock('./useIsABACAvailable', () => ({
useIsABACAvailable: () => useIsABACAvailableMock(),
}));
jest.mock('@rocket.chat/ui-contexts', () => ({
...jest.requireActual('@rocket.chat/ui-contexts'),
useRouter: () => ({
navigate: mockNavigate,
}),
useSetModal: () => mockSetModal,
useToastMessageDispatch: () => mockDispatchToastMessage,
}));
const mockAttribute = {
_id: 'attribute-1',
key: 'Room Type',
};
const baseAppRoot = mockAppRoot()
.withTranslations('en', 'core', {
Edit: 'Edit',
Delete: 'Delete',
ABAC_Attribute_deleted: 'Attribute {{attributeName}} deleted',
ABAC_Cannot_delete_attribute: 'Cannot delete attribute',
ABAC_Cannot_delete_attribute_content:
'The attribute <bold>{{attributeName}}</bold> is currently in use and cannot be deleted. Please remove it from all rooms before deleting.',
ABAC_Delete_room_attribute: 'Delete room attribute',
ABAC_Delete_room_attribute_content:
'Are you sure you want to delete the attribute <bold>{{attributeName}}</bold>? This action cannot be undone.',
View_rooms: 'View rooms',
Cancel: 'Cancel',
})
.withSetting('ABAC_Enabled', true, {
packageValue: false,
blocked: false,
public: true,
type: 'boolean',
i18nLabel: 'ABAC_Enabled',
i18nDescription: 'ABAC_Enabled_Description',
})
.withEndpoint('GET', '/v1/licenses.info', async () => ({
license: createFakeLicenseInfo({ activeModules: ['abac'] }),
}));
describe('useAttributeOptions', () => {
beforeEach(() => {
jest.clearAllMocks();
mockNavigate.mockClear();
mockSetModal.mockClear();
mockDispatchToastMessage.mockClear();
});
it('should return menu items with correct structure', () => {
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', async () => null)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
expect(result.current).toHaveLength(2);
expect(result.current[0]).toMatchObject({
id: 'edit',
icon: 'edit',
content: 'Edit',
});
expect(result.current[1]).toMatchObject({
id: 'delete',
icon: 'trash',
iconColor: 'danger',
});
});
it('should enable edit when ABAC is available', async () => {
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', async () => null)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
await waitFor(() => {
expect(result.current[0].disabled).toBe(false);
});
});
it('should navigate to edit page when edit action is clicked', async () => {
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', async () => null)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
const editAction = result.current[0].onClick;
if (editAction) {
editAction();
}
expect(mockNavigate).toHaveBeenCalledWith(
{
name: 'admin-ABAC',
params: {
tab: 'room-attributes',
context: 'edit',
id: mockAttribute._id,
},
},
{ replace: true },
);
});
it('should disable edit when ABAC is not available', () => {
useIsABACAvailableMock.mockReturnValue(false);
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withSetting('ABAC_Enabled', false, {
packageValue: false,
blocked: false,
public: true,
type: 'boolean',
i18nLabel: 'ABAC_Enabled',
i18nDescription: 'ABAC_Enabled_Description',
})
.withEndpoint('GET', '/v1/licenses.info', async () => ({
license: createFakeLicenseInfo({ activeModules: [] }),
}))
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', async () => null)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
expect(result.current[0].disabled).toBe(true);
});
it('should show warning modal when delete is clicked and attribute is in use', async () => {
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', async () => null)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: true }))
.build(),
});
const deleteAction = result.current[1].onClick;
if (deleteAction) {
deleteAction();
}
await waitFor(() => {
expect(mockSetModal).toHaveBeenCalled();
});
const modalCall = mockSetModal.mock.calls[0][0];
expect(modalCall.props.variant).toBe('warning');
expect(modalCall.props.title).toBe('Cannot delete attribute');
});
it('should show delete confirmation modal when delete is clicked and attribute is not in use', async () => {
const deleteEndpointMock = jest.fn().mockResolvedValue(null);
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', deleteEndpointMock)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
const deleteAction = result.current[1].onClick;
if (deleteAction) {
deleteAction();
}
await waitFor(() => {
expect(mockSetModal).toHaveBeenCalled();
});
const modalCall = mockSetModal.mock.calls[0][0];
expect(modalCall.props.variant).toBe('danger');
expect(modalCall.props.title).toBe('Delete room attribute');
expect(modalCall.props.confirmText).toBe('Delete');
});
it('should call delete endpoint when delete is confirmed', async () => {
const deleteEndpointMock = jest.fn().mockResolvedValue(null);
let confirmHandler: (() => void) | undefined;
mockSetModal.mockImplementation((modal) => {
if (modal?.props?.onConfirm) {
confirmHandler = modal.props.onConfirm;
}
});
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', deleteEndpointMock)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
const deleteAction = result.current[1].onClick;
if (deleteAction) {
deleteAction();
}
await waitFor(() => {
expect(mockSetModal).toHaveBeenCalled();
});
if (confirmHandler) {
confirmHandler();
}
await waitFor(() => {
expect(deleteEndpointMock).toHaveBeenCalled();
});
});
it('should show success toast when delete succeeds', async () => {
const deleteEndpointMock = jest.fn().mockResolvedValue(null);
let confirmHandler: (() => void) | undefined;
mockSetModal.mockImplementation((modal) => {
if (modal?.props?.onConfirm) {
confirmHandler = modal.props.onConfirm;
}
});
const { result } = renderHook(() => useAttributeOptions(mockAttribute), {
wrapper: baseAppRoot
.withEndpoint('DELETE', '/v1/abac/attributes/:_id', deleteEndpointMock)
.withEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', async () => ({ inUse: false }))
.build(),
});
const deleteAction = result.current[1].onClick;
if (deleteAction) {
deleteAction();
}
await waitFor(() => {
expect(mockSetModal).toHaveBeenCalled();
});
if (confirmHandler) {
confirmHandler();
}
await waitFor(() => {
expect(mockDispatchToastMessage).toHaveBeenCalledWith({
type: 'success',
message: 'Attribute Room Type deleted',
});
});
});
});

View File

@@ -0,0 +1,105 @@
import { Box } from '@rocket.chat/fuselage';
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
import type { GenericMenuItemProps } from '@rocket.chat/ui-client';
import { GenericModal } from '@rocket.chat/ui-client';
import { useRouter, useSetModal, useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Trans, useTranslation } from 'react-i18next';
import { useIsABACAvailable } from './useIsABACAvailable';
import { useViewRoomsAction } from './useViewRoomsAction';
import { ABACQueryKeys } from '../../../../lib/queryKeys';
export const useAttributeOptions = (attribute: { _id: string; key: string }): GenericMenuItemProps[] => {
const { t } = useTranslation();
const router = useRouter();
const setModal = useSetModal();
const queryClient = useQueryClient();
const deleteAttribute = useEndpoint('DELETE', '/v1/abac/attributes/:_id', { _id: attribute._id });
const isAttributeUsed = useEndpoint('GET', '/v1/abac/attributes/:key/is-in-use', { key: attribute.key });
const dispatchToastMessage = useToastMessageDispatch();
const isABACAvailable = useIsABACAvailable();
const viewRoomsAction = useViewRoomsAction();
const editAction = useStableCallback(() => {
return router.navigate(
{
name: 'admin-ABAC',
params: {
tab: 'room-attributes',
context: 'edit',
id: attribute._id,
},
},
{ replace: true },
);
});
const deleteMutation = useMutation({
mutationFn: deleteAttribute,
onSuccess: () => {
dispatchToastMessage({ type: 'success', message: t('ABAC_Attribute_deleted', { attributeName: attribute.key }) });
},
onError: (error) => {
dispatchToastMessage({ type: 'error', message: error });
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ABACQueryKeys.roomAttributes.all() });
setModal(null);
},
});
const deleteAction = useStableCallback(async () => {
const isUsed = await isAttributeUsed();
if (isUsed.inUse) {
return setModal(
<GenericModal
variant='warning'
icon={null}
title={t('ABAC_Cannot_delete_attribute')}
confirmText={t('View_rooms')}
onConfirm={() => {
viewRoomsAction(attribute.key);
setModal(null);
}}
onCancel={() => setModal(null)}
>
<Trans
i18nKey='ABAC_Cannot_delete_attribute_content'
values={{ attributeName: attribute.key }}
components={{ bold: <Box is='span' fontWeight='bold' /> }}
/>
</GenericModal>,
);
}
setModal(
<GenericModal
variant='danger'
icon={null}
title={t('ABAC_Delete_room_attribute')}
confirmText={t('Delete')}
onConfirm={() => {
deleteMutation.mutateAsync(undefined);
}}
onCancel={() => setModal(null)}
>
<Trans
i18nKey='ABAC_Delete_room_attribute_content'
values={{ attributeName: attribute.key }}
components={{ bold: <Box is='span' fontWeight='bold' /> }}
/>
</GenericModal>,
);
});
return [
{ id: 'edit', icon: 'edit' as const, content: t('Edit'), onClick: () => editAction(), disabled: !isABACAvailable },
{
id: 'delete',
iconColor: 'danger',
icon: 'trash' as const,
content: <Box color='danger'>{t('Delete')}</Box>,
onClick: () => deleteAction(),
},
];
};

View File

@@ -0,0 +1,52 @@
import { faker } from '@faker-js/faker';
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook, waitFor } from '@testing-library/react';
import { useDeleteRoomModal } from './useDeleteRoomModal';
const mockSetModal = jest.fn();
jest.mock('@rocket.chat/ui-contexts', () => {
const originalModule = jest.requireActual('@rocket.chat/ui-contexts');
return {
...originalModule,
useSetModal: () => mockSetModal,
};
});
describe('useDeleteRoomModal', () => {
beforeEach(() => {
jest.clearAllMocks();
mockSetModal.mockClear();
});
it('should show delete confirmation modal when hook is called', async () => {
const { result } = renderHook(
() =>
useDeleteRoomModal({
rid: faker.database.mongodbObjectId(),
name: faker.lorem.words(3),
}),
{
wrapper: mockAppRoot()
.withTranslations('en', 'core', {
Edit: 'Edit',
Remove: 'Remove',
ABAC_Room_removed: 'Room {{roomName}} removed from ABAC management',
ABAC_Delete_room: 'Remove room from ABAC management',
ABAC_Delete_room_annotation: 'Proceed with caution',
ABAC_Delete_room_content:
'Removing <bold>{{roomName}}</bold> from ABAC management may result in unintended users gaining access.',
Cancel: 'Cancel',
})
.build(),
},
);
result.current();
await waitFor(() => {
expect(mockSetModal).toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,11 @@
import { useSetModal } from '@rocket.chat/ui-contexts';
import DeleteRoomModal from '../ABACRoomsTab/DeleteRoomModal';
export const useDeleteRoomModal = (room: { rid: string; name: string }) => {
const setModal = useSetModal();
return () => {
setModal(<DeleteRoomModal rid={room.rid} roomName={room.name} onClose={() => setModal(null)} />);
};
};

View File

@@ -0,0 +1,10 @@
import { useSetting } from '@rocket.chat/ui-contexts';
import { useHasLicenseModule } from '../../../../hooks/useHasLicenseModule';
export const useIsABACAvailable = () => {
const { data: hasABAC = false } = useHasLicenseModule('abac');
const isABACSettingEnabled = useSetting('ABAC_Enabled', false);
return hasABAC && isABACSettingEnabled;
};

View File

@@ -0,0 +1,9 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { isABACManagedRoom } from '@rocket.chat/core-typings';
import { useIsABACAvailable } from './useIsABACAvailable';
export const useIsABACManagedRoom = (room: Partial<IRoom>): boolean => {
const isABACAvailable = useIsABACAvailable();
return isABACAvailable && isABACManagedRoom(room);
};

View File

@@ -0,0 +1,8 @@
import { useSetting } from '@rocket.chat/ui-contexts';
export const useIsExternalAttributeStore = (): boolean => {
const pdpType = useSetting('ABAC_PDP_Type', 'local');
const attributeStore = useSetting('ABAC_Attribute_Store', 'local');
return pdpType !== 'local' && attributeStore !== 'local';
};

View File

@@ -0,0 +1,124 @@
import { faker } from '@faker-js/faker';
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook, waitFor } from '@testing-library/react';
import { useRoomItems } from './useRoomItems';
const navigateMock = jest.fn();
const setDeleteRoomModalMock = jest.fn();
const useIsABACAvailableMock = jest.fn(() => true);
jest.mock('./useIsABACAvailable', () => ({
useIsABACAvailable: () => useIsABACAvailableMock(),
}));
jest.mock('./useDeleteRoomModal', () => ({
useDeleteRoomModal: () => setDeleteRoomModalMock,
}));
jest.mock('@rocket.chat/ui-contexts', () => ({
...jest.requireActual('@rocket.chat/ui-contexts'),
useRouter: () => ({
navigate: navigateMock,
}),
}));
const mockRoom = {
rid: faker.database.mongodbObjectId(),
name: 'Test Room',
};
const createAppRoot = () =>
mockAppRoot()
.withTranslations('en', 'core', {
Edit: 'Edit',
Remove: 'Remove',
ABAC_Room_removed: 'Room {{roomName}} removed from ABAC management',
ABAC_Delete_room: 'Remove room from ABAC management',
ABAC_Delete_room_annotation: 'Proceed with caution',
ABAC_Delete_room_content: 'Removing <bold>{{roomName}}</bold> from ABAC management may result in unintended users gaining access.',
Cancel: 'Cancel',
})
.withEndpoint('DELETE', '/v1/abac/rooms/:rid/attributes', async () => null);
describe('useRoomItems', () => {
beforeEach(() => {
jest.clearAllMocks();
navigateMock.mockClear();
useIsABACAvailableMock.mockReturnValue(true);
});
it('should return menu items with correct structure', () => {
const { result } = renderHook(() => useRoomItems(mockRoom), {
wrapper: createAppRoot().build(),
});
expect(result.current).toHaveLength(2);
expect(result.current[0]).toMatchObject({
id: 'edit',
icon: 'edit',
content: 'Edit',
});
expect(result.current[1]).toMatchObject({
id: 'delete',
icon: 'cross',
iconColor: 'danger',
});
});
it('should enable edit when ABAC is available', async () => {
const { result } = renderHook(() => useRoomItems(mockRoom), {
wrapper: createAppRoot().build(),
});
await waitFor(() => {
expect(result.current[0].disabled).toBe(false);
});
});
it('should navigate to edit page when edit action is clicked', async () => {
const { result } = renderHook(() => useRoomItems(mockRoom), {
wrapper: createAppRoot().build(),
});
const editAction = result.current[0].onClick;
if (editAction) {
editAction();
}
expect(navigateMock).toHaveBeenCalledWith(
{
name: 'admin-ABAC',
params: {
tab: 'rooms',
context: 'edit',
id: mockRoom.rid,
},
},
{ replace: true },
);
});
it('should disable edit when ABAC is not available', () => {
useIsABACAvailableMock.mockReturnValue(false);
const { result } = renderHook(() => useRoomItems(mockRoom), {
wrapper: createAppRoot().build(),
});
expect(result.current[0].disabled).toBe(true);
});
it('should show delete modal when delete is clicked', async () => {
const { result } = renderHook(() => useRoomItems(mockRoom), {
wrapper: createAppRoot().build(),
});
const deleteAction = result.current[1].onClick;
if (deleteAction) {
deleteAction();
}
await waitFor(() => {
expect(setDeleteRoomModalMock).toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,40 @@
import { Box } from '@rocket.chat/fuselage';
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
import type { GenericMenuItemProps } from '@rocket.chat/ui-client';
import { useRouter } from '@rocket.chat/ui-contexts';
import { useTranslation } from 'react-i18next';
import { useDeleteRoomModal } from './useDeleteRoomModal';
import { useIsABACAvailable } from './useIsABACAvailable';
export const useRoomItems = (room: { rid: string; name: string }): GenericMenuItemProps[] => {
const { t } = useTranslation();
const router = useRouter();
const setDeleteRoomModal = useDeleteRoomModal(room);
const isABACAvailable = useIsABACAvailable();
const editAction = useStableCallback(() => {
return router.navigate(
{
name: 'admin-ABAC',
params: {
tab: 'rooms',
context: 'edit',
id: room.rid,
},
},
{ replace: true },
);
});
return [
{ id: 'edit', icon: 'edit' as const, content: t('Edit'), onClick: () => editAction(), disabled: isABACAvailable !== true },
{
id: 'delete',
iconColor: 'danger',
icon: 'cross' as const,
content: <Box color='danger'>{t('Remove')}</Box>,
onClick: setDeleteRoomModal,
},
];
};

View File

@@ -0,0 +1,23 @@
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
import { useRouter } from '@rocket.chat/ui-contexts';
export const useViewRoomsAction = () => {
const router = useRouter();
return useStableCallback((key: string) => {
return router.navigate(
{
name: 'admin-ABAC',
params: {
tab: 'rooms',
context: '',
id: '',
},
search: {
searchTerm: key,
type: 'attribute',
},
},
{ replace: true },
);
});
};