From 3d0b045c01d35b7759d2dcb72ea96a791c07fa6c Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 18 Oct 2023 10:53:51 -0600 Subject: [PATCH 1/4] Rename shouldDisableWriteActions to canUserPerformWriteAction --- src/libs/ReportUtils.js | 7 ++++--- src/libs/SidebarUtils.js | 2 +- src/pages/home/report/ReportActionsList.js | 2 +- src/pages/home/report/ReportFooter.js | 2 +- src/pages/iou/steps/NewRequestAmountPage.js | 2 +- src/pages/tasks/TaskShareDestinationSelectorModal.js | 2 +- tests/unit/OptionsListUtilsTest.js | 4 ++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 4e351d2dc5e3..7a376c59e6a3 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3386,7 +3386,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}; } @@ -3662,9 +3662,10 @@ 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; } /** @@ -4057,7 +4058,7 @@ export { getRootParentReport, getReportPreviewMessage, getModifiedExpenseMessage, - shouldDisableWriteActions, + canUserPerformWriteAction, getOriginalReportID, canAccessReport, getAddWorkspaceRoomOrChatReportErrors, diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index dd6db33902fb..9018ed1ddd80 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -305,7 +305,7 @@ function getOptionData(report, reportActions, personalDetails, preferredLocale, result.parentReportID = report.parentReportID || null; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = report.notificationPreference || null; - result.isAllowedToComment = !ReportUtils.shouldDisableWriteActions(report); + result.isAllowedToComment = !ReportUtils.canUserPerformWriteAction(report); const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; const subtitle = ReportUtils.getChatRoomSubtitle(report); diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index c673c06470f8..e986c7b53528 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -334,7 +334,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 renderFooter = useCallback(() => { diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index 2237e6448504..c96824770f07 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/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index ae319f5a73bb..dda52352e015 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -85,7 +85,7 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { // Check and dismiss modal useEffect(() => { - if (!ReportUtils.shouldDisableWriteActions(report)) { + if (!ReportUtils.canUserPerformWriteAction(report)) { return; } Navigation.dismissModal(reportID); diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.js b/src/pages/tasks/TaskShareDestinationSelectorModal.js index 2fc8f0eab014..f1cd009d197d 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 eda743f85aa2..0032f6a1ad42 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]; From 6b401e0e1d6631889f93e1fc1a16f19a068ba5e0 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 19 Oct 2023 08:11:06 -0600 Subject: [PATCH 2/4] Fix lint --- src/libs/ReportUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7a376c59e6a3..3b72e6829c39 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3664,7 +3664,6 @@ function getAddWorkspaceRoomOrChatReportErrors(report) { */ function canUserPerformWriteAction(report) { const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report); - return isArchivedRoom(report) || !_.isEmpty(reportErrors) || !isAllowedToComment(report) || isAnonymousUser; return !isArchivedRoom(report) && _.isEmpty(reportErrors) && isAllowedToComment(report) && !isAnonymousUser; } From cf90f7bd132d9562b80a09a6e027be38a8fd6d9a Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 19 Oct 2023 09:47:00 -0600 Subject: [PATCH 3/4] Negate logic for the referenced variable --- src/libs/SidebarUtils.js | 2 +- src/pages/home/report/ReportActionsList.js | 2 +- src/pages/home/report/ReportFooter.js | 2 +- src/pages/iou/steps/NewRequestAmountPage.js | 2 +- src/pages/tasks/TaskShareDestinationSelectorModal.js | 2 +- tests/unit/OptionsListUtilsTest.js | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 2c679ef3cda7..6eb07c6b19e0 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -305,7 +305,7 @@ function getOptionData(report, reportActions, personalDetails, preferredLocale, result.parentReportID = report.parentReportID || null; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = report.notificationPreference || null; - result.isAllowedToComment = !ReportUtils.canUserPerformWriteAction(report); + result.isAllowedToComment = ReportUtils.canUserPerformWriteAction(report); const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; const subtitle = ReportUtils.getChatRoomSubtitle(report); diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index e986c7b53528..32499ebc4090 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -334,7 +334,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.canUserPerformWriteAction(report); + const hideComposer = !ReportUtils.canUserPerformWriteAction(report); const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(personalDetailsList, report, currentUserPersonalDetails.accountID) && !isComposerFullSize; const renderFooter = useCallback(() => { diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index c96824770f07..754fae8d670a 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.canUserPerformWriteAction(props.report); + const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report); return ( <> diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index dda52352e015..c624973a0189 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -85,7 +85,7 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { // Check and dismiss modal useEffect(() => { - if (!ReportUtils.canUserPerformWriteAction(report)) { + if (ReportUtils.canUserPerformWriteAction(report)) { return; } Navigation.dismissModal(reportID); diff --git a/src/pages/tasks/TaskShareDestinationSelectorModal.js b/src/pages/tasks/TaskShareDestinationSelectorModal.js index f1cd009d197d..32e02e7ba42e 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.canUserPerformWriteAction(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 0032f6a1ad42..50edfa7f0522 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.canUserPerformWriteAction(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.canUserPerformWriteAction(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]; From 51fa6ed5dfc99e76f3132f9fe2833e4e05d81f88 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 24 Oct 2023 08:34:33 -0600 Subject: [PATCH 4/4] Rename a missed spot --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d49af6c84074..93f456b22ed5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -3730,7 +3730,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);