Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor(billing): enhance organization query handling and permission checks
Victor Hugo dos Santos421286c258e1
diff --git a/frontend/src/hooks/api/billingV2/queries.tsx b/frontend/src/hooks/api/billingV2/queries.tsxindex b3d5b76725..cb850477eb 100644--- a/frontend/src/hooks/api/billingV2/queries.tsx+++ b/frontend/src/hooks/api/billingV2/queries.tsx@@ -16,8 +16,8 @@ export const billingV2Keys = {catalog: (orgId: string) => [{ orgId }, "billing-v2-catalog"] as const,usageBreakdown: (orgId: string, dimensionKey: string) =>[{ orgId, dimensionKey }, "billing-v2-usage-breakdown"] as const,- organizations: (orgId: string, params: BillingV2OrganizationsParams) =>- [{ orgId, ...params }, "billing-v2-organizations"] as const+ organizations: (orgId: string, { search, ...rest }: BillingV2OrganizationsParams) =>+ [{ orgId, search: search || undefined, ...rest }, "billing-v2-organizations"] as const};export const useGetBillingV2Overview = (orgId: string) => {diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex 2473f47371..1595c02ba0 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -51,7 +51,7 @@ export const BillingV2Page = () => {const { currentOrg } = useOrganization();const { permission } = useOrgPermission();const orgId = currentOrg?.id ?? "";- const canManageBilling = permission.can(+ const hasManageBillingPermission = permission.can(OrgPermissionBillingActions.ManageBilling,OrgPermissionSubjects.Billing);@@ -72,7 +72,8 @@ export const BillingV2Page = () => {limit: ORG_PAGE_SIZE});const rootOrgs = orgPage?.organizations ?? [];- const { data: unsearchedOrgPage } = useGetBillingV2Organizations(orgId, { limit: ORG_PAGE_SIZE });+ const { data: unsearchedOrgPage, isPending: isRootOrgCountPending } =+ useGetBillingV2Organizations(orgId, { limit: ORG_PAGE_SIZE });const {data: serverOverview,@@ -142,9 +143,17 @@ export const BillingV2Page = () => {// eslint-disable-next-line react-hooks/exhaustive-deps}, []);+ // An instance admin can point the page at an organization they are not a member of, which the+ // permission above says nothing about; ensureManageBilling grants them no bypass, so every mutation+ // would 403.+ const isViewingOtherOrg = selectedOrgId !== orgId;+ const canManageBilling = hasManageBillingPermission && !isViewingOtherOrg;+let subState: BillingV2RenderState = "loading";if (isError) {subState = "error";+ } else if (isRootOrgCountPending) {+ subState = "loading";} else if (overview) {subState = overview.subState;} else if (isPending) {@@ -158,7 +167,7 @@ export const BillingV2Page = () => {const redirectToPortal = async () => {try {const url = await createPortalSession.mutateAsync({- orgId,+ orgId: selectedOrgId,returnPath: window.location.pathname});window.location.href = url;@@ -191,7 +200,7 @@ export const BillingV2Page = () => {const onUpdatePayment = async () => {try {const url = await addPaymentMethod.mutateAsync({- orgId,+ orgId: selectedOrgId,returnPath: window.location.pathname});window.location.href = url;@@ -261,7 +270,7 @@ export const BillingV2Page = () => {{flow?.type === "sheet" && (<ProductSheet- orgId={orgId}+ orgId={selectedOrgId}prod={catalogById(catalog, flow.prodId)}entitlement={overview?.entitlements[flow.prodId]}hasActiveSubscription={hasActiveSubscription}@@ -290,7 +299,7 @@ export const BillingV2Page = () => {{removeProd && (<RemoveProductModal- orgId={orgId}+ orgId={selectedOrgId}product={removeProd}onClose={() => setRemoveProdId(null)}onRemoved={() => {