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
feat(billing): enhance organization breakdown with parent organization name
Victor Hugo dos Santos4cc9cef91ae7
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.tsindex cc16a35a10..99f36b2cca 100644--- a/backend/src/ee/routes/v1/license-v2-router.ts+++ b/backend/src/ee/routes/v1/license-v2-router.ts@@ -197,6 +197,10 @@ const BillingV2BreakdownScopeSchema = z.object({orgId: z.string().describe("ID of the organization the units were created in."),name: z.string().describe("Display name of the organization."),isRoot: z.boolean().describe("Whether this is the root organization of the billing tree."),+ parentOrgName: z+ .string()+ .nullable()+ .describe("Display name of the root organization this sub-organization belongs to; null on a root org."),count: z.number().describe("Metered units attributed to this organization."),orgLevelCount: z.number().describe("Units created on the organization itself rather than in a project."),projects: zdiff --git a/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts b/backend/src/ee/services/license-v2/license-v2-breakdown-dal.tsindex 2dfff0cdd1..eab9c1242c 100644--- a/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts+++ b/backend/src/ee/services/license-v2/license-v2-breakdown-dal.ts@@ -6,7 +6,7 @@ import { orgTreeIds } from "@app/lib/knex";export type TLicenseV2BreakdownDALFactory = ReturnType<typeof licenseV2BreakdownDALFactory>;-export type TScopeOrgRow = { id: string; name: string; isRoot: boolean };+export type TScopeOrgRow = { id: string; name: string; isRoot: boolean; rootOrgId: string | null };export type TRootOrgRow = { id: string; name: string; slug: string };export type TScopeProjectRow = { id: string; name: string; orgId: string };@@ -20,7 +20,7 @@ export const licenseV2BreakdownDALFactory = (db: TDbClient) => {.select("id", "name", "rootOrgId")) as { id: string; name: string; rootOrgId: string | null }[];// A root org is the one carrying no rootOrgId; every sub-org points back at it.- return rows.map((row) => ({ id: row.id, name: row.name, isRoot: !row.rootOrgId }));+ return rows.map((row) => ({ id: row.id, name: row.name, isRoot: !row.rootOrgId, rootOrgId: row.rootOrgId }));} catch (error) {throw new DatabaseError({ error, name: "Find org tree names for usage breakdown" });}@@ -37,7 +37,7 @@ export const licenseV2BreakdownDALFactory = (db: TDbClient) => {rootOrgId: string | null;}[];- return rows.map((row) => ({ id: row.id, name: row.name, isRoot: !row.rootOrgId }));+ return rows.map((row) => ({ id: row.id, name: row.name, isRoot: !row.rootOrgId, rootOrgId: row.rootOrgId }));} catch (error) {throw new DatabaseError({ error, name: "Find all org names for usage breakdown" });}diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.tsindex 32497588ba..484066d2a7 100644--- a/backend/src/ee/services/license-v2/license-v2-service.ts+++ b/backend/src/ee/services/license-v2/license-v2-service.ts@@ -875,11 +875,21 @@ export const licenseV2ServiceFactory = ({type TScopeAccumulator = {name: string;isRoot: boolean;+ rootOrgId: string | null;orgLevelCount: number;projects: BillingV2BreakdownProject[];};+ const orgNameById = new Map(orgs.map((org) => [org.id, org.name]));const byOrg = new Map<string, TScopeAccumulator>();- orgs.forEach((org) => byOrg.set(org.id, { name: org.name, isRoot: org.isRoot, orgLevelCount: 0, projects: [] }));+ orgs.forEach((org) =>+ byOrg.set(org.id, {+ name: org.name,+ isRoot: org.isRoot,+ rootOrgId: org.rootOrgId,+ orgLevelCount: 0,+ projects: []+ })+ );rows.forEach((row) => {let target = byOrg.get(row.orgId);@@ -887,7 +897,7 @@ export const licenseV2ServiceFactory = ({// An organization that left the tree between the count and this read still holds metered// units. Folding them into the root would inflate the figure the root org's own usage view// shows, so the scope keeps its own row- target = { name: "Deleted organization", isRoot: false, orgLevelCount: 0, projects: [] };+ target = { name: "Deleted organization", isRoot: false, rootOrgId: null, orgLevelCount: 0, projects: [] };byOrg.set(row.orgId, target);}if (!row.projectId) {@@ -912,6 +922,7 @@ export const licenseV2ServiceFactory = ({orgId,name: scope.name,isRoot: scope.isRoot,+ parentOrgName: scope.rootOrgId ? (orgNameById.get(scope.rootOrgId) ?? null) : null,count,orgLevelCount: scope.orgLevelCount,projectsdiff --git a/backend/src/ee/services/license-v2/license-v2-types.ts b/backend/src/ee/services/license-v2/license-v2-types.tsindex f2abdd82e2..4914208cdf 100644--- a/backend/src/ee/services/license-v2/license-v2-types.ts+++ b/backend/src/ee/services/license-v2/license-v2-types.ts@@ -371,6 +371,9 @@ export type BillingV2BreakdownScope = {orgId: string;name: string;isRoot: boolean;+ // Name of the root org this sub-org belongs to; null on a root itself. The instance-wide breakdown+ // lists several trees flat, so a sub-org row is unattributable without it.+ parentOrgName: string | null;count: number;// Units created on the org itself rather than inside one of its projects. Always 0 for a dimension// with no project attribution (see hasProjectDetail).diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.tsindex 9e4507b05e..ca90884392 100644--- a/frontend/src/hooks/api/billingV2/types.ts+++ b/frontend/src/hooks/api/billingV2/types.ts@@ -379,6 +379,7 @@ export type BillingV2BreakdownScope = {orgId: string;name: string;isRoot: boolean;+ parentOrgName: string | null;count: number;orgLevelCount: number;projects: BillingV2BreakdownProject[];diff --git a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsxindex 4b150f7850..371892e330 100644--- a/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/UsageBreakdownSheet.tsx@@ -90,9 +90,10 @@ type ScopeRowProps = {scopedCount: number;unit: string;hasProjectDetail: boolean;+ showParentOrg: boolean;};-const ScopeRow = ({ scope, scopedCount, unit, hasProjectDetail }: ScopeRowProps) => {+const ScopeRow = ({ scope, scopedCount, unit, hasProjectDetail, showParentOrg }: ScopeRowProps) => {const scopeTint = scope.isRoot ? "bg-org/85" : "bg-sub-org/85";const orgLevelTint = "bg-neutral/85";const canExpand = hasProjectDetail && scope.count > 0;@@ -105,7 +106,14 @@ const ScopeRow = ({ scope, scopedCount, unit, hasProjectDetail }: ScopeRowProps)<ScopeIconclassName={cn("size-3.5 shrink-0", scope.isRoot ? "text-org" : "text-sub-org")}/>- <span className="truncate">{scope.name}</span>+ <span className="flex min-w-0 items-baseline gap-2">+ <span className="truncate">{scope.name}</span>+ {showParentOrg && scope.parentOrgName && (+ <span className="min-w-0 truncate text-xs font-normal text-muted">+ {scope.parentOrgName}+ </span>+ )}+ </span></span><CountShare count={scope.count} total={scopedCount} unitLabel={pluralizeUnit(unit)} /></div>@@ -399,6 +407,7 @@ const BreakdownBody = ({scopedCount={scopedCount}unit={unit}hasProjectDetail={hasProjectDetail}+ showParentOrg={isInstanceScope}/>)}@@ -453,6 +462,7 @@ const BreakdownBody = ({scopedCount={scopedCount}unit={unit}hasProjectDetail={hasProjectDetail}+ showParentOrg={isInstanceScope}/>))}</div>