Commit Graph
142 Commits
Author SHA1 Message Date
Sharang Parnerkar 76b836653a fix(onprem): only directory users join a workspace
In directory mode the registry attached any Keycloak user found by
e-mail. On an installation the realm also holds our local staff accounts
(onprem keycloak/staff-account.sh): a workspace admin could add one to
their team (201 added), giving our support account workspace attributes
and membership. Found in the test install.

Now only a user with a federation link (from the AD) counts, for the
first admin and for members; a local account answers not_in_directory
like an unknown address. The cloud is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1b821baa7b)
2026-11-20 17:08:48 +01:00
Sharang Parnerkar afe62e4795 feat(onprem): mails come from the installation, not from us
On APP_ENV=onprem the registry's mails (new findings, published documents)
no longer carry our company signature, address, register entry, contact
address or legal pages. They say the installation sent them, name the
customer's contact (MAIL_CONTACT) and link the customer's imprint and
privacy notice (LEGAL_IMPRINT_URL, LEGAL_PRIVACY_URL), each only when set.

mail.View gets a Site; the zero value is the cloud, so cloud mails stay as
they were (checked byte for byte against the previous templates) apart from
the spelling "Breakpilot", also in the default sender name. The legal line
moved from every text template into signature.tmpl.

On-prem the registry also refuses to start when MAIL_FROM, PORTAL_URL,
INVITE_REDIRECT_URI or LEGAL_* point at breakpilot.com.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6058a94254)
2026-11-20 17:08:48 +01:00
Sharang Parnerkar 30cd577a33 fix(onprem): the cloud admin keeps tenant_status trial
Only on-prem passes the workspace's status to Keycloak for its first admin;
a cloud demo workspace with an admin wrote demo instead of trial (pinned by
a test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d8cb363d5c)
2026-11-20 17:08:48 +01:00
Sharang Parnerkar 90ae11ae42 feat(onprem): directory users instead of invitations
On-prem every account comes from the customer's AD through Keycloak's
federation, so an AD admin answered email_taken and invitations asked for a
new password. The Keycloak adapter gets a directory mode (DirectoryUsers,
on with APP_ENV=onprem):

- The first admin and invited members are existing directory users,
  attached to the organization with their role. No local user is created,
  no execute-actions mail is sent (invite status "added", audit user.added /
  keycloak.admin_added).
- An unknown address (or one outside the admitted AD groups) answers 404
  not_in_directory. For the workspace's admin it is checked before the
  workspace is created, and the adapter looks the user up before creating
  the organization, so nothing is left behind.
- Resend answers 409 no_invite_mail; directory members are never pending.
- Member lists read the roles from the user when Keycloak lists a federated
  member with its LDAP attributes only (seen with Keycloak 26.8).
- The admin address is normalized once for lookup, store and Keycloak.

Checked against Keycloak 26.8.1 with a Samba AD (the test install in
platform/onprem, realm with UNSYNCED federation and realm-policy.sh).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b8206c553f)
2026-11-20 17:08:48 +01:00
Sharang Parnerkar b30b5e3f1c feat(onprem): refuse unknown product keys, no trials in the catalog, tighter tests
- Start fails when PRODUCTS or a URL override names no catalog product.
- The on-prem catalog sets supports_trial=false (the portal hides the button).
- Test that seeded cloud provision URLs are never called on-prem, with a
  cloud control; the outbox test gets its cloud control too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3e42b1ceb8)
2026-11-20 17:08:48 +01:00
Sharang Parnerkar a4fb318773 feat(onprem): APP_ENV=onprem for a customer's own node
The registry on a customer's node must never reach a Breakpilot host and
must not run the cloud's commercial machinery.

- APP_ENV=onprem: no ERP (nothing queued, webhook off), no trial (new
  workspaces start active, the ladder never escalates by time), and the
  trial-offer, trial-terms, catalog/trial request and admin trial routes
  answer 404 not_available.
- PRODUCTS, PRODUCT_LAUNCH_URLS, PRODUCT_PROVISION_URLS: one store
  decorator applies the product list and URLs to every catalog read
  (catalog, activation, provisioning, entitlement checks). On-prem has no
  seeded URLs, so provisioning goes only to the local products. Checked at
  start ({id} in provision URLs, absolute http(s)).
- On-prem start fails when the values leave something to a cloud or dev
  default (auth off, no authz rules, ephemeral licence key, portal, invite,
  sender, LLM gateway) or set an ERP or contract documents.
- SMTP_TLS=starttls|tls|none: a plain relay inside the customer's network;
  no AUTH without encryption.
- Migration 0032: the Werkpilot text no longer names our LLM host.

Cloud behaviour is unchanged without the new variables (tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2f6fa5f3e8)
2026-11-20 17:08:42 +01:00
sharangandSharang Parnerkar c6de35858e feat(connections): connect two workspaces by code (#138) (#145)
ci / shared (push) Successful in 12s
ci / image (push) Successful in 38s
ci / test (push) Successful in 6m30s
## What

- **Codes:** two workspaces connect by code. One administrator creates a code; another workspace's administrator enters it, and the two are connected at once. Each side sees only the other's display name.
- **Ending:** either side can end a connection. Archiving a workspace ends all of its connections. When a workspace is purged, the other side keeps the ended connection under the name it knew.
- **Product routes:** products (Prüfwerk's supplier SBOM releases first) list a tenant's active connections and check one before each delivery, under a new route group `connections.read`.

## Why

Closes #138. This is phase 4 of platform/pruefwerk#1028. Prüfwerk's agent is on stage and already calls the two internal routes; without them the release screen warns that connections can't be read (see the comment on #138).

Linked milestone: **n/a** (Prüfwerk #1028, phase 4)

## How

**Routes:**

| Call | Group | Answer |
|---|---|---|
| `POST /v1/tenants/{id}/connection-invites` | tenants.write | `201 {id, code, created_at, expires_at}`; the code is in this answer only |
| `GET /v1/tenants/{id}/connection-invites` | tenants.read | open codes, without the codes |
| `DELETE /v1/tenants/{id}/connection-invites/{invite}` | tenants.write | `204`, withdraws an unused code |
| `POST /v1/tenants/{id}/connections` `{code}` | tenants.write | `201 {id, peer_name, state, created_at, ended_by_us}` |
| `GET /v1/tenants/{id}/connections` | tenants.read | `{items: [...]}`, newest first |
| `POST /v1/tenants/{id}/connections/{connection}/end` | tenants.write | `200`; ending one that has ended answers it unchanged |
| `GET /v1/internal/tenants/{id}/connections?state=active` | **connections.read** | `{items: [{id, peer_tenant_id, peer_name}]}`; 404 for an unknown tenant |
| `GET /v1/internal/connections/{connection}` | **connections.read** | `{active, tenant_ids}`; 404 for an unknown id |

The two internal answers match what `compliance-agent/src/registry.rs` reads. A test pins the `items` key, because the agent defaults a missing key to "no connections".

**Codes:**
- 160 random bits (`crypto/rand`), shown as eight groups of four base32 letters.
- Stored as SHA-256 only, looked up by hash; case, spaces and dashes don't matter.
- Valid for 14 days, single use, at most 20 open per workspace.
- Every code that doesn't work gets the same 404 `invalid_code`: unknown, used, expired, withdrawn, the workspace's own, or either workspace archived.
- 409 `already_connected` when the two are connected already; the code then stays open.
- Entering codes is limited to 20 per hour per workspace, and per person when the call names one (`keyRateLimiter` now takes its limit as an argument; CI licences keep theirs). A call from the portal's own client that names nobody has only the workspace limit. Otherwise every workspace would share one limit through that client. **portal#201 must send `X-Portal-User-Subject`.**

**Redeeming** is one transaction. `SELECT … FOR UPDATE` on the code, insert the connection, then mark the code used. A partial unique index allows at most one connection per pair of workspaces that hasn't ended. A race test has two workspaces enter one code at the same time: exactly one connects.

**Active** is derived on every read: not ended, both workspaces exist, and neither is archived. So no delivery can go to an archived workspace, even if writing the end failed.

**Ending on archive:** every status change passes through `syncTenantStatus`, which now ends an archived workspace's connections. The admin purge calls the same step again before `DeleteTenant`, as a safety net. The foreign keys are `ON DELETE SET NULL`, with name snapshots, so the other side keeps its history.

**Audit:** `connection.invite_created`, `connection.invite_withdrawn`, `connection.created` and `connection.ended` go into both workspaces' logs.
- The acting side's entry names the actor.
- The other side's entry is a system entry with `by: peer`: no person, IP or user agent, only the connection id and the acting side's display name.
- Ends caused by archiving carry `reason: tenant_archived`.

**Product routes refuse user tokens** (403 `FORBIDDEN_CLIENT`), whatever groups the token's client holds, because they carry the peer's tenant id.

**Who may:** user tokens need IT_ADMIN or OWNER in their own workspace (the existing team gate, `IsTenantAdmin`). Another workspace's administrator gets a 404. The portal calls as its service client, naming the person in `X-Portal-User-*`.

**Side fix:** the Postgres `GetTenant` now answers a non-UUID id as not found (404), as the memory store does. It was a 500, which the new internal route hit.

## Test plan

- [x] Unit tests: route groups in `authz_test`, roles and cross-tenant scoping in `connections_scope_test`, and the OpenAPI contract cases.
- [x] Integration tests on memory **and Postgres (testcontainers)** in `connections_test.go`, run locally:
  - connect, list, product view, check, and the re-connect after end;
  - every invalid code gives the same answer, including expiry with an injected clock;
  - archive, then purge;
  - unknown ids;
  - the rate limit;
  - the redeem race.
- [x] The whole `internal/server` suite runs against Postgres locally (`go test -count=1 ./internal/server/`, 236 s, green). `-race` is green on the connection tests. `go vet` and `golangci-lint` v2.12.2: 0 issues.
- [ ] Playwright e2e: n/a, there's no UI here (portal#201).
- [ ] Manual smoke on stage after deploy, once `AUTHZ_RULES` carries the grant below. Prüfwerk's release screen should then show no warning.

## Risk

**Blast radius:** new tables and routes only. Existing routes change in two small ways: the `GetTenant` 500→404 for non-UUID ids, and the archive path now also ends connections.

**What could break:**
- **Migration number:** `0032` is also used by the open onprem PRs (#142/#143, `0032_werkpilot_description`). Whichever merges second must renumber. A duplicate version fails the migrations test loudly. I didn't pick 0033, because golang-migrate would silently skip a 0032 that merges after it.
- **Deployment grant:** the new group needs a grant in stage and prod `AUTHZ_RULES`. That config isn't in this repo: `pruefwerk-svc-stage:…,connections.read`, and the same for prod. Until it's added, Prüfwerk keeps getting 403.

**Rollback plan:** revert the PR and redeploy. The down migration drops both tables.

## Decided (2026-11-20, by the product owner)

- **Archived only** ends connections. A `halted` workspace keeps them, so a returning customer finds them again. Active stays false while a side is archived.
- **IT_ADMIN or OWNER** may create, enter and end, using the existing team gate rather than a new catalogue right.

## Open points for review

1. **Retention:** a purged workspace's display name stays visible to its former peers through the name snapshot, with no time limit. Should it be dropped after a while?
2. **Additions to the sketch:** the create answer now carries the invite `id`, which the withdraw route needs, and there's a list of open codes, without the codes.

## Checklist

- [x] Docs updated: the OpenAPI spec and the package doc in `connections.go` (no separate docs page for registry routes)
- [x] Audit events emitted for state changes
- [x] Secrets via Infisical, never in repo (none involved)
- [x] Migration is forward-only (new tables; down drops them)
- [x] Tenant scoping enforced on every DB query
- [x] OpenAPI spec updated
- [ ] `featureFlags.evaluate()`: n/a (nothing toggleable)
- [ ] CHANGELOG entry: n/a (generated by git-cliff on release)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #145
2026-11-20 08:54:44 +00:00
Sharang ParnerkarandClaude Opus 5.5 c8dd3ba4dc feat(avvfill): Unicode glyphs (Identity-H) instead of Windows-1252
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 9m6s
ci / image (pull_request) Skipped
With WinAnsi encoding, names like "Michał", "Yılmaz" or "Łódź" fell back to "staff fill it in", a path nobody watches yet. The value is now set as glyph ids of the embedded Geist Regular (Type0 / CIDFontType2, Identity-H) with a ToUnicode map, so any character the font has works and the text still extracts as written. Only control characters and characters without a glyph (e.g. CJK) are refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:23:57 +01:00
Sharang ParnerkarandClaude Opus 5.5 05673defd4 feat(contracts): fill the AVV from the company profile
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 8m26s
ci / image (pull_request) Skipped
A workspace whose company profile is submitted and whose Geschäftsleitung is named (Verantwortliche) now sees its AVV filled in: name with legal form, address, "Vertreten durch" and, as the owner decided, "Geschäftsleitung" on the Weisung line. The new package internal/legal/avvfill writes the details onto the released master as one incremental PDF update: the two content streams holding the blank lines are replaced, the underscores dropped and the value set in their place in Geist Regular at body size, inside the line's marked content. The master's bytes stay an untouched prefix, so its pin still holds; the result is deterministic and cached by master and details digest. Layouts are pinned per master SHA-256; a test makes every released AVV master have one.

Until then the master is listed with "missing" (profile, company_name, address, management) for the portal's hint; details that do not fit the form or the Windows-1252 character set give "manual" and a log line without the values. A staff upload still wins (filled_from: staff). The admin avv-values answer uses the same derivation; its Weisung is now "Geschäftsleitung" only. The legal form is no longer appended twice when the name writes it without spaces ("UG(haftungsbeschränkt)").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:10:45 +01:00
Sharang ParnerkarandClaude Opus 5.5 116bb83ddf feat(contractdocs): release the AVV 1.0.0 master
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m45s
ci / image (pull_request) Skipped
The owner released the AVV on 19.11.2026: Arbeitsstand 06, without a signature block (it is concluded with the main contract, § 12(1)), Stand 17.11.2026. The PDF is byte for byte the one in its release record FREIGABE_1.0.0.json (sha256 623aa518…). It is listed between AGB and TOM for every workspace; a workspace's own filled AVV still takes its place. The AVV contract status stays "not_concluded": listing the master concludes nothing.

Tests: released set and order, the master in the overview and as PDF, and the own-AVV-without-master path now on a catalogue without the master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 10:02:11 +01:00
Sharang ParnerkarandClaude Opus 5.5 37032e649e fix(usage): malformed tenant id lists no events on postgres
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 8m27s
ci / image (pull_request) Skipped
pgx reports an invalid UUID from rows.Err, not from Query, so GET /v1/usage/events?tenant_id=not-a-uuid answered 500 on Postgres and 200 on the memory store. It now returns an empty list on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:55:28 +01:00
Sharang ParnerkarandClaude Opus 5.5 b02bf254bc feat(erpsetup): registry user may read dunning, read only
The late-payment ladder (#134) reads Dunnings, which ERPNext lets only the Accounts roles read. The registry's API user holds Sales User only. erpsetup now adds a level-0 read rule for Sales User on Dunning through Frappe's permission manager (which first copies the standard rules, as the Role Permissions Manager UI does) and cuts a broader rule back to read only. The spec.go comment no longer claims Accounts User. Live ERP: the same rule was added by hand on 17.11.; the next run reports it as existing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:55:28 +01:00
sharang f6bb84933c Merge pull request 'feat(metering): count module users per tenant and month (t81, part 1)' (#136) from feat/module-user-count into main
ci / shared (push) Successful in 10s
ci / test (push) Successful in 6m51s
ci / image (push) Successful in 38s
2026-11-17 09:01:55 +00:00
sharang 2b3cea5974 Merge pull request 'feat(usage): add GET /v1/usage/summary aggregate route' (#135) from feat/usage-summary into main
ci / shared (push) Failing after 4s
ci / test (push) Successful in 7m45s
ci / image (push) Skipped
2026-11-17 08:33:49 +00:00
Sharang ParnerkarandClaude Opus 5.5 9af0d9f8e1 test(metering): low-entropy token sentinel for gitleaks
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 7m23s
ci / image (pull_request) Skipped
The first sentinel looked like an API key to gitleaks' generic rule. It
is a test value; its fingerprint goes into .gitleaksignore since the
commit is already pushed.

Refs: t81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:32:59 +01:00
Sharang ParnerkarandClaude Opus 5.5 692a9dd378 feat(metering): count module users per tenant and month
ci / test (pull_request) Failing after 26s
ci / image (pull_request) Skipped
ci / shared (pull_request) Failing after 3s
Daily Europe/Berlin job: Managed Git = members signed in to the tenant's
active instances; Werkpilot/Firmwerk = people with their own licence in
use in the month. Staff PUT for the Gitea admin token, staff and tenant
reads of the month's counts, POST /v1/internal/module-users/count on
demand (route group module-users). No invoicing yet (t72).

Refs: t81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:28:20 +01:00
Sharang ParnerkarandClaude Opus 5.5 f9ada789ea feat(gitea): list the users of a managed git instance
GET /api/v1/admin/users with a read:admin token in the Authorization
header, paged until an empty page. Errors carry no body, URL or token.

Refs: t81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:28:20 +01:00
Sharang ParnerkarandClaude Opus 5.5 7b9ae37be7 feat(store): module user counts and sealed git admin token (0031)
Migration 0031 adds managed_services.admin_token_enc (sealed, write-only),
module_user_days (Managed Git daily counts, month = peak day) and
module_users_seen (Werkpilot/Firmwerk people per month). Postgres and
Memory stores implement both.

Refs: t81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:28:20 +01:00
Sharang ParnerkarandClaude Opus 5.5 9138ac586b feat(usage): add GET /v1/usage/summary aggregate route
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Successful in 7m32s
ci / image (pull_request) Skipped
The portal's 30-day views folded at most 1000 events from the usage list,
so busy tenants saw figures that were too low. The summary aggregates
every matching event in the store (GROUP BY in Postgres, the same fold in
Memory): counts, quantity sums and the latest occurred_at per product and
metric, and counts and sums per UTC day and metric.

Same filters, tenant pinning for user tokens and route group (usage.read)
as GET /v1/usage/events, so the portal's service client needs no new
AUTHZ grant. Both stores share the filter (usageWhere / matches).

Refs: t80

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:17:47 +01:00
Sharang ParnerkarandClaude Opus 5.5 38b9a72eda feat(erp): restrict for late payment only after a mahnung
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m51s
ci / image (pull_request) Skipped
AGB § 10 allows restricting access only "trotz Mahnung und angemessener
Nachfrist". The ladder counted from the due date (restricted after 14,
halted after 30 days overdue) and escalated any warning after 14 days.

Now an overdue invoice alone means warning. The reconcile pass reads the
customer's submitted, unresolved ERPNext Dunnings; the earliest one that
names a still-open invoice sets the clock: restricted 14 days after its
posting date, halted a further 14 days after the restriction. A Mahnung
never halts directly, so a late-seen one errs in the customer's favour.
A failed Dunning read keeps the tenant on warning and is reported.

ERP_HALT_AFTER_DAYS defaults to 28 (was 30), so an expired trial is
read-only for 14 days instead of 16 before it is halted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:04:11 +01:00
Sharang ParnerkarandClaude Opus 5.5 2921fa0663 fix(contracts): TOMs are available once the released TOM is listed
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m24s
ci / image (pull_request) Skipped
The contracts overview reported the TOMs as "pending" unconditionally,
from before the TOM was released, so the portal showed "Wird
bereitgestellt" above the released TOM 1.0.0 on stage. The status is
now "available" when a TOM document is listed for the tenant (i.e.
released and CONTRACT_DOCUMENTS on), and stays "pending" otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 22:38:10 +01:00
Sharang ParnerkarandClaude Opus 5.5 0271c99ab7 test(contractdocs): plain condition for the released-set check (staticcheck QF1001)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m12s
ci / image (pull_request) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 22:14:12 +01:00
Sharang ParnerkarandClaude Opus 5.5 290fa64f6a feat(contractdocs): release AGB 1.0.0 and TOM 1.0.0
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 36s
ci / image (pull_request) Skipped
Released by the owner on 16.11.2026 (AGB SaaS AS06, TOM AS08, both
Stand 09.11.2026). The PDFs are byte for byte the released working
versions (release records FREIGABE_1.0.0.json next to them in the
document store); their SHA-256 are pinned in the table. They apply to
every workspace and are listed first, before the Leistungsbeschreibungen.

The AVV master stays out: it is on hold until the signature block and
§12(1) are decided internally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 22:06:16 +01:00
Sharang ParnerkarandClaude Opus 5.5 b7608e07ba test(roles): rank namespace check without double negation
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 7m0s
ci / image (pull_request) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-16 12:49:51 +01:00
Sharang ParnerkarandClaude Opus 5.5 bef4e31c05 feat(roles): functions of owner decision Nr. 2 in the catalogue
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 37s
ci / image (pull_request) Skipped
Catalogue r1-2026-11-16.1 adds the functions owner decision Nr. 2
(docgen#6 17878, 18011) names and that no R1 function already covers:
CVD-Verantwortung and Veröffentlichungsverantwortung (R5), Meldefreigabe,
Fristführung, Vorabprüfung, Weitergabe von Informationen and
Datenschutzfunktion (R2), and the R1 functions Erstzuordnung, Eskalation
and Einsichtsprotokollkontrolle. External holders as proposed in 18110
K-4. The safety check and product measures wait for the owner (K-1, K-2).

GET /role-dataset now names the current catalogue as catalogue_version
and the stored one as stored_catalogue_version. It named the stored one,
which the portal sends back on save: after any catalogue change every
save of an existing dataset was refused as catalogue_outdated, and
reloading answered the same version again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-16 12:48:02 +01:00
sharang 9cf4f7db05 Merge pull request 'feat(roles): company rule for separate determination and approval' (#129) from feat/company-rules into main
ci / shared (push) Successful in 12s
ci / test (push) Successful in 6m4s
ci / image (push) Successful in 40s
2026-11-12 17:17:58 +00:00
Sharang ParnerkarandClaude Opus 5.5 0f7cc29f10 feat(roles): company rule for separate determination and approval
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Successful in 5m51s
ci / image (pull_request) Skipped
docgen#4 Nr. 31 (AK-R3-030): the role dataset gets an optional section
company_rules with separate_approval ("Festlegung und Freigabe durch
verschiedene Personen"). Not set counts as off.

- The rule is maintained by whoever maintains the dataset (AM-3),
  stamped from the writer's token, and historised with the revisions.
- Older datasets decode unchanged and store no section.
- GET /v1/tenants/{id}/role-dataset/rules answers the rules now for
  Werkmeister (tenants.read) or a member of the tenant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-12 18:11:17 +01:00
Sharang ParnerkarandClaude Opus 5.5 fb7aea76a9 feat(tenants): staff may create the "breakpilot" workspace
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 5m52s
ci / image (pull_request) Skipped
The slug "breakpilot" was reserved (#32) so no customer could pose as
Breakpilot. Sharang decided (12.11.) that the company's own workspace
is app.breakpilot.com/breakpilot. Staff (a named staff member on the
admin client) may now create exactly this slug; everyone else, and
the trial offer's slug choice, still get reserved_slug. The other
reserved slugs stay closed to staff too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:58:54 +01:00
Sharang ParnerkarandClaude Opus 5.5 34921bd44e fix(intake): security reports outlive their workspace
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m5s
ci / image (pull_request) Skipped
Purging an archived workspace deleted its intake reports with it: every
intake table cascaded from tenants. Benjamin's decision Nr. 17 (docgen#6
17878, V-g): no automatic deletion of the reports when a workspace is
deleted.

The purge now refuses first, before any file or account is removed:
409 intake_retained while the workspace has reports. Migration 0030 makes
the database refuse as well (intake_reports → tenants ON DELETE RESTRICT),
and DeleteTenant maps that to ErrConflict. CountIntakeReports on both
stores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-12 14:25:53 +01:00
Sharang ParnerkarandClaude Opus 5.5 f4a9f937fb fix(authz): bundle labels as the portal names them; last admin message
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 6m10s
ci / image (pull_request) Skipped
The catalogue named CXO "Geschäftsleitung" and OWNER "Inhaber des
Arbeitsbereichs", while the portal shows "Geschäftsführung" and
"Inhaberschaft". The catalogue now takes the portal's names (version
2026-11-12.1), which also keeps the role "Geschäftsführung" apart from
the company function "Geschäftsleitung" of the role dataset.

The last-admin refusal named only IT_ADMIN; the guard holds for OWNER
too, so the message now says "the last administrator (IT_ADMIN or
OWNER)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-12 10:59:15 +01:00
Sharang ParnerkarandClaude Opus 5.5 2e6f360751 test(trial): status read shows a staff-extended trial end
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 5m52s
ci / image (pull_request) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:42:48 +01:00
Sharang ParnerkarandClaude Opus 5.5 d0b1287afb feat(trial): offer address in the contract overview
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Failing after 6m9s
ci / image (pull_request) Skipped
GET /v1/tenants/{id}/contracts carries street, postcode, city and
country of the trial offer, so the company profile can suggest the
registration address as the master data (portal#159, item 3; read
by portal#161). Only for the tenant's own activated offer, as the
rest of the trial block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:34:46 +01:00
Sharang ParnerkarandClaude Opus 5.5 0f8cc33888 feat(trial): GET /v1/trial-offers/{id} for the waiting page
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Successful in 5m33s
ci / image (pull_request) Skipped
The page that sent the offer waits for the e-mail confirmation. When
the link is opened on another device (a phone), that page stayed put
(portal#159, item 1). The status read lets it follow: the state and,
once active, the workspace slug and the trial dates. No e-mail or
company data in the answer; the offer id, which only the sending
browser has, is the key. Same authz group as the other offer routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:23:05 +01:00
Sharang ParnerkarandClaude Opus 5.5 351c7356fd test(server): the workers stop with their context; client addresses
ci / shared (pull_request) Successful in 11s
ci / image (pull_request) Skipped
ci / test (pull_request) Successful in 5m32s
The coverage gate sits at 70% and main is just above it; these cover
the mail, outbox and reconcile loops and clientIP, which no test ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 22:37:54 +01:00
Sharang ParnerkarandClaude Opus 5.5 79588bef05 feat(roles): the holders answer names the function
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 5m57s
ci / image (pull_request) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 22:15:34 +01:00
Sharang ParnerkarandClaude Opus 5.5 9c2e23a036 feat(roles): who holds a function (RBAC step 5)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Failing after 5m56s
ci / image (pull_request) Skipped
GET /v1/tenants/{id}/role-dataset/holders?function=…[&scope] answers
who holds a role-dataset function now: the holders in the scope, the
effective deputies of the function and open/filled/not applicable.
Werkmeister reads it (tenants.read) when a step names a function.

It shares the matching with /resolve, which now goes through it; for a
decision type, only deputies covering it count, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 22:14:54 +01:00
Sharang ParnerkarandClaude Opus 5.5 dc44eb22bb feat(authz): the new bundles are assignable (RBAC step 4)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m6s
ci / image (pull_request) Skipped
PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR and EXTERNAL
can be given to a member (catalogue 2026-11-11.1). Invitations and role
changes accept exactly the catalogue's assignable bundles.

The registry's own checks read the catalogue instead of role lists:
notification recipients, managed services and Prüfwerk settings. For
today's six bundles nothing changes (pinned against the 2026-11-10
tables); AUDITOR now reads managed services, and the new bundles get
the mails their capabilities name. Individual capabilities still do not
count in the registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 21:29:33 +01:00
Sharang ParnerkarandClaude Opus 5.5 fe05192182 feat(authz): individual capabilities per member (RBAC step 3)
ci / shared (pull_request) Successful in 26s
ci / test (pull_request) Successful in 6m7s
ci / image (pull_request) Skipped
A member can hold capabilities on top of their bundle. They live in the
Keycloak user attribute extra_capabilities, which the tenant-context
mapper puts into the token; the registry writes it like org_roles and
clears it when the member leaves.

- POST/DELETE /v1/tenants/{id}/members/{uid}/capabilities[/{cap}]
- a person who holds registry:members.manage grants, never on
  themselves, and only what they hold themselves
- an administration capability waits for a second person: open
  requests in capability_requests (0029), approve or reject under
  /v1/tenants/{id}/capability-requests
- a role change keeps the extras; the principal parses the claim, the
  registry's own checks still go by org_roles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 13:39:36 +01:00
Sharang ParnerkarandClaude Opus 5.5 19f2300934 feat(authz): the catalogue of rights (RBAC step 1)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 8m8s
ci / image (pull_request) Skipped
Capabilities, bundles and the two position variants, versioned in
code and served as GET /v1/authz/catalogue. Today's six roles are
bundles that reproduce the portal surfaces, the Werkmeister
permissions and the registry's own role checks; pin tests fail if
any of them drifts. Nothing reads the catalogue yet, so no right
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 22:46:34 +01:00
Sharang ParnerkarandClaude Opus 5.5 4c17affc1f feat(intake): page the pending list and say when a capture is settled
ci / shared (pull_request) Successful in 10s
ci / test (pull_request) Successful in 5m9s
ci / image (pull_request) Skipped
The pending list is across workspaces, oldest first; entries that keep
waiting in one workspace (no receiving workflow, not booked) could fill
every page and hide those of all others. GET /v1/internal/intake/pending
takes after=<entry id>, so the reader pages on with the last id it got.

Each item says whether its report's capture is settled
(capture_settled), so a reader paging on can hold a supplement back
until its capture is handed over, also when the capture was on an
earlier page. Without after the route answers as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 10:50:54 +01:00
Sharang ParnerkarandClaude Opus 5.5 cc4675c85d test(intake): plain error comparison in the store test
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m33s
ci / image (pull_request) Skipped
staticcheck flagged the double negation (tenant-registry#119).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 09:53:36 +01:00
Sharang ParnerkarandClaude Opus 5.5 bf83d0625e feat(intake): pending entries carry the newest receipt's handoff
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Failing after 1m32s
ci / image (pull_request) Skipped
So the receiving service can look up a handoff it already made before it
repeats one (tenant-registry#119).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 09:52:23 +01:00
Sharang ParnerkarandClaude Opus 5.5 b4583de691 feat(intake): record R1 security reports with one stable reference
ci / shared (pull_request) Successful in 27s
ci / test (pull_request) Failing after 1m58s
ci / image (pull_request) Skipped
docgen#6 slice 3, F01 (P-R1-K05 Fassung 4 M21, M13): the R1 intake keeps
a security notice unchanged with the time it arrived and gives it one
stable Eingangsreferenz (SH-YYYY-NNNNN), which is also the Meldereferenz
of the confirmation (F-1). Later information is a supplement to the same
reference, never a second report.

- migration 0028: intake_reports, intake_entries (capture and
  supplements), intake_receipts; all insert-only (trigger), one capture
  per report, one settling receipt per entry
- a person reports, lists and reads their own reports and adds to them
  with their own token (route group intake.user); others get 404, and
  no route returns the original text, since "Original einsehen" (F07,
  TV-1) does not exist yet
- werkmeister reads entries not settled yet (reference and the
  reporter's own answers, never the text) and writes receipts back:
  waiting, delivered, processed, refused (route group intake)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-10 09:50:37 +01:00
sharang 5525759392 feat(contracts): serve contract documents in Vertragsunterlagen (#118)
ci / shared (push) Successful in 12s
ci / test (push) Successful in 25m50s
ci / image (push) Successful in 35s
2026-11-09 12:59:20 +00:00
sharang f778cbb1a8 feat(erpsetup): quotes name the Leistungsbeschreibung versions (#117)
ci / shared (push) Successful in 13s
ci / test (push) Successful in 26m31s
ci / image (push) Successful in 40s
2026-11-09 10:25:59 +00:00
sharangandSharang Parnerkar 1332ad7bc5 feat(erpsetup): catalogue for Leistungsbeschreibung 1.0.0, opt-in -sync-catalog (#115)
ci / shared (push) Successful in 15s
ci / test (push) Successful in 26m35s
ci / image (push) Successful in 53s
Brings the ERPNext sales catalogue in line with the frozen Leistungsbeschreibungen 1.0.0. This PR changes code and tests only. No ERP was called; the live run is yours, using the erpsetup CLI.

## Dry run first (with the flag; only this path prints `field old → new`)

```sh
ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… ERP_WEBHOOK_SECRET=… \
  go run ./cmd/erpsetup -webhook-url https://registry.breakpilot.com/v1/internal/erp/webhook -sync-catalog -dry-run
```

(`ERP_LEAD_DOCTYPE` is optional, as before.) Leave out `-dry-run` for the real run.

## What a run does with and without `-sync-catalog`

| | without the flag (as today) | with `-sync-catalog` |
|---|---|---|
| New items, unit "Prüftag", their list prices | created | created |
| Item **description** | **updated (this already happens on every run today)** | updated |
| Item `item_name`, `disabled` | untouched | updated when they differ |
| Standard Selling `price_list_rate` (rows without a customer) | set once, never changed | updated when it differs |
| Customer-specific Item Prices | untouched | untouched |
| Quote print format (Mehrverbrauch row) | updated | updated |

**A plain run is not inert.** It creates the 5 new items, the new unit and 5 new prices, rewrites every changed description, and updates the quote template. Only names, the disabled flags and price changes wait for the flag. Nothing is ever deleted. Only the doctypes Item, Item Price and UOM are touched beyond what erpsetup already manages.

## Catalogue changes

| Code | Status | Price old → new (EUR) |
|---|---|---|
| PLT-CORE-CLD-STD/BUS/ENT | keep (name "Breakpilot …", new text) | 290 / 790 / 1990 (unchanged) |
| PLT-BNDL-CLD-STD | **new** Starter-Modulpaket | 990 |
| PLT-BNDL-CLD-ADD | **new** Weiteres Modul | 499 |
| CRA-CSA-CLD-STD | keep | **1490 → 490** |
| CRA-CSA-CLD-BUS | keep | **3990 → 1290** |
| CRA-CSA-CLD-ENT | keep | **9900 → 0** (Preis nach Vereinbarung: a quote shows 0,00 € unless the rate is entered by hand) |
| CRA-CSA-CLD-TGT | **new** extra Prüfobjekt / Monat | 5.99 |
| CRA-CSA-CLD-DAY | **new** Prüftag (unit Prüftag) | 9.99 |
| CRA-CSA-CLD-SCAN | **disable** | 12 (unchanged) |
| CRA-WBK-CLD-STD/BUS/ENT | **disable** | unchanged |
| DEV-WP-CLD-STD | keep ("Werkpilot Cloud") | 59 |
| DEV-WP-CLD-BUS/ENT | **disable** | unchanged |
| DEV-WP-OPR-*, DEV-FWK-OPR-*, INF-GIT-OPR-*, INF-CI-OPR-* | keep, new texts | unchanged |
| DEV-FWK-CLD-STD | keep ("Firmwerk Cloud") | 89 |
| DEV-FWK-CLD-BUS/ENT | **disable** | unchanged |
| INF-GIT-CLD-STD/BUS/ENT | keep, new texts | 190 / 390 / 790 |
| INF-GIT-CLD-USR | **new** extra user | 19 |
| INF-CI-CLD-STD/BUS/ENT | keep, new texts | 149 / 290 / 590 |

The item group stays "BreakPilot Abonnements".

Correction to the spec, applied here: PLT-CORE-CLD-STD no longer mentions "Rechnungen", because LB Plattform §2(3) says the portal provides no invoices. The text is now "Arbeitsbereich mit Anmeldung und Team für bis 25 Nutzer, Standard-Support. Module werden einzeln gebucht." No other item text mentions invoices, and a test now checks that none does.

## Other changes

- `sku.Disabled` is sent to ERPNext as the Item field `disabled: 1`. Disabled items stay in ERPNext so old documents keep working. Since the disabled items already exist on prod, their flag only changes with `-sync-catalog`.
- **Quote, Mehrverbrauch row:** "Zusätzliche Prüfobjekte werden mit {TGT} netto je Monat berechnet, Prüftage nach verbrauchtem Monatskontingent mit {DAY} netto (Leistungsbeschreibung Prüfwerk, Abschnitt 7)." If a rate is missing, the text says "gemäß der jeweils gültigen Preisliste" instead, per rate. If both are missing, one combined sentence is printed. Quotes with INF-GIT-CLD-STD/BUS/ENT or PLT-BNDL-* add the sentence on extra users (Leistungsbeschreibung Breakpilot Plattform, Abschnitt 4). The Jinja was parsed and rendered locally with jinja2 against mocks for eight item mixes.
- **Migration 0026** adds CRA-CSA-CLD-TGT and -DAY to the `pruefwerk` product. SCAN stays so old orders still map. The up is guarded so it can run twice; the down removes the two SKUs. `DefaultProducts` and the ERP mock's SKU list follow. **Run `migrate-up` with the deploy.** Without it, TGT/DAY lines on an order log "sales order item without catalog product".
- **0 € module lines:** nothing needed fixing. Neither the webhook path nor reconcile reads the rate: the webhook template sends only `item_code` and `qty`, and `SubscriptionPlan` has no rate. A new test covers both paths: a bundle order with modules at rate 0 and qty 15 gives an active tenant, plan standard, and seats 15 per module.

## Decisions the spec did not cover

1. **No Prüfwerk Mehrverbrauch sentence on Enterprise quotes.** CRA-CSA-CLD-ENT is "ohne Begrenzung". Edge case: a quote with both -STD and -ENT also prints no Prüfwerk sentence. The extra-users sentence is not affected.
2. The run without the flag still writes descriptions, as `Run` has done until now (see the table).
3. `-sync-catalog` only changes Item Price rows without a `customer`. If there are several such rows for an item, the run reports "not synced". If there are none, it creates the list price.
4. The quote template's Item Price lookup still has no customer filter (unchanged from before).
5. INF-GIT-OPR texts: STD uses the spec text exactly, so "kein Quellcode verlässt das Haus" is gone. BUS keeps "für mittelgroße Teams" and loses "schnellerer Patch-Rhythmus", like CI. ENT says "für große Entwicklungsorganisationen".
6. INF-CI-OPR texts differ only by size ("mindestens 2 vCPU / 4 GB" etc.); "für größere/umfangreiche Builds" was dropped.
7. DEV-WP-OPR and DEV-FWK-OPR texts: the tier phrase sits after "im eigenen Netz", e.g. "Werkpilot im eigenen Netz für mittlere Teams, mit einem vom Kunden betriebenen KI-Modell; …".
8. TGT/DAY quantities on an order or subscription count toward Prüfwerk `seats`, exactly as SCAN already does. Not changed here.
9. Bundle revenue goes to cost center Plattform (PLT-*). Module lines at 0 € book nothing on Prüfwerk, Firmwerk or Werkpilot. Whether to allocate it is an accounting decision for you.
10. The dry run prints texts in full (no truncation), so the wording can be read before it goes live.
11. `TestEverySKUHasAListPrice` now allows exactly one item at 0: CRA-CSA-CLD-ENT.
12. The ERP mock's `DefaultSKUs` now also lists PLT-BNDL-* and CRA-CSA-CLD-TGT/DAY.

## Tests

`go build ./... && go vet ./... && go test ./...` all pass. The Postgres testcontainers suites ran (podman socket) with no skips: server 463 s, migrations 32 s. New tests:

- catalogue consistency: unique codes, units, disabled set, prices including 5.99/9.99, brand spelling
- `TestSyncCatalog`: the dry run writes nothing and names every change; the run updates name, description, disabled and price and keeps the customer price; a second run makes no updates; without the flag only the description changes
- quote template phrases
- `TestMigrate_productsSeedMatchesDefaults`: seed equals `DefaultProducts`, 0026 applied twice, down
- `TestErp_zeroRateModuleLinesEntitle`: webhook and reconcile, memory and Postgres

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #115
2026-11-06 16:20:22 +00:00
sharangandSharang Parnerkar 32e10e0e13 feat(entitlements): Prüfwerk plan limits and Prüftag cap setting (t72) (#114)
ci / shared (push) Successful in 15s
ci / test (push) Successful in 26m37s
ci / image (push) Failing after 39s
Registry side of Prüfwerk metering (backlog t72). Stage first; nothing deployed.

## What changes

- **Entitlement check**: for `pruefwerk` the limits now always carry `included_targets`, `monthly_pruefungen` and `prueftag_cap`, with `null` meaning unlimited or no cap. The values come from one plan table in `internal/server/pruefwerk.go`:

  | Plan | SKU | included_targets | monthly_pruefungen | prueftag_cap |
  |---|---|---|---|---|
  | Standard | CRA-CSA-CLD-STD | 5 | 100 | the workspace's cap or null |
  | Business | CRA-CSA-CLD-BUS | 25 | 500 | the workspace's cap or null |
  | Enterprise | CRA-CSA-CLD-ENT | null | null | always null |

  The highest plan SKU in `config.skus` wins. A tenant with no plan SKU (trial, preview grant, SCAN-only order) gets Standard. The limits are built on a copy of `tenant_products.config`, so the existing keys stay and the stored config is not changed. Other products are unchanged.
- **Migration 0025** adds `tenant_product_settings(tenant_id, product, settings jsonb, updated_by, updated_at)`, PK `(tenant_id, product)`, with ON DELETE CASCADE. Both stores implement it (Postgres and Memory). `recomputeEntitlements` never touches this table, so the cap survives ERP recomputes.
- **`GET`/`PUT /v1/tenants/{id}/products/pruefwerk/settings`**: the body is `{"prueftag_cap": 0..10000 | null}`. Unknown keys, a missing key, non-integers and out-of-range values all return 400.
  - **User tokens** must be in their own tenant (404 otherwise) and have the IT_ADMIN, OWNER or FINANCE org role (403 `FORBIDDEN_ROLE` otherwise).
  - **Service clients** are gated by their route group, as for the company profile: GET needs `tenants.read`, PUT needs `tenants.write`. Staff come through the admin client with `X-Staff-*`.
  - **Audit**: a change is logged as `product_settings.changed` with `old`, `new`, `plan` and `applies`. A PUT that changes nothing writes nothing and logs nothing.
  - **Enterprise**: PUT still stores the cap and GET shows it with `cap_applies: false`, but the check sends `null`.
- **Usage metrics**: `prueftag.booked` and `target.extra` go through the existing `POST /v1/usage/events`. A test checks that both are stored once per idempotency key and that a repeat, even with a different quantity, counts as a duplicate. No update-in-place path, no invoicing, no ERP item or price changes.
- OpenAPI: the new path, a `PruefwerkSettings` schema, and the three keys described on `EntitlementCheck.limits`.

## Deploy note

Run **`migrate-up` (0025) before the new build takes traffic.** If reading the settings table fails, the Prüfwerk check returns 500 rather than silently sending `prueftag_cap: null`.

## Decisions not in the brief

1. OWNER is allowed alongside IT_ADMIN and FINANCE, because every other admin check in the registry treats OWNER like IT_ADMIN. Dropping it is a one-line change.
2. The registry enforces the org role only on user tokens. Service clients are trusted by route group (the portal checks roles for its users), which matches the company-profile route.
3. The plan table wins over same-named keys that a staff `activate` may have written into the config.
4. The settings response also carries `plan` and `cap_applies`. GET with nothing saved returns 200 with `prueftag_cap: null`.

## Tests

- `go build ./... && go vet ./...` pass.
- `go test -race ./...` passed with the Postgres harness, using rootless podman as the testcontainers backend.
- After two small edits I re-ran `-short` and the new and related tests against Postgres; all passed.
- New tests cover: plan resolution (STD, BUS, ENT, none, SCAN-only, mixed SKUs, JSONB `[]interface{}`); limits per plan, checking that null keys are present in the JSON rather than left out; settings validation; the role matrix with audit (user token, portal user, staff); a product client reading but not writing; the cap surviving an ERP recompute; the store contract on both stores; usage dedup for both metrics; and migration 0025 (table, one row per product, object check, cascade).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #114
2026-11-06 14:29:49 +00:00
sharang 286f50c5fb feat(invoiceintake): send every invoice mail on to DATEV from invoice@ (#110)
ci / shared (push) Successful in 12s
ci / image (push) Successful in 39s
ci / test (push) Successful in 26m6s
2026-11-02 11:59:00 +00:00
sharangandClaude Opus 5.5 b14d6f61f0 feat(store): public product documents may name their product (#109)
ci / shared (push) Successful in 13s
ci / test (push) Successful in 26m48s
ci / image (push) Successful in 42s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-10-30 10:36:20 +00:00
sharang 1691bf1be3 Merge pull request 'test: postgres harness no longer provisions at the live stage Prüfwerk' (#108) from fix/tests-no-stage-calls into main
ci / shared (push) Successful in 15s
ci / test (push) Successful in 27m10s
ci / image (push) Successful in 40s
2026-10-30 07:58:35 +00:00