Skip to content

refactor(admin): extract shared owner-or-admin check helper - #316

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:refactor/admin-01-helper
Jul 28, 2026
Merged

refactor(admin): extract shared owner-or-admin check helper#316
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:refactor/admin-01-helper

Conversation

@thlpkee20-wq

Copy link
Copy Markdown
Contributor

Closes #305

The canonical admin-only gate (`require_admin`) was already extracted
prior to this PR and is used consistently across ~20 admin-gated
entrypoints — so the main remaining duplication was a different,
narrower pattern: `settle`, `settle_all`, and
`transfer_service_ownership` each inlined the same "caller is admin or
the service's `ServiceMetadata.owner`" comparison.

Extracted a pure `is_owner_or_admin()` predicate and applied it at all
three call sites. Behavior is unchanged: each call site still loads its
own `owner` and panics with its own pre-existing error code (`settle`
uses `NotPendingAdmin`, the other two use `Unauthorized`), so this is
not an ABI or rejection-code change.

Test plan

Note

Depends on #315 (unrelated pre-existing test fix) for a fully green
`cargo test`; that PR is independent of this one.

settle, settle_all, and transfer_service_ownership each inlined the
same "caller is admin or the service's ServiceMetadata.owner"
comparison. Extracted a pure is_owner_or_admin() predicate and applied
it at all three call sites. Behavior is unchanged: each call site still
loads its own owner and panics with its own pre-existing error code
(settle uses NotPendingAdmin, the other two use Unauthorized), so no
ABI or rejection-code change.

The canonical admin-only gate (require_admin) was already extracted
prior to this change and is used consistently across ~20 admin-gated
entrypoints; this closes the one remaining duplicated authorization
pattern (owner-or-admin, a narrower check than admin-only).
@mikewheeleer

Copy link
Copy Markdown
Contributor

clean and focused @thlpkee20-wq — appreciated. merging 💪

@mikewheeleer
mikewheeleer merged commit 2d91d33 into Agentpay-Org:main Jul 28, 2026
1 check failed
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.

Extract the repeated admin check into a shared helper

2 participants