diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 07bc99fa8314..82b3010b1434 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7869,11 +7869,9 @@ function isIOUOwnedByCurrentUser(report: OnyxEntry, allReportsDict?: Ony * Assuming the passed in report is a default room, lets us know whether we can see it or not, based on permissions and * the various subsets of users we've allowed to use default rooms. */ -function canSeeDefaultRoom(report: OnyxEntry, betas: OnyxEntry): boolean { +function canSeeDefaultRoom(report: OnyxEntry, betas: OnyxEntry, isReportArchived = false): boolean { // Include archived rooms - // This will get removed as part of https://github.com/Expensify/App/issues/59961 - // eslint-disable-next-line deprecation/deprecation - if (isArchivedNonExpenseReport(report, !!getReportNameValuePairs(report?.reportID)?.private_isArchived)) { + if (isArchivedNonExpenseReport(report, isReportArchived)) { return true; } @@ -7891,9 +7889,9 @@ function canSeeDefaultRoom(report: OnyxEntry, betas: OnyxEntry): return Permissions.isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS, betas ?? []); } -function canAccessReport(report: OnyxEntry, betas: OnyxEntry): boolean { +function canAccessReport(report: OnyxEntry, betas: OnyxEntry, isReportArchived = false): boolean { // We hide default rooms (it's basically just domain rooms now) from people who aren't on the defaultRooms beta. - if (isDefaultRoom(report) && !canSeeDefaultRoom(report, betas)) { + if (isDefaultRoom(report) && !canSeeDefaultRoom(report, betas, isReportArchived)) { return false; } @@ -8204,7 +8202,7 @@ function reasonForReportToBeInOptionList({ return null; } - if (!canAccessReport(report, betas)) { + if (!canAccessReport(report, betas, isReportArchived)) { return null; } @@ -9296,8 +9294,8 @@ function isReportParticipant(accountID: number | undefined, report: OnyxEntry): boolean { - return (isReportParticipant(currentUserAccountID, report) || isPublicRoom(report)) && canAccessReport(report, allBetas); +function canCurrentUserOpenReport(report: OnyxEntry, isReportArchived = false): boolean { + return (isReportParticipant(currentUserAccountID, report) || isPublicRoom(report)) && canAccessReport(report, allBetas, isReportArchived); } function shouldUseFullTitleToDisplay(report: OnyxEntry): boolean { diff --git a/src/pages/home/report/ReportActionItemParentAction.tsx b/src/pages/home/report/ReportActionItemParentAction.tsx index 76df12c156cc..eb0468d65907 100644 --- a/src/pages/home/report/ReportActionItemParentAction.tsx +++ b/src/pages/home/report/ReportActionItemParentAction.tsx @@ -3,6 +3,7 @@ import {View} from 'react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import useNetwork from '@hooks/useNetwork'; +import useOnyx from '@hooks/useOnyx'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import onyxSubscribe from '@libs/onyxSubscribe'; @@ -13,6 +14,7 @@ import { canUserPerformWriteAction as canUserPerformWriteActionReportUtils, getAllAncestorReportActionIDs, getAllAncestorReportActions, + isArchivedReport, navigateToLinkedReportAction, } from '@libs/ReportUtils'; import {navigateToConciergeChatAndDeleteReport} from '@userActions/Report'; @@ -81,6 +83,19 @@ function ReportActionItemParentAction({ const [allAncestors, setAllAncestors] = useState([]); const {isOffline} = useNetwork(); const {isInNarrowPaneModal} = useResponsiveLayout(); + const [ancestorReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, { + canBeMissing: true, + selector: (allPairs) => { + const ancestorIDsToSelect = new Set(ancestorIDs.current.reportIDs); + + return Object.fromEntries( + Object.entries(allPairs ?? {}).filter(([key]) => { + const id = key.split('_').at(1); + return id && ancestorIDsToSelect.has(id); + }), + ); + }, + }); useEffect(() => { const unsubscribeReports: Array<() => void> = []; @@ -124,7 +139,9 @@ function ReportActionItemParentAction({ const ancestorReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${ancestor.report.reportID}`]; const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(ancestorReport); const shouldDisplayThreadDivider = !isTripPreview(ancestor.reportAction); - + const reportNameValuePair = + ancestorReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${ancestorReports.current?.[ancestor?.report?.reportID]?.reportID}`]; + const isAncestorReportArchived = isArchivedReport(reportNameValuePair); return ( )} navigateToLinkedReportAction(ancestor, isInNarrowPaneModal, canUserPerformWriteAction, isOffline) : undefined } diff --git a/src/pages/home/report/withReportAndReportActionOrNotFound.tsx b/src/pages/home/report/withReportAndReportActionOrNotFound.tsx index 69c24c392a79..a28699fa7b2e 100644 --- a/src/pages/home/report/withReportAndReportActionOrNotFound.tsx +++ b/src/pages/home/report/withReportAndReportActionOrNotFound.tsx @@ -4,6 +4,7 @@ import React, {useEffect, useMemo} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import useOnyx from '@hooks/useOnyx'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import {openReport} from '@libs/actions/Report'; import getComponentDisplayName from '@libs/getComponentDisplayName'; @@ -83,7 +84,8 @@ export default function { expect(getReportStatusTranslation(undefined, CONST.REPORT.STATUS_NUM.OPEN)).toBe(''); }); }); + describe('canSeeDefaultRoom', () => { + it('should return true if report is archived room ', () => { + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + const report: Report = { + ...createRandomReport(40002), + type: CONST.REPORT.TYPE.CHAT, + participants: buildParticipantsFromAccountIDs([currentUserAccountID, 1]), + }; + expect(canSeeDefaultRoom(report, betas, true)).toBe(true); + }); + it('should return true if the room has an assigned guide', () => { + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + const report: Report = { + ...createRandomReport(40002), + participants: buildParticipantsFromAccountIDs([currentUserAccountID, 8]), + }; + Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails).then(() => { + expect(canSeeDefaultRoom(report, betas, false)).toBe(true); + }); + }); + it('should return true if the report is admin room', () => { + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + const report: Report = { + ...createRandomReport(40002), + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + }; + Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails).then(() => { + expect(canSeeDefaultRoom(report, betas, false)).toBe(true); + }); + }); + }); });