refactor(admin): extract shared owner-or-admin check helper - #316
Merged
mikewheeleer merged 1 commit intoJul 28, 2026
Merged
Conversation
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).
Contributor
|
clean and focused @thlpkee20-wq — appreciated. merging 💪 |
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.
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
(`test_transfer_service_ownership_genuine_transfer_emits_event`)
is pre-existing on unmodified `main` (verified independently) and
unrelated to this change — see fix(test): correct cross-call event-count assumption in ownership-transfer test #315 for the standalone fix.
Note
Depends on #315 (unrelated pre-existing test fix) for a fully green
`cargo test`; that PR is independent of this one.