feat(catalogs): org members see their organization's catalogs (chat#1938)

Merged
SW
4mo ago
+250-30

Implements item 1 of recoupable/chat#1938.

Merge order: docs#288 → this PR. The docs PR is the contract; this fulfills it.

Problem

Artists already flow through organizations; catalogs do not. selectAccountCatalogs was .eq("account", accountId) with no org join, and the chat client calls /api/accounts/${accountId}/catalogs with the logged-in user's id — so nothing ever queries the org's id and an org-owned catalog is invisible to every member.

Querying the org id explicitly does not work either: canAccessAccount 403s a member asking for their own org's catalogs, because an org account is generally not a member of its own org.

Change

account IN (accountId, ...the account's organization ids), reusing the existing getAccountOrganizations, then deduplicated by catalog id.

This mirrors checkAccountArtistAccess, which already resolves org membership for artists — so there is one mental model for "what can this account see" rather than two. Membership is resolved at read time rather than duplicated per member at write time, so access follows the org as people join and leave instead of a snapshot taken at insert.

No schema change. An organization is a row in accounts, so account_catalogs.account can already hold an organization id.

Scope — nothing existing changes

Org catalogs are a new concept, and this alters the visibility of zero existing rows. Measured on prod 2026-08-05: 0 of 117 account_catalogs rows are owned by an organization account, so on merge this surfaces nothing new. It is the prerequisite that makes org-owned catalogs readable; creating them lands in the write PRs.

Deliberately not done: widening the union so members see each other's personal catalogs. That would expose 53 existing catalogs to colleagues — 83 people on Rostrum Pacific alone — without anyone opting in. Existing catalogs stay private to whoever created them.

Tests — TDD, RED before GREEN

New lib/supabase/account_catalogs/__tests__/selectAccountCatalogs.test.ts. Ran against the old implementation first: 5 failed, 1 passed (only the unchanged error path passed). After the change: 6/6 green.

TestAsserts
no organizationsqueries ["acc_1"] only — byte-identical behaviour to today
belongs to two orgsqueries ["acc_1", "org_1", "org_2"]
owned directly and via an orgcatalog returned once
null organization_id rowsskipped, not passed to the query
org id equal to the account idnot duplicated in the filter
query errorstill throws Failed to fetch account_catalogs: …

Full suites green: lib/catalog, lib/supabase/account_catalogs, lib/organizations, lib/supabase/account_organization_ids — 31 files, 197 tests passed. tsc --noEmit clean for the changed files; eslint and prettier clean.

Preview verification of the live endpoint to follow on this PR once the deployment is up.


Summary by cubic

Org members can now see their organization’s catalogs across the API. Implements chat#1938 by resolving owner ids (account + orgs) at read time and using them for both list and item endpoints.

  • New Features

    • Adds getCatalogOwnerIds (account + orgs) and uses it in catalog list, measurements, and access checks so listed org catalogs open without 404s.
    • Deduplicates catalogs by id across owners; behavior is unchanged when the account has no orgs.
  • Refactors

    • Selectors now take owner id arrays: selectAccountCatalogs(accountIds) and selectAccountCatalog({ accountIds, catalogId }), capped at one row.
    • Adds focused tests for owner resolution, deduping, and error paths; no schema changes.

Summary by CodeRabbit

  • Bug Fixes
    • Account catalog listings now include catalogs owned by the account and its organizations.
    • Duplicate catalogs are automatically removed while preserving the existing display order.