From 6b41cdec96ff1cfb8ce8a59791f8000027def43c Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 23 Apr 2024 17:10:22 +0200 Subject: [PATCH] restrict actions for read-only chats --- .../home/report/ContextMenu/ContextMenuActions.tsx | 12 ++++++++++++ src/pages/home/report/ReportActionItem.tsx | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index eb1e60461005..5638e08d3b34 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -513,5 +513,17 @@ const ContextMenuActions: ContextMenuAction[] = [ }, ]; +const restrictedReadOnlyActions = [ + 'common.download', + 'reportActionContextMenu.replyInThread', + 'reportActionContextMenu.editAction', + 'reportActionContextMenu.joinThread', + 'reportActionContextMenu.deleteAction', +]; + +// @ts-expect-error Not all actions have textTranslateKey +const RestrictedReadOnlyContextMenuActions: ContextMenuAction[] = ContextMenuActions.filter((action) => restrictedReadOnlyActions.includes(action.textTranslateKey)); + +export {RestrictedReadOnlyContextMenuActions}; export default ContextMenuActions; export type {ContextMenuActionPayload, ContextMenuAction}; diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index c07b693001e0..b2dc4550f8fd 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -66,6 +66,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {OriginalMessageActionableMentionWhisper, OriginalMessageActionableTrackedExpenseWhisper, OriginalMessageJoinPolicyChangeLog} from '@src/types/onyx/OriginalMessage'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground'; +import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions'; import MiniReportActionContextMenu from './ContextMenu/MiniReportActionContextMenu'; import * as ReportActionContextMenu from './ContextMenu/ReportActionContextMenu'; import {hideContextMenu} from './ContextMenu/ReportActionContextMenu'; @@ -914,6 +915,7 @@ function ReportActionItem({ originalReportID={originalReportID ?? ''} isArchivedRoom={ReportUtils.isArchivedRoom(report)} displayAsGroup={displayAsGroup} + disabledActions={ReportUtils.isReadOnly(report) ? RestrictedReadOnlyContextMenuActions : []} isVisible={hovered && draftMessage === undefined && !hasErrors} draftMessage={draftMessage} isChronosReport={ReportUtils.chatIncludesChronos(originalReport)}