Skip to content

Commit

Permalink
Merge pull request #34320 from rojiphil/34263-redirection-to-mr-report
Browse files Browse the repository at this point in the history
prevent offline navigation on money request report deletion
  • Loading branch information
blimpich authored Jan 17, 2024
2 parents 089f3e1 + c6017fc commit fe9e9e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3983,15 +3983,26 @@ function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Recor
return report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat;
}

/**
* Return true if the Money Request report is marked for deletion.
*/
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report>): boolean {
if (!isMoneyRequestReport(report)) {
return false;
}

const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

function canUserPerformWriteAction(report: OnyxEntry<Report>) {
const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);

// If the Money Request report is marked for deletion, let us prevent any further write action.
if (isMoneyRequestReport(report)) {
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
if (parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return false;
}
if (isMoneyRequestReportPendingDeletion(report)) {
return false;
}

return !isArchivedRoom(report) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser;
}

Expand Down Expand Up @@ -4567,6 +4578,7 @@ export {
getParentReport,
getRootParentReport,
getReportPreviewMessage,
isMoneyRequestReportPendingDeletion,
canUserPerformWriteAction,
getOriginalReportID,
canAccessReport,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ function ReportScreen({
Navigation.goBack(ROUTES.HOME, false, true);
}
if (prevReport.parentReportID) {
// Prevent navigation to the Money Request Report if it is pending deletion.
const parentReport = ReportUtils.getReport(prevReport.parentReportID);
if (ReportUtils.isMoneyRequestReportPendingDeletion(parentReport)) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
return;
}
Expand Down

0 comments on commit fe9e9e3

Please sign in to comment.