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
17 changes: 14 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@
};

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

Check warning on line 1048 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 @@ -1053,7 +1053,7 @@
});

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

Check warning on line 1056 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 @@ -1071,7 +1071,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1074 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 @@ -1083,7 +1083,7 @@
});

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

Check warning on line 1086 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 @@ -1091,7 +1091,7 @@

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

Check warning on line 1094 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 @@ -1101,7 +1101,7 @@
});

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

Check warning on line 1104 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 @@ -1109,7 +1109,7 @@

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

Check warning on line 1112 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 @@ -1145,14 +1145,14 @@
});

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

Check warning on line 1148 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 1155 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 All @@ -1178,7 +1178,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1181 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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -11326,9 +11326,16 @@
);
}

function createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected: OnyxEntry<IntroSelected>, transactionID: string, actionName: IOUAction, workspaceName: string): void {
function createDraftWorkspaceAndNavigateToConfirmationScreen(
introSelected: OnyxEntry<IntroSelected>,
transactionID: string,
actionName: IOUAction,
workspaceName: string,
currentUserAccountID: number,
currentUserEmail: string,
): void {
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, workspaceName, deprecatedCurrentUserEmail);
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, workspaceName, currentUserAccountID, currentUserEmail);
setMoneyRequestParticipants(transactionID, [
{
selected: true,
Expand Down Expand Up @@ -11360,6 +11367,8 @@
isRestrictedToPreferredPolicy?: boolean;
preferredPolicyID?: string;
transaction: OnyxEntry<Transaction>;
currentUserAccountID: number;
currentUserEmail: string;
};

function createDraftTransactionAndNavigateToParticipantSelector({
Expand All @@ -11375,6 +11384,8 @@
isRestrictedToPreferredPolicy = false,
preferredPolicyID,
transaction,
currentUserAccountID,
currentUserEmail,
}: CreateDraftTransactionParams): void {
const transactionID = transaction?.transactionID;
if (!transactionID || !reportID) {
Expand Down Expand Up @@ -11519,7 +11530,7 @@
return;
}

return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName, '');
return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName, '', currentUserAccountID, currentUserEmail);
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,8 @@ function createWorkspace(options: CreateWorkspaceDataOptions): CreateWorkspacePa
function createDraftWorkspace(
introSelected: OnyxEntry<IntroSelected>,
workspaceName: string,
currentUserAccountID: number,
currentUserEmail: string,
policyOwnerEmail = '',
makeMeAdmin = false,
policyID = generatePolicyID(),
Expand All @@ -3002,13 +3004,13 @@ function createDraftWorkspace(
type: CONST.POLICY.TYPE.TEAM,
name: workspaceName,
role: CONST.POLICY.ROLE.ADMIN,
owner: deprecatedSessionEmail,
ownerAccountID: deprecatedSessionAccountID,
owner: currentUserEmail,
ownerAccountID: currentUserAccountID,
isPolicyExpenseChatEnabled: true,
outputCurrency,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
autoReporting: true,
approver: deprecatedSessionEmail,
approver: currentUserEmail,
autoReportingFrequency: shouldEnableWorkflowsByDefault ? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE : CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
harvesting: {
enabled: !shouldEnableWorkflowsByDefault,
Expand All @@ -3024,9 +3026,9 @@ function createDraftWorkspace(
areConnectionsEnabled: false,
areExpensifyCardsEnabled: false,
employeeList: {
[deprecatedSessionEmail]: {
submitsTo: deprecatedSessionEmail,
email: deprecatedSessionEmail,
[currentUserEmail]: {
submitsTo: currentUserEmail,
email: currentUserEmail,
role: CONST.POLICY.ROLE.ADMIN,
errors: {},
},
Expand Down
6 changes: 6 additions & 0 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
isRestrictedToPreferredPolicy,
preferredPolicyID,
transaction: iouTransaction,
currentUserAccountID: currentUserPersonalDetails.accountID,
currentUserEmail: currentUserPersonalDetails.email ?? '',
});
},
});
Expand All @@ -491,6 +493,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
amountOwed,
ownerBillingGracePeriodEnd,
transaction: iouTransaction,
currentUserAccountID: currentUserPersonalDetails.accountID,
currentUserEmail: currentUserPersonalDetails.email ?? '',
});
},
});
Expand All @@ -512,6 +516,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
amountOwed,
ownerBillingGracePeriodEnd,
transaction: iouTransaction,
currentUserAccountID: currentUserPersonalDetails.accountID,
currentUserEmail: currentUserPersonalDetails.email ?? '',
});
},
});
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Travel/WorkspaceConfirmationForTravelPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ function WorkspaceConfirmationForTravelPage({route}: WorkspaceConfirmationForTra
};

const onSubmit = (params: WorkspaceConfirmationSubmitFunctionParams) => {
createDraftWorkspace(introSelected, params.name, '', false, params.policyID, params.currency, params.avatarFile as File);
createDraftWorkspace(
introSelected,
params.name,
currentUserPersonalDetails.accountID,
currentUserPersonalDetails.email ?? '',
'',
false,
params.policyID,
params.currency,
params.avatarFile as File,
);
createWorkspace({
policyName: params.name,
policyID: params.policyID,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/inbox/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ function PureReportActionItem({
isRestrictedToPreferredPolicy,
preferredPolicyID,
transaction: trackExpenseTransaction,
currentUserAccountID: personalDetail.accountID,
currentUserEmail: personalDetail.email ?? '',
});
},
},
Expand All @@ -998,6 +1000,8 @@ function PureReportActionItem({
amountOwed,
ownerBillingGracePeriodEnd,
transaction: trackExpenseTransaction,
currentUserAccountID: personalDetail.accountID,
currentUserEmail: personalDetail.email ?? '',
});
},
},
Expand All @@ -1016,6 +1020,8 @@ function PureReportActionItem({
amountOwed,
ownerBillingGracePeriodEnd,
transaction: trackExpenseTransaction,
currentUserAccountID: personalDetail.accountID,
currentUserEmail: personalDetail.email ?? '',
});
},
},
Expand Down
11 changes: 9 additions & 2 deletions src/pages/iou/request/step/IOURequestStepAccountant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function IOURequestStepAccountant({
},
}: IOURequestStepAccountantProps) {
const {translate} = useLocalize();
const {login, email = ''} = useCurrentUserPersonalDetails();
const {accountID, login, email = ''} = useCurrentUserPersonalDetails();
const selector = useCallback(
(policies: OnyxCollection<Policy>) => {
return activeAdminPoliciesSelector(policies, login ?? '');
Expand All @@ -49,7 +49,14 @@ function IOURequestStepAccountant({
// Sharing with an accountant involves inviting them to the workspace and that requires admin access.
const hasActiveAdminWorkspaces = (adminPolicies?.length ?? 0) > 0;
if (!hasActiveAdminWorkspaces) {
createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, action, newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate));
createDraftWorkspaceAndNavigateToConfirmationScreen(
introSelected,
transactionID,
action,
newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate),
accountID,
email,
);
return;
}

Expand Down
13 changes: 10 additions & 3 deletions src/pages/iou/request/step/IOURequestStepParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ function IOURequestStepParticipants({
if ((isCategorizing || isShareAction) && numberOfParticipants.current === 0) {
const email = currentUserPersonalDetails.email ?? '';
const lastWorkspaceNumber = lastWorkspaceNumberSelector(allPolicies, email);
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate));
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(
introSelected,
newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate),
currentUserPersonalDetails.accountID,
email,
Comment thread
DylanDylann marked this conversation as resolved.
);
for (const transaction of draftTransactions) {
setMoneyRequestParticipants(transaction.transactionID, [
{
Expand Down Expand Up @@ -392,17 +397,19 @@ function IOURequestStepParticipants({
participants,
iouType,
initialTransaction,
selfDMReportID,
initialTransactionID,
reportID,
waitForKeyboardDismiss,
draftTransactions,
isMovingTransactionFromTrackExpense,
allPolicies,
policyForMovingExpenses,
currentUserPersonalDetails.email,
currentUserPersonalDetails.accountID,
introSelected,
backTo,
selfDMReportID,
translate,
backTo,
],
);

Expand Down
8 changes: 8 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ describe('actions/IOU', () => {
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
transaction: transactionToCategorize,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -588,6 +590,8 @@ describe('actions/IOU', () => {
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
transaction: originalTransaction,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -625,6 +629,8 @@ describe('actions/IOU', () => {
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
transaction: undefined,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -657,6 +663,8 @@ describe('actions/IOU', () => {
transaction,
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down
4 changes: 4 additions & 0 deletions tests/actions/IOUTest/TrackExpenseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ describe('actions/IOU/TrackExpense', () => {
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
transaction,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down Expand Up @@ -841,6 +843,8 @@ describe('actions/IOU/TrackExpense', () => {
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
transaction: createdTransaction,
currentUserAccountID: RORY_ACCOUNT_ID,
currentUserEmail: RORY_EMAIL,
});
await waitForBatchedUpdates();

Expand Down
44 changes: 42 additions & 2 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,16 @@ describe('actions/Policy', () => {
await waitForBatchedUpdates();

const policyID = Policy.generatePolicyID();
const params = Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, WORKSPACE_NAME, ESH_EMAIL, true, policyID, CONST.CURRENCY.USD);
const params = Policy.createDraftWorkspace(
{choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM},
WORKSPACE_NAME,
ESH_ACCOUNT_ID,
ESH_EMAIL,
ESH_EMAIL,
true,
policyID,
CONST.CURRENCY.USD,
);
await waitForBatchedUpdates();

const draft = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);
Expand Down Expand Up @@ -1952,7 +1961,7 @@ describe('actions/Policy', () => {
await waitForBatchedUpdates();

const policyID = Policy.generatePolicyID();
Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE}, WORKSPACE_NAME, ESH_EMAIL, false, policyID, CONST.CURRENCY.EUR);
Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE}, WORKSPACE_NAME, ESH_ACCOUNT_ID, ESH_EMAIL, ESH_EMAIL, false, policyID, CONST.CURRENCY.EUR);
await waitForBatchedUpdates();

const draft = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);
Expand All @@ -1963,6 +1972,37 @@ describe('actions/Policy', () => {
expect(draft?.harvesting?.enabled).toBe(true);
expect(draft?.outputCurrency).toBe(CONST.CURRENCY.EUR);
});

it('should set owner, ownerAccountID, approver, and employeeList from explicit parameters instead of Onyx session', async () => {
// Set Onyx session to a DIFFERENT accountID/email to verify the explicit parameters are used
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
await waitForBatchedUpdates();

const customAccountID = 999;
const customEmail = 'custom@example.com';
const policyID = Policy.generatePolicyID();

Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, WORKSPACE_NAME, customAccountID, customEmail, customEmail, false, policyID);
await waitForBatchedUpdates();

const draft = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);

// Verify explicit params are used, not the Onyx session values
expect(draft?.owner).toBe(customEmail);
expect(draft?.ownerAccountID).toBe(customAccountID);
expect(draft?.approver).toBe(customEmail);
expect(draft?.employeeList?.[customEmail]).toEqual({
submitsTo: customEmail,
email: customEmail,
role: CONST.POLICY.ROLE.ADMIN,
errors: {},
});

// Verify the Onyx session values are NOT used
expect(draft?.owner).not.toBe(ESH_EMAIL);
expect(draft?.ownerAccountID).not.toBe(ESH_ACCOUNT_ID);
expect(draft?.employeeList?.[ESH_EMAIL]).toBeUndefined();
});
});

describe('upgradeToCorporate', () => {
Expand Down
Loading
Loading