diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 514dc71ffe2c..bc2c36534288 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -116,7 +116,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); const isCancelled = moneyRequestReport && moneyRequestReport.isCancelledIOU; const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction); - const canEditAmount = canEdit && !isSettled && !isCardTransaction; + const canEditAmount = ReportUtils.canEditMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.AMOUNT, transaction) && !isSettled && !isCardTransaction; const canEditReceipt = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, moneyRequestReport.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT); // A flag for verifying that the current report is a sub-report of a workspace chat diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6a4914f44121..f1830408593d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1812,7 +1812,7 @@ function getTransactionDetails(transaction: OnyxEntry, createdDateF * - the current user is the requestor and is not settled yet * - or the user is an admin on the policy the expense report is tied to */ -function canEditMoneyRequest(reportAction: OnyxEntry, fieldToEdit = ''): boolean { +function canEditMoneyRequest(reportAction: OnyxEntry, fieldToEdit = '', transaction?: OnyxEntry): boolean { const isDeleted = ReportActionsUtils.isDeletedAction(reportAction); if (isDeleted) { @@ -1839,11 +1839,14 @@ function canEditMoneyRequest(reportAction: OnyxEntry, fieldToEdit const isApproved = isReportApproved(moneyRequestReport); const isAdmin = isExpenseReport(moneyRequestReport) && (getPolicy(moneyRequestReport?.policyID ?? '')?.role ?? '') === CONST.POLICY.ROLE.ADMIN; const isRequestor = currentUserAccountID === reportAction?.actorAccountID; + const isDistanceRequest = !isEmpty(transaction) && TransactionUtils.isDistanceRequest(transaction); if (isAdmin && !isRequestor && fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT) { return false; } - + if (isDistanceRequest && fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT) { + return isAdmin; + } if (isAdmin) { return true; } @@ -1855,7 +1858,12 @@ function canEditMoneyRequest(reportAction: OnyxEntry, fieldToEdit * Checks if the current user can edit the provided property of a money request * */ -function canEditFieldOfMoneyRequest(reportAction: OnyxEntry, reportID: string, fieldToEdit: ValueOf): boolean { +function canEditFieldOfMoneyRequest( + reportAction: OnyxEntry, + reportID: string, + fieldToEdit: ValueOf, + transaction: OnyxEntry, +): boolean { // A list of fields that cannot be edited by anyone, once a money request has been settled const nonEditableFieldsWhenSettled: string[] = [ CONST.EDIT_REQUEST_FIELD.AMOUNT, @@ -1866,7 +1874,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxEntry, repor ]; // Checks if this user has permissions to edit this money request - if (!canEditMoneyRequest(reportAction, fieldToEdit)) { + if (!canEditMoneyRequest(reportAction, fieldToEdit, transaction)) { return false; // User doesn't have permission to edit } diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index fe2d28b6c0ef..e41f30779f22 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -104,7 +104,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT // Decides whether to allow or disallow editing a money request useEffect(() => { // Do not dismiss the modal, when a current user can edit this property of the money request. - if (ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, parentReport.reportID, fieldToEdit)) { + if (ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, parentReport.reportID, fieldToEdit, transaction)) { return; } @@ -112,7 +112,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT Navigation.isNavigationReady().then(() => { Navigation.dismissModal(); }); - }, [parentReportAction, parentReport.reportID, fieldToEdit]); + }, [parentReportAction, parentReport.reportID, fieldToEdit, transaction]); // Update the transaction object and close the modal function editMoneyRequest(transactionChanges) {