Skip to content
Draft
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
10 changes: 8 additions & 2 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1911,21 +1911,27 @@ function isViolationDismissed(
return dismissedByEmails.length > 0;
}

// If the admin is looking at an open report, we check for both, submitter and admin.
// If someone is looking at an open report, we check for cross-role dismissals.
if (!iouReport) {
return false;
}

const isSubmitter = iouReport.ownerAccountID === currentUserAccountID;
const shouldViewAsSubmitter = !isSubmitter && isOpenExpenseReport(iouReport);

// If the admin is looking at an open report, check if the submitter dismissed it.
const shouldViewAsSubmitter = !isSubmitter && isOpenExpenseReport(iouReport);
if (shouldViewAsSubmitter && iouReport.ownerAccountID) {
const reportOwnerEmail = getLoginsByAccountIDs([iouReport.ownerAccountID]).at(0);
if (reportOwnerEmail && dismissedByEmails.includes(reportOwnerEmail)) {
return true;
}
}

// If the submitter is looking at an open report, check if an admin/approver dismissed it.
if (isSubmitter && isOpenExpenseReport(iouReport) && dismissedByEmails.length > 0) {
return true;
}

return false;
}

Expand Down
33 changes: 30 additions & 3 deletions tests/unit/TransactionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,14 @@ describe('TransactionUtils', () => {
expect(result).toBe(false);
});

it('should return false when submitter views their own open report (not condition 2)', () => {
it('should return true when submitter views their own open report and admin dismissed violation', () => {
// Given an OPEN report owned by current user
const iouReport: Report = {
...openReport,
ownerAccountID: CURRENT_USER_ID,
};

// And a transaction where someone else dismissed a violation
// And a transaction where someone else (admin) dismissed a violation
const transaction = generateTransaction({
reportID: iouReport.reportID,
comment: {
Expand All @@ -950,7 +950,34 @@ describe('TransactionUtils', () => {
// When current user (the submitter) checks if violation is dismissed
const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, iouReport, undefined);

// Then it should return false (condition 2 doesn't apply to submitters)
// Then it should return true because admin dismissed it on behalf of the submitter
expect(result).toBe(true);
});

it('should return false when submitter views their own processing report and admin dismissed violation', () => {
// Given a PROCESSING report owned by current user
const iouReport: Report = {
...processingReport,
ownerAccountID: CURRENT_USER_ID,
};

// And a transaction where someone else (admin) dismissed a violation
const transaction = generateTransaction({
reportID: iouReport.reportID,
comment: {
dismissedViolations: {
[CONST.VIOLATIONS.DUPLICATED_TRANSACTION]: {
[OTHER_USER_EMAIL]: DateUtils.getDBTime(),
},
},
},
});
const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION};

// When current user (the submitter) checks if violation is dismissed
const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, iouReport, undefined);

// Then it should return false because on processing reports, submitter must dismiss separately
expect(result).toBe(false);
});
});
Expand Down
Loading