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
6 changes: 6 additions & 0 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getValidConnectedIntegration,
hasDynamicExternalWorkflow,
hasIntegrationAutoSync,
isPaidGroupPolicy,
isPolicyAdmin as isPolicyAdminPolicyUtils,
isPreferredExporter,
} from './PolicyUtils';
Expand Down Expand Up @@ -415,6 +416,11 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
isSubmittingAnimationRunning,
} = params;

// The expense report of personal policy shouldn't have any action
if (isExpenseReportUtils(report) && !isPaidGroupPolicy(policy)) {
return '';
}

// We want to have action displayed for either paid or approved animations
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (isPaidAnimationRunning || isApprovedAnimationRunning) {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
hasDynamicExternalWorkflow,
hasIntegrationAutoSync,
isInstantSubmitEnabled,
isPaidGroupPolicy,
isPolicyAdmin,
isPolicyMember,
isPreferredExporter,
Expand Down Expand Up @@ -204,7 +205,7 @@ function isSubmitAction({

const isExpenseReport = isExpenseReportUtils(report);

if (!isExpenseReport || (report?.total === 0 && reportTransactions.length === 0)) {
if (!isExpenseReport || (report?.total === 0 && reportTransactions.length === 0) || !isPaidGroupPolicy(policy)) {
return false;
}

Expand Down
8 changes: 7 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput';
import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow';
import type PolicyData from '@hooks/usePolicyData/types';
import {computeReportName} from '@libs/ReportNameUtils';

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected subpath import via alias '@libs/ReportNameUtils'. Use './ReportNameUtils' instead
import type {PolicyTagList} from '@pages/workspace/tags/types';
import type {ThemeColors} from '@styles/theme/types';
import type {IOUAction, IOUType, OnboardingAccounting} from '@src/CONST';
Expand Down Expand Up @@ -2789,12 +2789,18 @@
* - if current user is not the submitter of an expense report
*/
function canAddTransaction(moneyRequestReport: OnyxEntry<Report>, isReportArchived = false, isMovingTransaction = false): boolean {
if (!isMoneyRequestReport(moneyRequestReport) || (isExpenseReport(moneyRequestReport) && !isCurrentUserSubmitter(moneyRequestReport))) {
if (!isMoneyRequestReport(moneyRequestReport)) {
return false;
}

// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(moneyRequestReport?.policyID);

if (isExpenseReport(moneyRequestReport) && (!isCurrentUserSubmitter(moneyRequestReport) || !isPaidGroupPolicyPolicyUtils(policy))) {
return false;
}
Comment thread
nkdengineer marked this conversation as resolved.

if (
isInstantSubmitEnabled(policy) &&
isSubmitAndClose(policy) &&
Expand Down
8 changes: 8 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import {rand64} from '@libs/NumberUtils';
import {getLoginsByAccountIDs} from '@libs/PersonalDetailsUtils';
// eslint-disable-next-line no-restricted-syntax
import type * as PolicyUtils from '@libs/PolicyUtils';
import {
getOriginalMessage,
getReportActionHtml,
Expand Down Expand Up @@ -174,6 +176,12 @@ jest.mock('@src/libs/SearchQueryUtils', () => {
};
});

jest.mock('@libs/PolicyUtils', () => ({
...jest.requireActual<typeof PolicyUtils>('@libs/PolicyUtils'),
isPaidGroupPolicy: jest.fn().mockReturnValue(true),
isPolicyOwner: jest.fn().mockImplementation((policy?: OnyxEntry<Policy>, currentUserAccountID?: number) => !!currentUserAccountID && policy?.ownerAccountID === currentUserAccountID),
}));

const CARLOS_EMAIL = 'cmartins@expensifail.com';
const CARLOS_ACCOUNT_ID = 1;
const CARLOS_PARTICIPANT: Participant = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, role: 'member'};
Expand Down
3 changes: 2 additions & 1 deletion tests/actions/ReportPreviewActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jest.mock('@libs/PolicyUtils', () => ({
isPreferredExporter: jest.fn().mockReturnValue(true),
hasAccountingConnections: jest.fn().mockReturnValue(true),
getValidConnectedIntegration: jest.fn().mockReturnValue('netsuite'),
isPaidGroupPolicy: jest.fn().mockReturnValue(true),
}));
jest.mock('@src/libs/SearchUIUtils', () => ({
getSuggestedSearches: jest.fn().mockReturnValue({}),
Expand Down Expand Up @@ -70,7 +71,7 @@ describe('getReportPreviewAction', () => {
} as unknown as Report;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

const policy = createRandomPolicy(0, CONST.POLICY.TYPE.PERSONAL);
const policy = createRandomPolicy(0, CONST.POLICY.TYPE.CORPORATE);
expect(getReportPreviewAction({isReportArchived: false, currentUserAccountID: CURRENT_USER_ACCOUNT_ID, currentUserEmail: CURRENT_USER_EMAIL, report, policy, transactions: []})).toBe(
CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE,
);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/QuickActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ describe('QuickActionUtils', () => {
ABCDEF: perDiemCustomUnit,
},
} as unknown as Policy;
mockedPolicyUtils.isPaidGroupPolicy.mockReturnValue(true);

expect(isQuickActionAllowed(perDiemAction, report, policy, false, false)).toBe(true);
});
it("should not allow per diem action when policy doesn't have per diem rates", () => {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/ReportPrimaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jest.mock('@libs/PolicyUtils', () => ({
...jest.requireActual<typeof PolicyUtils>('@libs/PolicyUtils'),
isPolicyAdmin: jest.fn().mockImplementation((policy?: Policy) => policy?.role === 'admin'),
getValidConnectedIntegration: jest.fn(),
isPaidGroupPolicy: jest.fn().mockReturnValue(true),
}));

describe('getPrimaryAction', () => {
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/ReportSecondaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jest.mock('@libs/PolicyUtils', () => ({
hasAccountingConnections: jest.fn().mockReturnValue(true),
isPolicyAdmin: jest.fn().mockReturnValue(true),
getValidConnectedIntegration: jest.fn().mockReturnValue('netsuite'),
isPaidGroupPolicy: jest.fn().mockReturnValue(true),
}));

describe('getSecondaryAction', () => {
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('getSecondaryAction', () => {
harvesting: {
enabled: true,
},
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const TRANSACTION_ID = 'TRANSACTION_ID';
Expand Down Expand Up @@ -121,6 +123,7 @@ describe('getSecondaryAction', () => {
harvesting: {
enabled: true,
},
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

Expand Down Expand Up @@ -151,6 +154,7 @@ describe('getSecondaryAction', () => {
enabled: true,
},
role: CONST.POLICY.ROLE.ADMIN,
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

Expand Down Expand Up @@ -181,6 +185,7 @@ describe('getSecondaryAction', () => {
harvesting: {
enabled: true,
},
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

Expand Down Expand Up @@ -257,6 +262,7 @@ describe('getSecondaryAction', () => {
enabled: true,
},
role: CONST.POLICY.ROLE.USER,
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;

const transaction = {
Expand Down Expand Up @@ -303,6 +309,7 @@ describe('getSecondaryAction', () => {
enabled: true,
},
role: CONST.POLICY.ROLE.AUDITOR,
type: CONST.POLICY.TYPE.CORPORATE,
} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {translate} from '@libs/Localize';
import getReportURLForCurrentContext from '@libs/Navigation/helpers/getReportURLForCurrentContext';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation from '@libs/Navigation/Navigation';
// eslint-disable-next-line no-restricted-syntax
import * as PolicyUtils from '@libs/PolicyUtils';
import {getOriginalMessage, getReportAction, isWhisperAction} from '@libs/ReportActionsUtils';
import {buildReportNameFromParticipantNames, computeReportName, getGroupChatName, getPolicyExpenseChatName, getReportName} from '@libs/ReportNameUtils';
import type {OptionData} from '@libs/ReportUtils';
Expand Down Expand Up @@ -188,6 +190,14 @@ jest.mock('@libs/Navigation/Navigation', () => ({
},
}));

jest.mock('@libs/PolicyUtils', () => ({
...jest.requireActual<typeof PolicyUtils>('@libs/PolicyUtils'),
isPolicyAdmin: jest.fn().mockImplementation((policy?: Policy) => policy?.role === 'admin'),
isPaidGroupPolicy: jest.fn().mockImplementation((policy?: Policy) => policy?.type === 'corporate' || policy?.type === 'team'),
}));

const mockedPolicyUtils = PolicyUtils as jest.Mocked<typeof PolicyUtils>;

const testDate = DateUtils.getDBTime();
const currentUserEmail = 'bjorn@vikings.net';
const currentUserAccountID = 5;
Expand Down Expand Up @@ -2886,6 +2896,7 @@ describe('ReportUtils', () => {
type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: currentUserAccountID,
};
mockedPolicyUtils.isPaidGroupPolicy.mockReturnValue(true);
const moneyRequestOptions = temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID]);
expect(moneyRequestOptions.length).toBe(2);
expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true);
Expand Down Expand Up @@ -5988,6 +5999,8 @@ describe('ReportUtils', () => {
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);

mockedPolicyUtils.isPaidGroupPolicy.mockReturnValue(true);

// When it's checked if the transactions can be added
// Simulate how components determined if a report is archived by using this hook
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));
Expand All @@ -6006,6 +6019,8 @@ describe('ReportUtils', () => {
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);

mockedPolicyUtils.isPaidGroupPolicy.mockReturnValue(true);

const result = canAddTransaction(report, false);

// Then the result is false
Expand Down Expand Up @@ -6050,6 +6065,8 @@ describe('ReportUtils', () => {

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));

mockedPolicyUtils.isPaidGroupPolicy.mockReturnValue(true);

// If the canAddTransaction is used for the case of adding expense into the report
const result = canAddTransaction(report, isReportArchived.current);

Expand Down
Loading