From d6fde63fc91142640a4728a5650eb11b3a96574a Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 20 Aug 2024 13:50:11 +0700 Subject: [PATCH 1/6] re-create: Submit expense option is not disabled for users who are invited to expense report --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5d161b8a5e76..fad2ec8d4cdc 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1667,6 +1667,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } + if (isExpenseReport(moneyRequestReport) && currentUserAccountID !== moneyRequestReport?.managerID && currentUserAccountID !== moneyRequestReport?.ownerAccountID) { + return false; + } + const policy = getPolicy(moneyRequestReport?.policyID); if (PolicyUtils.isInstantSubmitEnabled(policy) && PolicyUtils.isSubmitAndClose(policy) && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID)) { return false; From 5a92ecc2afac205cbfc3ac6034c8e75d3f6e0eb7 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 20 Aug 2024 14:15:37 +0700 Subject: [PATCH 2/6] fix jest test --- src/libs/ReportUtils.ts | 2 +- tests/unit/ReportUtilsTest.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fad2ec8d4cdc..d5458972338c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1667,7 +1667,7 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } - if (isExpenseReport(moneyRequestReport) && currentUserAccountID !== moneyRequestReport?.managerID && currentUserAccountID !== moneyRequestReport?.ownerAccountID) { + if (currentUserAccountID !== moneyRequestReport?.managerID && currentUserAccountID !== moneyRequestReport?.ownerAccountID) { return false; } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 12bcabc92b19..741b550e093d 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: currentUserAccountID, }; 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: currentUserAccountID, }; 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: currentUserAccountID, }; 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: currentUserAccountID, }; 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: currentUserAccountID, }; 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: currentUserAccountID, }; 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: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs[0]]); expect(moneyRequestOptions.length).toBe(2); From 1ec852c7de66797e7847a830fddf9d8054018ad2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 27 Aug 2024 15:54:59 +0700 Subject: [PATCH 3/6] fix: logic show submit expense button --- src/libs/ReportUtils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 574ee5bd1848..9f7e84ea9106 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1654,10 +1654,6 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } - if (currentUserAccountID !== moneyRequestReport?.managerID && currentUserAccountID !== moneyRequestReport?.ownerAccountID) { - return false; - } - const policy = getPolicy(moneyRequestReport?.policyID); if (PolicyUtils.isInstantSubmitEnabled(policy) && PolicyUtils.isSubmitAndClose(policy) && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID)) { return false; @@ -6311,6 +6307,11 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o return false; } + // Current user must be a manager or owner of this expense + if (currentUserAccountID !== report?.managerID && currentUserAccountID !== report?.ownerAccountID) { + return false; + } + // User can submit expenses in any IOU report, unless paid, but the user can only submit expenses in an expense report // which is tied to their workspace chat. if (isMoneyRequestReport(report)) { From 1734242a5a77a0406b522767731dd4476b45473f Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 27 Aug 2024 16:01:47 +0700 Subject: [PATCH 4/6] fix jest test --- tests/unit/ReportUtilsTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 741b550e093d..6161fa57f75c 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -713,6 +713,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true, + managerID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs]); expect(moneyRequestOptions.length).toBe(3); From ba3c5d172d6edba29026b782be820cb9e4af84ea Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:48:06 +0700 Subject: [PATCH 5/6] Update src/libs/ReportUtils.ts Co-authored-by: Youssef Lourayad --- 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 9f7e84ea9106..5366898dbb6a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6307,7 +6307,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o return false; } - // Current user must be a manager or owner of this expense + // Current user must be a manager or owner of this IOU if (currentUserAccountID !== report?.managerID && currentUserAccountID !== report?.ownerAccountID) { return false; } From 10ea8cbb4b8e665b8e34078871fe343161d2b251 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:48:25 +0700 Subject: [PATCH 6/6] Update src/libs/ReportUtils.ts Co-authored-by: Youssef Lourayad --- 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 5366898dbb6a..b09506c8c3bd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6308,7 +6308,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o } // Current user must be a manager or owner of this IOU - if (currentUserAccountID !== report?.managerID && currentUserAccountID !== report?.ownerAccountID) { + if (isIOUReport(report) && currentUserAccountID !== report?.managerID && currentUserAccountID !== report?.ownerAccountID) { return false; }