Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct type filter for LocalDevelopmentUser #1744

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

oskogstad
Copy link
Collaborator

Description

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

@oskogstad oskogstad requested a review from a team as a code owner January 28, 2025 11:47
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a modification to the authorization scope logic in the AuthorizationPolicy class. The change specifically alters the field filtering mechanism within the GetAll method, adjusting the condition for identifying string-based literal fields. This modification impacts how authorization scopes are collected and filtered, potentially changing the method's behavior in determining which fields are processed.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs Modified field filtering logic in GetAll method, changing the condition from checking declaring type to checking field type for string literals

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs (2)

26-29: Consider adding validation for non-null and non-empty scopes.

While the field filtering logic is correct, consider adding additional validation to ensure we never collect null or empty scope strings, as these could cause issues in authorization checks.

 private static ReadOnlyCollection<string> GetAll() =>
     typeof(AuthorizationScope)
         .GetFields()
         .Where(x => x.IsLiteral && !x.IsInitOnly && x.FieldType == typeof(string))
         .Select(x => (string)x.GetRawConstantValue()!)
+        .Where(x => !string.IsNullOrEmpty(x))
         .ToList()
         .AsReadOnly();

Line range hint 1-29: Consider documenting the authorization scope format.

The authorization scopes follow a specific format (e.g., digdir:dialogporten.serviceprovider). Consider adding XML documentation to describe this format and any validation rules.

 internal static class AuthorizationScope
 {
+    /// <summary>
+    /// Authorization scopes following the format: organization:service[.resource][.action]
+    /// Examples: digdir:dialogporten.serviceprovider, altinn:system/notifications.condition.check
+    /// </summary>
     public const string EndUser = "digdir:dialogporten";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9281fc and 40a3fde.

📒 Files selected for processing (1)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Dry run deploy apps / Deploy job sync-resource-policy-information-job to test
  • GitHub Check: Dry run deploy apps / Deploy job sync-subject-resource-mappings-job to test
  • GitHub Check: build / build-and-test
🔇 Additional comments (1)
src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs (1)

27-27: Verify the impact of the field type filtering change.

The change from checking the declaring type to checking the field type (x.FieldType == typeof(string)) appears to be more precise for filtering string constants. However, we should verify that this doesn't accidentally exclude any required authorization scopes.

Let's verify the impact:

✅ Verification successful

The change fixes a critical bug in scope collection

The modification from x.DeclaringType == typeof(string) to x.FieldType == typeof(string) is actually a critical bug fix. The old condition was incorrect as it checked if the declaring type was string (which would never be true since the declaring type is AuthorizationScope). The new condition correctly filters for string constants, which is what we want for collecting authorization scopes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare the authorization scopes before and after the change
# by analyzing the git history and checking field declarations

# Check the field declarations in the current and previous versions
git log -p -- src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs | grep -A 1 "public const"

# Verify if there are any other string constants in related authorization files
rg "public const|internal const" src/**/Authorization/**/*.cs

# Check for any test failures related to authorization scopes
rg "AuthorizationScope" src/**/*Test*.cs

Length of output: 234


Script:

#!/bin/bash
# Find and show the AuthorizationPolicy file content
fd -e cs AuthorizationPolicy.cs | xargs cat

# Find all string constants in the codebase that might be related to authorization
ast-grep --pattern 'public const string $_ = $_'

# Find test files related to authorization
fd -e cs -g '*Test*.cs' | xargs rg -l "AuthorizationScope|AuthorizationPolicy"

Length of output: 2694

@oskogstad oskogstad merged commit fa30ebe into main Jan 28, 2025
23 checks passed
@oskogstad oskogstad deleted the fix/fix-scopes-on-local-development-user branch January 28, 2025 11:50
arealmaas pushed a commit that referenced this pull request Jan 28, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.47.3](v1.47.2...v1.47.3)
(2025-01-28)


### Bug Fixes

* **graphql:** Use correct type filter for LocalDevelopmentUser
([#1745](#1745))
([14ff138](14ff138))
* Use correct type filter for LocalDevelopmentUser
([#1744](#1744))
([fa30ebe](fa30ebe))


### Miscellaneous Chores

* **deps:** update dependency npgsql.entityframeworkcore.postgresql to
9.0.3 ([#1734](#1734))
([195443f](195443f))
* **deps:** update dependency verify.xunit to 28.9.0
([#1735](#1735))
([73d1ddb](73d1ddb))
* **deps:** update dependency vitest to v3
([#1732](#1732))
([9e67931](9e67931))
* **deps:** update dependency vitest to v3.0.2
([#1733](#1733))
([f32a0e2](f32a0e2))
* **deps:** update opentelemetry-dotnet monorepo to 1.11.0
([#1736](#1736))
([75c7a24](75c7a24))
* Include chores in the changelog
([#1525](#1525))
([d9281fc](d9281fc))
* Set 20% otel sample rate for all apps in yt01
([#1737](#1737))
([09c9ce9](09c9ce9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants