Skip to content

feat(platform): billing sets an org's apps and quotas (tenancy step 6) - #307

Merged
Yoshiofthewire merged 1 commit into
masterfrom
feat/org-apps-entitlements
Nov 26, 2026
Merged

Yoshiofthewire merged 1 commit into
masterfrom
feat/org-apps-entitlements

Conversation

@Yoshiofthewire

Copy link
Copy Markdown
Member

In one line: billing can now turn apps on and off for an organisation, with per-app quotas, through the platform API, so /api/suite/orgs tells each app which orgs it serves (tenancy build plan step 6).

What changed

  • POST /platform/v1/orgs and PATCH /platform/v1/orgs/{id} take apps, keyed by OAuth client ID: {"kycalendar": {"enabled": true, "quotas": {...}}}. Until now any apps field was refused.
  • Each app sees only its own entry (enabled, quotas) in /api/suite/orgs, and a change takes a new org revision, so ?since= finds it. An unchanged entry takes none.
  • Turning an app off ends the org's tokens, codes and client sessions for that app in the same transaction, as any lost access does.
  • 400 invalid_apps, changing nothing (the rest of the body included), for an unknown client, a missing enabled, or quotas that are not a JSON object of at most 4 KiB. Quotas are stored canonical (sorted keys, numbers exact); omitted quotas keep the stored ones. Staff's access_mode is untouched.
  • Seats were already enforced by triggers on every path. A new test races the last free seat across four store handles.
  • Single-tenant: unchanged (the platform API does not run there).

Review this

  • internal/store/org_apps.go setOrgAppsTx: the write, the revision bump and the revocation on disable. A missed revocation would leave a disabled app's tokens live.
  • internal/store/platform_orgs.go: NewOrg.Apps is omitempty, so a create without apps keeps the same create_request_hash as before (billing_ref replays).
  • Safe to skip: docs (AGENTS.md, spec status, CHANGELOG).

Checked

  • Full go test -race ./... on SQLite and the CI postgres package set on PostgreSQL 17 (K host k83), plus go vet, gofmt and scripts/check-test-gate.sh. One PostgreSQL test unrelated to this change, TestExportOutlastsTheIdleTimeout (a deliberate 20 ms idle-in-transaction limit), failed in schema setup on the loaded host. It passed 3 of 3 when rerun alone.
  • TestPlatformOrgApps and TestSeatRaceAcrossReplicas on both backends.
  • 9 mutations, each killed by its test: create without apps, patch without apps, no revision bump, no revocation on disable, enabled not required, no quota size limit, quotas not required to be an object, every entry treated as changed, no seat trigger.

Not checked: a live billing service. The e2e harness (KyCalendar S1) is what exercises that.

Decided for you

  • apps is a partial update: apps not named keep their row, and an app is switched off with enabled: false (the row stays so the app learns it was turned off) rather than by leaving it out.
  • GET /orgs/{id} does not list apps. The spec doesn't ask for it, and billing holds what it sent.
  • Errors use a new invalid_apps code rather than invalid_request.

You need to: nothing.

Detail

Body shape. apps: {client_id: {enabled: bool (required), quotas?: object}}. The client must have an app_registry row. Quotas are decoded with UseNumber and re-encoded, so key order and spacing never cause a spurious revision, and large integers stay exact (9007199254740993 round-trips).

Audit. platform.org_created / platform.org_updated carry apps: {client: enabled} for the entries that changed.

Tests. TestPlatformOrgApps (create with apps; each app's view; holder access and /api/suite/apps; token revoked on disable; 6 refused bodies with nothing changed; replay; same apps under a new key take no revision; stale revision refused). TestSeatRaceAcrossReplicas (16 concurrent pending adds for one free seat: exactly one succeeds, the rest ErrSeatLimit). TestPlatformCreateOrg now expects invalid_apps for an unregistered client.

Mutation run (k83, SQLite): every line KILLED with the failing assertion; script in the run log, not committed.

🤖 Generated with Claude Code

POST and PATCH /platform/v1/orgs take apps, keyed by OAuth client ID:
{client_id: {enabled, quotas?}}. Each app reads its own entry from
/api/suite/orgs after the change, which takes a new org revision.
Quotas are stored canonical, at most 4 KiB, and kept when omitted;
staff's access_mode is untouched. An unknown client, a missing
enabled or bad quotas are 400 invalid_apps and change nothing.

Disabling an app runs the lost-access revocation, so the org's
tokens, codes and client sessions for it end at once.

Seats were already triggers; a new test races the last seat across
four store handles on both backends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyidentity-server-307, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire
Yoshiofthewire added this pull request to the merge queue Nov 26, 2026
Merged via the queue into master with commit 9be2a01 Nov 26, 2026
15 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/org-apps-entitlements branch November 26, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant