diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0e9091fd6cb2..9d58b3468910 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3526,7 +3526,7 @@ function parseReportRouteParams(route) { parsingRoute = parsingRoute.slice(1); } - if (!parsingRoute.startsWith(Url.addTrailingForwardSlash('r'))) { + if (!parsingRoute.startsWith(Url.addTrailingForwardSlash(ROUTES.REPORT))) { return {reportID: '', isSubReportPageRoute: false}; } @@ -3810,9 +3810,9 @@ function getAddWorkspaceRoomOrChatReportErrors(report) { * @param {Object} report * @returns {Boolean} */ -function shouldDisableWriteActions(report) { +function canUserPerformWriteAction(report) { const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report); - return isArchivedRoom(report) || !_.isEmpty(reportErrors) || !isAllowedToComment(report) || isAnonymousUser; + return !isArchivedRoom(report) && _.isEmpty(reportErrors) && isAllowedToComment(report) && !isAnonymousUser; } /** @@ -3866,7 +3866,7 @@ function getPolicyExpenseChatReportIDByOwner(policyOwner) { */ function canCreateRequest(report, betas, iouType) { const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []); - if (shouldDisableWriteActions(report)) { + if (!canUserPerformWriteAction(report)) { return false; } return getMoneyRequestOptions(report, participantAccountIDs, betas).includes(iouType); @@ -4249,7 +4249,7 @@ export { getRootParentReport, getReportPreviewMessage, getModifiedExpenseMessage, - shouldDisableWriteActions, + canUserPerformWriteAction, getOriginalReportID, canAccessReport, getAddWorkspaceRoomOrChatReportErrors, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 79d3280e859e..a0b676bdffff 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -385,7 +385,7 @@ function getOptionData( result.parentReportID = report.parentReportID ?? null; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = report.notificationPreference ?? null; - result.isAllowedToComment = !ReportUtils.shouldDisableWriteActions(report); + result.isAllowedToComment = ReportUtils.canUserPerformWriteAction(report); result.chatType = report.chatType; const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 8fa40a96bd6b..ebcd90281354 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -354,7 +354,7 @@ function ReportActionsList({ // Native mobile does not render updates flatlist the changes even though component did update called. // To notify there something changes we can use extraData prop to flatlist const extraData = [isSmallScreenWidth ? currentUnreadMarker : undefined, ReportUtils.isArchivedRoom(report)]; - const hideComposer = ReportUtils.shouldDisableWriteActions(report); + const hideComposer = !ReportUtils.canUserPerformWriteAction(report); const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(personalDetailsList, report, currentUserPersonalDetails.accountID) && !isComposerFullSize; const contentContainerStyle = useMemo( diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index f3598a92a9eb..00d586b67697 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -70,7 +70,7 @@ function ReportFooter(props) { const isAnonymousUser = Session.isAnonymousUser(); const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint; - const hideComposer = ReportUtils.shouldDisableWriteActions(props.report); + const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report); return ( <> diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.js b/src/pages/tasks/TaskShareDestinationSelectorModal.js index fde02c2a4108..085d9a5a96b7 100644 --- a/src/pages/tasks/TaskShareDestinationSelectorModal.js +++ b/src/pages/tasks/TaskShareDestinationSelectorModal.js @@ -52,7 +52,7 @@ function TaskShareDestinationSelectorModal(props) { const reports = {}; _.keys(props.reports).forEach((reportKey) => { if ( - ReportUtils.shouldDisableWriteActions(props.reports[reportKey]) || + !ReportUtils.canUserPerformWriteAction(props.reports[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) || ReportUtils.isCanceledTaskReport(props.reports[reportKey]) ) { diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 5d18608a3de4..77e639ad1106 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -590,7 +590,7 @@ describe('OptionsListUtils', () => { // Filter current REPORTS as we do in the component, before getting share destination options const filteredReports = {}; _.keys(REPORTS).forEach((reportKey) => { - if (ReportUtils.shouldDisableWriteActions(REPORTS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS[reportKey])) { + if (!ReportUtils.canUserPerformWriteAction(REPORTS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS[reportKey])) { return; } filteredReports[reportKey] = REPORTS[reportKey]; @@ -617,7 +617,7 @@ describe('OptionsListUtils', () => { // Filter current REPORTS_WITH_WORKSPACE_ROOMS as we do in the component, before getting share destination options const filteredReportsWithWorkspaceRooms = {}; _.keys(REPORTS_WITH_WORKSPACE_ROOMS).forEach((reportKey) => { - if (ReportUtils.shouldDisableWriteActions(REPORTS_WITH_WORKSPACE_ROOMS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS_WITH_WORKSPACE_ROOMS[reportKey])) { + if (!ReportUtils.canUserPerformWriteAction(REPORTS_WITH_WORKSPACE_ROOMS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS_WITH_WORKSPACE_ROOMS[reportKey])) { return; } filteredReportsWithWorkspaceRooms[reportKey] = REPORTS_WITH_WORKSPACE_ROOMS[reportKey];