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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportU
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import {getConnectedIntegration} from '@libs/PolicyUtils';
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
getBankAccountRoute,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ function getReportPreviewAction(
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
}

export default getReportPreviewAction;
export {canReview, getReportPreviewAction};
4 changes: 4 additions & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy} from './PolicyUtils';
import {getOriginalMessage, isCreatedAction, isDeletedAction, isMoneyRequestAction, isResolvedActionableWhisper, isWhisperActionTargetedToOthers} from './ReportActionsUtils';
import {canReview} from './ReportPreviewActionUtils';
import {
getIcons,
getPersonalDetailsForAccountID,
Expand Down Expand Up @@ -637,6 +638,9 @@ function getAction(data: OnyxTypes.SearchResults['data'], allViolations: OnyxCol

// Only check for violations if we need to (when user has permission to review)
if ((isSubmitter || isApprover || isAdmin) && hasViolations(report.reportID, allViolations, undefined, allReportTransactions)) {
if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, policy, allReportTransactions)) {
return CONST.SEARCH.ACTION_TYPES.VIEW;
}
return CONST.SEARCH.ACTION_TYPES.REVIEW;
}
// Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option.
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/ReportPreviewActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Onyx from 'react-native-onyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
// eslint-disable-next-line no-restricted-syntax
import type * as PolicyUtils from '@libs/PolicyUtils';
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
// eslint-disable-next-line no-restricted-syntax
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const approverAccountID = 1111111;
const approverEmail = 'approver@policy.com';
const overlimitApproverAccountID = 222222;
const overlimitApproverEmail = 'overlimit@policy.com';
const submitterAccountID = 333333;
const submitterEmail = 'submitter@policy.com';
const policyID = 'A1B2C3';
const reportID = '123456789';
const reportID2 = '11111';
Expand Down Expand Up @@ -60,6 +62,12 @@ const searchResults: OnyxTypes.SearchResults = {
displayName: 'Overlimit Approver',
login: overlimitApproverEmail,
},
[submitterAccountID]: {
accountID: submitterAccountID,
avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png',
displayName: 'Submitter',
login: submitterEmail,
},
},
[`policy_${policyID}`]: {
id: 'Admin',
Expand Down Expand Up @@ -97,6 +105,11 @@ const searchResults: OnyxTypes.SearchResults = {
role: CONST.POLICY.ROLE.ADMIN,
submitsTo: approverEmail,
},
[submitterEmail]: {
email: submitterEmail,
role: CONST.POLICY.ROLE.USER,
submitsTo: adminEmail,
},
},
},
[`reportActions_${reportID}`]: {
Expand Down Expand Up @@ -953,6 +966,29 @@ describe('SearchUIUtils', () => {
expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT);
});

test('Should return `View` action for transaction on policy with delayed submission and with violations when current user is submitter and the expense was submitted', async () => {
await Onyx.merge(ONYXKEYS.SESSION, {accountID: submitterAccountID});
const localSearchResults = {
...searchResults.data,
[`policy_${policyID}`]: {
...searchResults.data[`policy_${policyID}`],
role: CONST.POLICY.ROLE.USER,
},
[`report_${reportID2}`]: {
...searchResults.data[`report_${reportID2}`],
accountID: submitterAccountID,
ownerAccountID: submitterAccountID,
},
[`transactions_${transactionID2}`]: {
...searchResults.data[`transactions_${transactionID2}`],
accountID: submitterAccountID,
managerID: adminAccountID,
},
};
expect(SearchUIUtils.getAction(localSearchResults, allViolations, `report_${reportID2}`)).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW);
expect(SearchUIUtils.getAction(localSearchResults, allViolations, `transactions_${transactionID2}`)).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW);
});

test('Should return `Review` action for transaction on policy with delayed submission and with violations', () => {
let action = SearchUIUtils.getAction(searchResults.data, allViolations, `report_${reportID2}`);
expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW);
Expand Down