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 @@ -109,6 +109,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo

const {isOffline} = useNetwork();
const activePolicy = usePolicy(activePolicyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const lastWorkspaceNumber = useLastWorkspaceNumber();

const {isBetaEnabled} = usePermissions();
Expand Down Expand Up @@ -185,6 +186,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
currentUserLogin: currentUserLogin ?? '',
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const activePolicy = usePolicy(activePolicyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
const isInvoiceReport = isInvoiceReportUtil(moneyRequestReport);

Expand Down Expand Up @@ -267,6 +268,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
currentUserLogin: currentUserLogin ?? '',
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${moneyRequestReport?.reportID}`);

const activePolicy = usePolicy(activePolicyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const invoiceReceiverPolicyID = chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined;
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`);
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
Expand Down Expand Up @@ -131,6 +132,7 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
currentUserLogin: currentUserLogin ?? '',
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function PayActionButton({
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`,
);
Expand Down Expand Up @@ -167,6 +168,7 @@ function PayActionButton({
currentUserLogin: currentUserDetails.login ?? '',
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useHoldMenuSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const activePolicy = usePolicy(activePolicyID);
const policy = usePolicy(moneyRequestReport?.policyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
Expand Down Expand Up @@ -88,6 +89,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
full,
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSelectionModeReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function useSelectionModeReportActions({

const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const activePolicy = usePolicy(activePolicyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`,
);
Expand Down Expand Up @@ -387,6 +388,7 @@ function useSelectionModeReportActions({
currentUserLogin: currentUserLogin ?? '',
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
userBillingGracePeriodEnds,
Expand Down
9 changes: 8 additions & 1 deletion src/libs/actions/IOU/PayMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type PayMoneyRequestFunctionParams = {
full?: boolean;
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
policy?: OnyxEntry<OnyxTypes.Policy>;
chatReportPolicy: OnyxEntry<OnyxTypes.Policy>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean | undefined;
amountOwed: OnyxEntry<number>;
Expand Down Expand Up @@ -739,14 +740,20 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
full = true,
activePolicy,
policy,
chatReportPolicy,
betas,
isSelfTourViewed,
amountOwed,
ownerBillingGracePeriodEnd,
methodID,
onPaid,
} = params;
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
const policyForBillingRestriction = chatReportPolicy ?? (policy?.id === chatReport.policyID ? policy : undefined);
if (
chatReport.policyID &&
policyForBillingRestriction &&
shouldRestrictUserBillableActions(policyForBillingRestriction, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)
Comment on lines +751 to +755

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep billing restriction check when chat policy is unresolved

The new guard requires policyForBillingRestriction to be truthy before calling shouldRestrictUserBillableActions, so payments are allowed whenever chatReportPolicy is still undefined and the IOU policy ID differs from chatReport.policyID. In UI flows this can happen while usePolicy(chatReport?.policyID) is still hydrating, and unlike the previous code path we no longer fall back to passing chatReport.policyID directly (which allowed SubscriptionUtils to resolve from the policy collection). This creates a regression where restricted users can briefly bypass the redirect and attempt payment.

Useful? React with 👍 / 👎.

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.

@truph01 should we address this?

) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
return;
}
Expand Down
Loading
Loading