Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ import {
wasActionTakenByCurrentUser,
} from './ReportActionsUtils';
import type {LastVisibleMessage} from './ReportActionsUtils';
import {getSession} from './SessionUtils';
import {shouldRestrictUserBillableActions} from './SubscriptionUtils';
import {
getAttendees,
Expand Down Expand Up @@ -11841,12 +11840,11 @@ function canRejectReportAction(currentUserLogin: string, report: Report, policy?

const isReportApprover = isApproverUtils(policy, currentUserLogin);
const isReportBeingProcessed = isProcessingReport(report);
const isReportPayer = isPayer(getSession(), report, false, policy);
const isIOU = isIOUReport(report);
const isInvoice = isInvoiceReport(report);
const isCurrentUserManager = report?.managerID === currentUserAccountID;

const userCanReject = (isReportApprover && isCurrentUserManager) || isReportPayer;
const userCanReject = isReportApprover && isCurrentUserManager;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Report manager should be able to reject expense even if approver changed to another person. (context: #79599 (comment))

As a solution, isReportApprover && condition should have been removed.


if (!userCanReject) {
return false; // must be approver or payer
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
canHoldUnholdReportAction,
canJoinChat,
canLeaveChat,
canRejectReportAction,
canSeeDefaultRoom,
canUserPerformWriteAction,
excludeParticipantsForDisplay,
Expand Down Expand Up @@ -8264,4 +8265,24 @@ describe('ReportUtils', () => {
expect(actorAccountID).toEqual(123);
});
});

describe('canRejectReportAction', () => {
it('should return false if the user is not the report manager', async () => {
const approver = 'approver@gmail.com';
const expenseReport: Report = {
...createRandomReport(0),
type: CONST.REPORT.TYPE.EXPENSE,
managerID: 1,
};
const reportPolicy: Policy = {
...createRandomPolicy(0),
approver,
};
await Onyx.merge(ONYXKEYS.SESSION, {
accountID: 2,
});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.NEWDOT_REJECT]);
expect(canRejectReportAction(approver, expenseReport, reportPolicy)).toBe(false);
});
});
});
Loading