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: Return distinct actions in GetAlinnActions #1298

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

elsand
Copy link
Member

@elsand elsand commented Oct 15, 2024

Description

GetAltinnActions now removes duplicate action/resource tuples, which results in simpler XACML requests and dialog tokens.

Related Issue(s)

  • N/A

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)

Summary by CodeRabbit

  • New Features

    • Improved handling of duplicate actions in the Altinn authorization process, ensuring a cleaner and more accurate list of actions.
  • Bug Fixes

    • Enhanced test coverage for action retrieval, ensuring the correct actions and attributes are validated.

@elsand elsand requested a review from a team as a code owner October 15, 2024 12:35
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

📝 Walkthrough

Walkthrough

The pull request modifies the GetAltinnActions method in the DialogEntityExtensions class to include a grouping operation that consolidates duplicate AltinnAction entries. It groups actions by their Name and AuthorizationAttribute, ensuring that duplicates are removed from the returned list. Additionally, the test method GetAltinnActionsShouldReturnCorrectActionsForTransmissionAuthorizationAttributes in DialogEntityExtensionsTests has been updated to reflect these changes, enhancing its coverage by checking for specific action names and attributes.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/DialogEntityExtensions.cs Modified GetAltinnActions to group AltinnAction entries by Name and AuthorizationAttribute, removing duplicates from the returned list.
tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/DialogEntityExtensionsTests.cs Updated GetAltinnActionsShouldReturnCorrectActionsForTransmissionAuthorizationAttributes test to include specific action names and attributes, enhancing coverage.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • arealmaas: Suggested as a reviewer for their potential expertise in the relevant codebase.

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 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

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

🧹 Outside diff range and nitpick comments (3)
src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/DialogEntityExtensions.cs (1)

23-24: Approved: Effective duplicate removal implemented

The changes successfully address the PR objective by eliminating duplicate action/resource tuples. This optimization will indeed simplify XACML requests and dialog tokens as intended.

For a minor performance improvement, consider using DistinctBy instead of GroupBy and Select. It's more concise and potentially more efficient for this use case.

Here's a suggested optimization:

- .GroupBy(x => new { x.Name, x.AuthorizationAttribute })
- .Select(g => g.First()) // Remove duplicates by grouping
+ .DistinctBy(x => new { x.Name, x.AuthorizationAttribute })

This change maintains the same functionality while potentially improving performance.

tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/DialogEntityExtensionsTests.cs (2)

46-51: Great job: Assertions significantly improved and more specific.

The new assertions provide a much more thorough check of the GetAltinnActions method's output:

  1. Verifying the exact number of actions (9) instead of just non-emptiness.
  2. Checking for specific action names and their corresponding authorization attributes.

These changes align well with the updated test setup and likely reflect the expected behavior of the GetAltinnActions method, including deduplication of actions.

For improved readability, consider extracting the expected action count to a constant:

const int ExpectedActionCount = 9;
Assert.Equal(ExpectedActionCount, actions.Count);

This would make it easier to update the expected count if the test setup changes in the future.


Line range hint 1-57: Excellent work: Test changes align well with PR objectives.

The modifications to this test method strongly support the PR objectives:

  1. The test setup now includes duplicate actions, allowing verification of the deduplication process.
  2. The specific count assertion (9 actions) confirms that duplicates are indeed eliminated.
  3. The detailed assertions for various action/attribute combinations ensure correct handling of different scenarios.

These changes effectively verify that the GetAltinnActions method now returns distinct actions, which should lead to simplified XACML requests and dialog tokens as intended.

To further enhance test coverage, consider adding an assertion to explicitly verify that no duplicate action/attribute combinations exist in the result:

Assert.Equal(actions.Count, actions.Distinct().Count());

This would provide an additional safeguard against potential future regressions in the deduplication logic.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0deef0f and c406c9d.

📒 Files selected for processing (2)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/DialogEntityExtensions.cs (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/DialogEntityExtensionsTests.cs (3 hunks)
🧰 Additional context used
🔇 Additional comments (3)
src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/DialogEntityExtensions.cs (1)

23-24: Verify impact on downstream code and test coverage

While the changes effectively remove duplicates and optimize the output, it's crucial to ensure that any downstream code relying on GetAltinnActions can handle the potentially reduced number of actions.

Please run the following script to check for usages of GetAltinnActions in the codebase:

Review the results to ensure that all usages are compatible with the new behavior.

Additionally, you mentioned in the PR description that relevant automated tests have been added. Could you please provide more information about these tests? It would be helpful to review them to ensure they cover both the new behavior and potential edge cases.

If you need help creating or expanding the test coverage for this change, I'd be happy to assist. Would you like me to propose some additional test cases?

tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/DialogEntityExtensionsTests.cs (2)

3-3: LGTM: Import statement added for new action types.

The new import statement for Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actions is appropriate and necessary for the DialogApiAction and DialogGuiAction types used in the updated test setup.


17-30: Excellent: Test setup enhanced with more comprehensive scenarios.

The modifications to the ApiActions and GuiActions properties significantly improve the test coverage by including:

  1. Duplicate actions (e.g., multiple "read" actions)
  2. Actions with different authorization attributes
  3. New action types ("apiread" and "guiread")

The change in the first transmission's AuthorizationAttribute to "bar" aligns well with the new API action setup.

These changes will help ensure that the GetAltinnActions method correctly handles various scenarios, including deduplication and proper attribute assignment.

Also applies to: 33-33

@elsand elsand changed the title Return distinct actions in GetAlinnActions fix: Return distinct actions in GetAlinnActions Oct 15, 2024
@elsand elsand merged commit 49948b2 into main Oct 18, 2024
22 of 24 checks passed
@elsand elsand deleted the fix/remove-duplicate-actions branch October 18, 2024 15:45
oskogstad pushed a commit that referenced this pull request Oct 22, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.26.0](v1.25.0...v1.26.0)
(2024-10-22)


### Features

* Add masstransit outbox system
([#1277](#1277))
([bc04860](bc04860))


### Bug Fixes

* **infrastructure:** use correct networking for servicebus
([#1320](#1320))
([4fb42bb](4fb42bb))
* Return distinct actions in GetAlinnActions
([#1298](#1298))
([49948b2](49948b2))
* Upgraded Altinn.ApiClients.Maskinporten, specify
TokenExchangeEnvironment
([#1328](#1328))
([5156799](5156799))

---
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