From a476cdd10f7b2da50d3410bdbbc207e823b074a8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 14 Aug 2024 10:03:54 +0700 Subject: [PATCH 1/4] fix: Submit expense option is not disabled for users who are invited to expense report --- src/libs/ReportUtils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c5a42de9e1e..268aa83f0a8a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1660,6 +1660,14 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } + if (isIOUReport(moneyRequestReport) && currentUserAccountID !== moneyRequestReport?.managerID && currentUserAccountID !== moneyRequestReport?.ownerAccountID) { + return false; + } + + if (isExpenseReport(moneyRequestReport) && currentUserAccountID !== moneyRequestReport?.managerID) { + return false; + } + const policy = getPolicy(moneyRequestReport?.policyID); if (PolicyUtils.isInstantSubmitEnabled(policy) && PolicyUtils.isSubmitAndClose(policy) && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID)) { return false; @@ -6218,7 +6226,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o // which is tied to their workspace chat. if (isMoneyRequestReport(report)) { const canAddTransactions = canAddTransaction(report); - return isReportInGroupPolicy(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; + return isReportInGroupPolicy(report) || isExpenseReport(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; } // In the case of policy expense chat, users can only submit expenses from their own policy expense chat From 3580a0609b8d8cdb9f1a20b5abc0ccb6c5e2f926 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 14 Aug 2024 16:00:13 +0700 Subject: [PATCH 2/4] fix: jest test --- tests/unit/ReportUtilsTest.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 12bcabc92b19..658d4ffc0858 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -561,6 +561,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -573,6 +574,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -591,6 +593,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), parentReportID: '102', type: CONST.REPORT.TYPE.EXPENSE, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(2); @@ -611,6 +614,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, parentReportID: '103', + managerID: 5, }; const paidPolicy = { type: CONST.POLICY.TYPE.TEAM, @@ -634,6 +638,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -646,6 +651,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -679,6 +685,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, parentReportID: '101', policyID: paidPolicy.id, + managerID: 5, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(2); From 8894db79748299050aedc3e480659d46663bfd91 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 14 Aug 2024 16:04:46 +0700 Subject: [PATCH 3/4] clean code --- tests/unit/ReportUtilsTest.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 658d4ffc0858..741b550e093d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -561,7 +561,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -574,7 +574,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -593,7 +593,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), parentReportID: '102', type: CONST.REPORT.TYPE.EXPENSE, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]); expect(moneyRequestOptions.length).toBe(2); @@ -614,7 +614,7 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN, parentReportID: '103', - managerID: 5, + managerID: currentUserAccountID, }; const paidPolicy = { type: CONST.POLICY.TYPE.TEAM, @@ -638,7 +638,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -651,7 +651,7 @@ describe('ReportUtils', () => { type: CONST.REPORT.TYPE.IOU, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(1); @@ -685,7 +685,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, parentReportID: '101', policyID: paidPolicy.id, - managerID: 5, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(2); From 81536dabb12ba644351d1bf974d5e7e9f1e99175 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 15 Aug 2024 10:56:49 +0700 Subject: [PATCH 4/4] remove useless code --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 268aa83f0a8a..f6cde4494024 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6226,7 +6226,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o // which is tied to their workspace chat. if (isMoneyRequestReport(report)) { const canAddTransactions = canAddTransaction(report); - return isReportInGroupPolicy(report) || isExpenseReport(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; + return isReportInGroupPolicy(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; } // In the case of policy expense chat, users can only submit expenses from their own policy expense chat