Skip to content

Commit ba3dd9c

Browse files
authored
Merge pull request Expensify#73120 from bernhardoj/fix/72465-only-allow-reject-for-report-manager
Only allow report manager to reject expense
2 parents 77f32f2 + 0a48624 commit ba3dd9c

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ import {
242242
wasActionTakenByCurrentUser,
243243
} from './ReportActionsUtils';
244244
import type {LastVisibleMessage} from './ReportActionsUtils';
245-
import {getSession} from './SessionUtils';
246245
import {shouldRestrictUserBillableActions} from './SubscriptionUtils';
247246
import {
248247
getAttendees,
@@ -11837,12 +11836,11 @@ function canRejectReportAction(currentUserLogin: string, report: Report, policy?
1183711836

1183811837
const isReportApprover = isApproverUtils(policy, currentUserLogin);
1183911838
const isReportBeingProcessed = isProcessingReport(report);
11840-
const isReportPayer = isPayer(getSession(), report, false, policy);
1184111839
const isIOU = isIOUReport(report);
1184211840
const isInvoice = isInvoiceReport(report);
1184311841
const isCurrentUserManager = report?.managerID === currentUserAccountID;
1184411842

11845-
const userCanReject = (isReportApprover && isCurrentUserManager) || isReportPayer;
11843+
const userCanReject = isReportApprover && isCurrentUserManager;
1184611844

1184711845
if (!userCanReject) {
1184811846
return false; // must be approver or payer

tests/unit/ReportUtilsTest.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
canHoldUnholdReportAction,
3636
canJoinChat,
3737
canLeaveChat,
38+
canRejectReportAction,
3839
canSeeDefaultRoom,
3940
canUserPerformWriteAction,
4041
excludeParticipantsForDisplay,
@@ -8264,4 +8265,24 @@ describe('ReportUtils', () => {
82648265
expect(actorAccountID).toEqual(123);
82658266
});
82668267
});
8268+
8269+
describe('canRejectReportAction', () => {
8270+
it('should return false if the user is not the report manager', async () => {
8271+
const approver = 'approver@gmail.com';
8272+
const expenseReport: Report = {
8273+
...createRandomReport(0),
8274+
type: CONST.REPORT.TYPE.EXPENSE,
8275+
managerID: 1,
8276+
};
8277+
const reportPolicy: Policy = {
8278+
...createRandomPolicy(0),
8279+
approver,
8280+
};
8281+
await Onyx.merge(ONYXKEYS.SESSION, {
8282+
accountID: 2,
8283+
});
8284+
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.NEWDOT_REJECT]);
8285+
expect(canRejectReportAction(approver, expenseReport, reportPolicy)).toBe(false);
8286+
});
8287+
});
82678288
});

0 commit comments

Comments
 (0)