feat(billing): Credits Manager role lets Operators issue and revoke credit grants [urgent] - #1775
Merged
Merged
Conversation
…redit grants Adds a seeded system role, Credits Manager (`credits_manager`), carrying `nyxid:billing:credit_grants:write`. An Operator holding it (directly or through a group) may issue and revoke one-off credit grants; Admins keep full access and regular users gain nothing from the role. Allowances and recurring schedules remain admin-only. `GET /users/me` adds `capabilities.manage_credit_grants` so Admin -> Credits shows grant controls to Credits Managers while allowance and schedule controls stay behind canAdminWrite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
📊 Code coverage
Gate: line coverage must stay at or above the threshold. Ratchet plan (W21): Backend → 55%, CLI → 50%, Frontend → 30% by quarter end. |
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.
Priority: urgent. We need non-admins (Operators) to be able to grant credits without giving them full platform Admin.
What changes
credits_manager), seeded at startup, with permissionnyxid:billing:credit_grants:write.require_credit_grant_manager(handlers/admin_helpers.rs) passes for every Admin, and for an Operator whose direct or group roles carry that permission. Regular users holding the role are still refused.POST /admin/credits/grantsandDELETE /admin/credits/grants/{id}now use that check. Allowances and recurring schedules stay admin-only. Credit list endpoints are unchanged (Operators could already read them).GET /users/me: addscapabilities.manage_credit_grants. This is an additive field; older frontends ignore it.canManageCreditGrants. Allowance and schedule controls keepcanAdminWrite.No new environment variables and no migration. The role is created by the existing system-role seed.
How to use it
An Admin assigns Credits Manager to a user who is already an Operator, in Admin → Users → Roles. The Operator sees grant controls after their next page load. Revoking works from the same Roles section: it previously hid Revoke for every system role, and now hides it only for the Admin, Operator and User platform roles.
Tests
credits_manager_operator_issues_and_revokes_grants_only:operator_reads_credit_admin_surfaces_but_cannot_mutate_themstill passes, so a plain Operator stays read-only.canManageCreditGrantsunit tests.cargo test -p nyxid --bin nyxid-server -- billing_credits role_service handlers::users: 58 passed.types/api.test.tsandadmin-credits-safety.test.tsx: passed.tscand eslint: clean.🤖 Generated with Claude Code