Support multiple authorize policies - #329
Conversation
|
Warning Review limit reached
Next review available in: 53 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (23)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughThe generator now processes every ChangesAuthorization policy generation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AuthorizeAttributes
participant GeneratorTransform
participant RouteTemplate
participant GeneratedEndpoint
AuthorizeAttributes->>GeneratorTransform: provide all [Authorize] attributes
GeneratorTransform->>RouteTemplate: pass default flag and policy collection
RouteTemplate->>GeneratedEndpoint: emit default authorization
RouteTemplate->>GeneratedEndpoint: emit all configured policy requirements
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Immediate.Apis.Generators/ImmediateApisGenerator.Transform.cs`:
- Around line 50-64: Update the authorizeAttribute processing in the generator
transform to inspect named arguments for every AuthorizeAttribute, including
those with constructor arguments. Validate all named arguments without rejecting
supported Roles or AuthenticationSchemes, and let a named Policy override the
constructor-derived policy; ensure authorization attributes beyond the first are
also processed.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 041a686a-8de0-4dec-a79b-46019acf4d0a
📒 Files selected for processing (9)
src/Immediate.Apis.Generators/ImmediateApisGenerator.Models.cssrc/Immediate.Apis.Generators/ImmediateApisGenerator.Transform.cssrc/Immediate.Apis.Generators/Templates/Route.sbntxttests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Delete#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Get#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Patch#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Post#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Put#IA.Dummy.GetUsersQuery.g.verified.cs
|
Addressed in commit 494663f:
Roles and AuthenticationSchemes remain intentionally unsupported, consistent with IAPI0002 and the library documentation, which currently support policy-based authorization only. |
|
Full audit follow-up in commit 7666734:
Final local validation: 467 tests passed; net8.0/net9.0 changed-project builds passed; net10.0 solution build passed with 0 warnings/errors; package validation passed. |
afc8e6e to
459e13e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| var authorizeAttributes = attributes.Where(a => a.AttributeClass.IsAuthorizeAttribute).ToArray(); | ||
| if (authorizeAttributes.Length is 0) |
There was a problem hiding this comment.
| var authorizeAttributes = attributes.Where(a => a.AttributeClass.IsAuthorizeAttribute).ToArray(); | |
| if (authorizeAttributes.Length is 0) | |
| var authorizeAttributes = attributes.Where(a => a.AttributeClass.IsAuthorizeAttribute); | |
| if (!authorizeAttributes.Any()) |
| _ = global::Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExtensions.RequireAuthorization(endpoint,{{~ | ||
| for policy in method.authorize_policies | ||
| ~}}{{ " " }}"{{ policy }}"{{ if !for.last }},{{ end }}{{~ | ||
| end | ||
| ~}}); |
There was a problem hiding this comment.
| _ = global::Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExtensions.RequireAuthorization(endpoint,{{~ | |
| for policy in method.authorize_policies | |
| ~}}{{ " " }}"{{ policy }}"{{ if !for.last }},{{ end }}{{~ | |
| end | |
| ~}}); | |
| _ = global::Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExtensions.RequireAuthorization( | |
| endpoint | |
| {{~ for policy in method.authorize_policies ~}} | |
| , "{{ policy }}" | |
| {{~ end ~}} | |
| ); |
459e13e to
70ab263
Compare
|
Follow-up after maintainer review; this supersedes my earlier implementation notes. Addressed in
CI will validate the pushed commit. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@tests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method`=Get#IA.Dummy.GetUsersQuery.g.verified.cs:
- Around line 31-35: Update TransformEndpoint to emit the effective named policy
from AuthorizeAttribute.Policy when both policy arguments are specified,
preserving the expected "NamedPolicy" value instead of emitting the constructor
policy. Then regenerate the affected snapshots.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 719143cf-42d8-40a9-b540-01cb8ff6d05c
📒 Files selected for processing (10)
src/Immediate.Apis.Analyzers/InvalidAuthorizeAttributeAnalyzer.cssrc/Immediate.Apis.Generators/ImmediateApisGenerator.Transform.cssrc/Immediate.Apis.Generators/Templates/Route.sbntxttests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cstests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Delete#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Get#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Patch#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Post#IA.Dummy.GetUsersQuery.g.verified.cstests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Put#IA.Dummy.GetUsersQuery.g.verified.cs
🚧 Files skipped from review as they are similar to previous changes (9)
- tests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Post#IA.Dummy.GetUsersQuery.g.verified.cs
- tests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Put#IA.Dummy.GetUsersQuery.g.verified.cs
- tests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cs
- src/Immediate.Apis.Generators/Templates/Route.sbntxt
- tests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Patch#IA.Dummy.GetUsersQuery.g.verified.cs
- src/Immediate.Apis.Analyzers/InvalidAuthorizeAttributeAnalyzer.cs
- tests/Immediate.Apis.Tests/GeneratorTests/Snapshots/ApiAuthorizeTests.MapMethodWithMultipleAuthorizePoliciesTest_method=Delete#IA.Dummy.GetUsersQuery.g.verified.cs
- src/Immediate.Apis.Generators/ImmediateApisGenerator.Transform.cs
- tests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cs
Coverage Report for CI Build 31563875634Coverage decreased (-0.04%) to 96.304%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
Fixes #328
Summary
Tests
Summary by CodeRabbit
New Features
Bug Fixes
Tests