Refactor auth extractor - #369
Draft
wumbabum wants to merge 5 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Axum request-parts extractor to centralize “organization admin” authorization checks (SuperAdmin global access or Admin scoped to the organization_id in the route path), along with integration-style tests using the existing mock DB/auth-session setup.
Changes:
- Introduces
OrganizationAdminAccessextractor that validatesorganization_idpath params, verifies the organization exists, and enforces admin authorization via the authenticated user’s roles. - Adds integration tests (behind
mockfeature) covering Admin, SuperAdmin, and unauthorized scenarios. - Exposes the new extractor module via
web::extractors::mod.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/src/extractors/organization_admin_access.rs | New admin-authorization extractor for organization-scoped routes + tests. |
| web/src/extractors/mod.rs | Registers the new organization_admin_access extractor module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+71
to
+75
| .any(|r| { | ||
| r.role == domain::users::Role::SuperAdmin && r.organization_id.is_none() | ||
| || r.role == domain::users::Role::Admin | ||
| && r.organization_id == Some(organization_id) | ||
| }) |
| && r.organization_id == Some(organization_id) | ||
| }) | ||
| .then_some(OrganizationAdminAccess(organization_id)) | ||
| .ok_or((StatusCode::UNAUTHORIZED, "UNAUTHORIZED".to_string())) |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
web/src/extractors/organization_admin_access.rs:75
- The boolean expression inside
.any()mixes&&and||without parentheses. Rust precedence makes it work today, but it’s easy to misread and fragile to future edits; adding explicit grouping (or splitting into named booleans) will make the authorization rule unambiguous.
.any(|r| {
r.role == domain::users::Role::SuperAdmin && r.organization_id.is_none()
|| r.role == domain::users::Role::Admin
&& r.organization_id == Some(organization_id)
})
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.
Description
WIP
GitHub Issue: [Closes|Fixes|Resolves] #your GitHub issue number here
Changes
Testing Strategy
describe how you or someone else can test and verify the changes
Concerns
describe any concerns that might be worth mentioning or discussing