refactor(infra-billing): dedupe the site-ownership check shared by GET and PORTAL - #6167
Merged
pedrofrxncx merged 1 commit intoAug 18, 2026
Merged
Conversation
…T and PORTAL INFRA_BILLING_GET and INFRA_BILLING_PORTAL each hand-rolled the identical lowercase+dedupe-slugs, load-owned-slugs, reject-unowned check. Extract it into resolveOwnedSlugs() in a new ownership.ts and call it from both. Net: -20 lines duplicated logic / +23 lines shared helper, behavior unchanged (byte-identical logic, just relocated + parameterized on ctx/orgId).
pedrofrxncx
deleted the
refactor/infra-billing-dedupe-ownership-check-w2
branch
August 18, 2026 14:08
decocms Bot
pushed a commit
that referenced
this pull request
Aug 18, 2026
PR: #6167 refactor(infra-billing): dedupe the site-ownership check shared by GET and PORTAL Bump type: patch - decocms (apps/api/package.json): 4.225.0 -> 4.225.1 - @decocms/native (apps/native/package.json): 4.225.0 -> 4.225.1 Deploy-Scope: server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Source: C1 duplication —
apps/api/src/tools/infra-billing/get.tsandportal.tseach contained the identical 8-line block (lowercase+dedupe requested slugs, load the org's owned slugs, reject any unowned slug) verbatim.Payoff: one home for a security-relevant check (this is the gate that stops one org reading another org's infra usage/plan/invoices by guessing a site slug) means a future fix to it can't be applied to one call site and missed in the other.
Change: extracted the block into
resolveOwnedSlugs(ctx, orgId, siteSlugs)in a newapps/api/src/tools/infra-billing/ownership.ts, and call it from both tools. Byte-identical logic, just relocated — no behavior change. Net diff: -20 duplicated lines / +23 shared-helper lines (one-time cost, future callers add zero).Verify:
cd apps/api && bunx tsc --noEmit(clean) andbun test apps/api/src/deco-legacy/infra-billing.test.ts(32 pass, unchanged) confirm nothing about the ownership check's behavior moved.Checks run locally:
bun run fmt,bunx tsc --noEmit(apps/api),bun test apps/api/src/deco-legacy/infra-billing.test.ts,bunx oxlinton the 3 changed files — all clean. Full CI validates the rest.Summary by cubic
Deduplicates the infra-billing site-ownership check used by GET and PORTAL into a shared helper, keeping behavior identical. Centralizing this security gate avoids divergence and ensures fixes apply to both endpoints.
resolveOwnedSlugs(ctx, orgId, siteSlugs)inapps/api/src/tools/infra-billing/ownership.ts(lowercase + dedupe, load owned slugs, throw on unowned; returnsslugsandownedSlugs).apps/api/src/tools/infra-billing/get.tsandapps/api/src/tools/infra-billing/portal.tswith the helper.Written for commit 9bfaca0. Summary will update on new commits.