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
19 changes: 1 addition & 18 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,24 +573,7 @@ function isHoldActionForTransaction(
return false;
}

const isOpenReport = isOpenReportUtils(report);
const isSubmitter = isCurrentUserSubmitter(report);
const isReportManager = isReportManagerUtils(report);

if (isIOUReport) {
return (isSubmitter || isReportManager) && !isSettled(report);
}

if (isOpenReport && (isSubmitter || isReportManager)) {
return true;
}

if (isSubmitter) {
return isAwaitingFirstLevelApproval(report);
}

const isProcessingReport = isProcessingReportUtils(report);
return isProcessingReport;
return true;
}

function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy>, currentUserLogin: string, reportActions?: ReportAction[]): boolean {
Expand Down
13 changes: 10 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import type PolicyData from '@hooks/usePolicyData/types';
import type {PolicyTagList} from '@pages/workspace/tags/types';
import type {ThemeColors} from '@styles/theme/types';
import {canApproveIOU, canIOUBePaid, canSubmitReport, getIOUReportActionWithBadge} from '@userActions/IOU/ReportWorkflow';

Check warning on line 27 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected subpath import via alias '@userActions/IOU/ReportWorkflow'. Use './actions/IOU/ReportWorkflow' instead
import type {IOUAction, IOUType, OnboardingAccounting} from '@src/CONST';
import CONST, {TASK_TO_FEATURE} from '@src/CONST';
import type {ParentNavigationSummaryParams} from '@src/languages/params';
Expand Down Expand Up @@ -1036,7 +1036,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1039 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1044,7 +1044,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1047 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1062,7 +1062,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1065 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1074,7 +1074,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1077 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1082,7 +1082,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1085 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1092,7 +1092,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1095 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1100,7 +1100,7 @@

let deprecatedAllReports: OnyxCollection<Report>;
let deprecatedReportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1103 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1136,14 +1136,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1139 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1146 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -5132,7 +5132,15 @@
return isActionOwner || isManager;
}

return isAdmin || isActionOwner || isManager;
if (isOpenExpenseReport(report)) {
return isActionOwner || isManager;

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.

Manager cannot modify hold status of open expense report

}

if (isActionOwner && !isAdmin) {
return isAwaitingFirstLevelApproval(report);
}

return (isAdmin || isManager) && isProcessingReport(report);
}

function canHoldUnholdReportAction(
Expand All @@ -5158,13 +5166,12 @@
const isAdmin = isPolicyAdminPolicyUtils(policy);
const isOnHold = isOnHoldTransactionUtils(transaction);
const isClosed = isClosedReport(report);
const isSubmitted = isProcessingReport(report);

const canModifyStatus = canModifyHoldStatus(report, reportAction, currentUserAccountID);
const canModifyUnholdStatus = !isTrackExpenseMoneyReport && (isAdmin || (isActionOwner && isHoldActionCreator) || isApprover);

const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isClosed && !isDeletedParentAction(reportAction);
const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && canModifyStatus && !isScanning(transaction) && (isSubmitted || isActionOwner);
const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && canModifyStatus && !isScanning(transaction);
Comment thread
nkdengineer marked this conversation as resolved.
Resolved

const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && (isRequestIOU ? isHoldActionCreator : canModifyUnholdStatus));

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ReportSecondaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1403,8 +1403,8 @@ describe('getSecondaryAction', () => {
} as unknown as Transaction;
const policy = {} as unknown as Policy;

jest.spyOn(ReportUtils, 'canHoldUnholdReportAction').mockReturnValueOnce({canHoldRequest: true, canUnholdRequest: true});
jest.spyOn(ReportUtils, 'isAwaitingFirstLevelApproval').mockReturnValueOnce(false);
jest.spyOn(ReportUtils, 'isActionCreator').mockReturnValueOnce(true);
jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValueOnce(originalMessageR14932.IOUTransactionID);
const result = getSecondaryReportActions({
currentUserLogin: EMPLOYEE_EMAIL,
Expand Down
100 changes: 100 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4924,6 +4924,106 @@ describe('ReportUtils', () => {
canUnholdRequest: true,
});
});

it('should return false for admin-only on open expense report', () => {
const expenseReport = {
...createExpenseReport(1001),
policyID: 'policy-1',
ownerAccountID: 99999,
managerID: 99998,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
};
const expenseTransaction = buildOptimisticTransaction({
transactionParams: {
amount: 100,
currency: 'USD',
reportID: expenseReport.reportID,
},
});
const expenseCreatedAction = buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
amount: 100,
currency: 'USD',
comment: '',
participants: [],
transactionID: expenseTransaction.transactionID,
iouReportID: expenseReport.reportID,
});
expenseCreatedAction.actorAccountID = 99997;
const adminPolicy = {
id: expenseReport.policyID,
role: CONST.POLICY.ROLE.ADMIN,
} as Policy;

expect(canHoldUnholdReportAction(expenseReport, expenseCreatedAction, undefined, expenseTransaction, adminPolicy, currentUserAccountID)).toEqual({
canHoldRequest: false,
canUnholdRequest: false,
});
});

it('should return false for non-admin action owner when processing report is not awaiting first level approval', () => {
const expenseReport = {
...createExpenseReport(1002),
policyID: 'policy-2',
managerID: 99999,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
const expenseTransaction = buildOptimisticTransaction({
transactionParams: {
amount: 100,
currency: 'USD',
reportID: expenseReport.reportID,
},
});
const expenseCreatedAction = buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
amount: 100,
currency: 'USD',
comment: '',
participants: [],
transactionID: expenseTransaction.transactionID,
iouReportID: expenseReport.reportID,
});

expect(canHoldUnholdReportAction(expenseReport, expenseCreatedAction, undefined, expenseTransaction, undefined, currentUserAccountID)).toEqual({
canHoldRequest: false,
canUnholdRequest: false,
});
});

it('should return true for manager on processing expense report', () => {
const expenseReport = {
...createExpenseReport(1003),
policyID: 'policy-3',
managerID: currentUserAccountID,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
};
const expenseTransaction = buildOptimisticTransaction({
transactionParams: {
amount: 100,
currency: 'USD',
reportID: expenseReport.reportID,
},
});
const expenseCreatedAction = buildOptimisticIOUReportAction({
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
amount: 100,
currency: 'USD',
comment: '',
participants: [],
transactionID: expenseTransaction.transactionID,
iouReportID: expenseReport.reportID,
});
expenseCreatedAction.actorAccountID = 99996;

expect(canHoldUnholdReportAction(expenseReport, expenseCreatedAction, undefined, expenseTransaction, undefined, currentUserAccountID)).toEqual({
canHoldRequest: true,
canUnholdRequest: false,
});
});
});

describe('isAdminOwnerApproverOrReportOwner uses explicit currentUserAccountID', () => {
Expand Down
Loading