feat(billing): record admin usage limit overrides as arrangements
Merged
ET
5d ago+735+735+012345678901234567890123456789-164-164-012345678901234567890123456789
Part of twentyhq/core-team-issues#2997. Builds on #30373 (per-member AI credit override), now on main.
What
- Admin panel usage limits can only be created and deleted. The admin update mutation is gone; workspace settings keep their own update.
- Each create writes a
LIMIT_OVERRIDEarrangement pointing to the operator usage-limit row, in the same transaction. Delete revokes it in the same transaction. - The admin create takes a
label(defaultOTHER) and an optionalcomment, set from Reason and Comment fields in the modal when billing is on. The Comment field starts with what is granted (scope, period and value) and follows the value until the operator edits it, so the arrangement keeps what was granted once the usage limit row is deleted. - Create takes an optional
endsAt, which must be in the future and needs billing enabled. When billing is on, the admin modal has an optional end date field. An hourly cron deletes, in one query per workspace, the usage limits of overrides whose end date has passed. The cron does nothing when billing is off. - Admin modal: an existing override is read-only with Reset. The limits table has an Ends column: the override's end date, or Never.
SettingsDatePickerInputnow applies the clicked day and can sit above a dialog, andBillingArrangementLabelis registered as a GraphQL enum. Both are the same change as in #30271, so either PR can merge first.- The override service, expiry cron and job live in
usage-limit/instance-override/, on top ofUsageLimitModuleandBillingArrangementModule, so billing never imports usage-limit. The arrangement is written and ended throughBillingArrangementService(insertArrangement,endLimitOverride).
Known gaps
- Enforcement does not check
endsAt: an ended override stays enforced until the expiry cron deletes its row, so up to an hour, or longer if the queue or worker is down.
Testing
- Server and front typecheck clean on the changed files, lint and format clean, unit tests pass.
workspace-usage-limits.integration-spec.tscovers the admin panel with billing off, including the refused end date. It runs in CI.- The arrangement writes (grant, revoke, expiry) have no automated test: billing suites do not run in CI, so the billing-only suite was dropped.