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

feat(webapi): Return 410 GONE for notification checks on deleted dialogs #1387

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Nov 4, 2024

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)

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for deleted entities in the notification condition query.
    • Added a new response type for deleted dialogs, improving clarity in error reporting.
  • Bug Fixes

    • Improved response handling for scenarios where a requested dialog has been deleted.
  • Tests

    • Introduced a new test case to verify correct behavior when querying a deleted dialog.
    • Refactored test methods for improved readability and maintainability.

@oskogstad oskogstad requested a review from a team as a code owner November 4, 2024 11:50
Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

📝 Walkthrough

Walkthrough

The changes involve updates to the NotificationConditionResult class and the NotificationConditionQueryHandler to incorporate a new return type, EntityDeleted, which indicates when a dialog entity has been deleted. The Handle method now checks for this state and returns the appropriate response. Additionally, the NotificationConditionEndpoint class has been modified to handle the deleted state in its error responses. The test suite has been updated to include tests for the new behavior, ensuring that the application correctly responds to deleted dialogs.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs Added EntityDeleted to NotificationConditionResult, updated Handle method to check for deleted dialogs.
src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs Enhanced error handling in HandleAsync to respond with GoneAsync for deleted resources.
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs Added test for deleted dialogs, refactored query creation logic, and updated existing tests to use new utility method.

Possibly related PRs


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

sonarqubecloud bot commented Nov 4, 2024

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 (2)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs (1)

Line range hint 26-57: Consider standardizing deleted resource handling

The introduction of EntityDeleted and the pattern of returning 410 GONE for deleted resources is a good practice. Consider applying this pattern consistently across other endpoints that might encounter deleted resources.

tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs (1)

89-110: LGTM: Good test coverage for deleted dialog scenario

The test effectively verifies the new 410 GONE response requirement. Consider enhancing it with additional test cases:

  1. Verify behavior when attempting to delete an already deleted dialog
  2. Test with different activity types to ensure consistent behavior
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 431fe16 and a5db9ca.

📒 Files selected for processing (3)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs (3 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs (4 hunks)
🔇 Additional comments (8)
src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs (1)

31-32: LGTM! Good use of HTTP status codes.

The implementation correctly distinguishes between "not found" (404) and "gone" (410) states, following REST best practices. This provides clear feedback to API consumers about whether a dialog doesn't exist or has been deleted.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs (3)

26-26: LGTM: Good addition of EntityDeleted to OneOf type

The addition of EntityDeleted to the union type is well-placed and aligns with the PR objective to handle deleted dialogs differently.


44-44: Consider documenting the IgnoreQueryFilters usage

While the addition of IgnoreQueryFilters() is necessary to detect deleted dialogs, it bypasses all global query filters. Consider adding a code comment explaining why this is needed.

Let's check for other global filters that might be affected:

#!/bin/bash
# Description: Check for other global query filters that might be affected
# Expected: Find any HasQueryFilter calls on DbSet<DialogEntity>

# Search for query filter definitions
ast-grep --pattern 'modelBuilder.Entity<DialogEntity>().HasQueryFilter($_)'

53-57: Verify the dialog deletion mechanism

The deletion check is implemented correctly. However, let's ensure the Deleted property is properly maintained.

Let's verify the dialog deletion implementation:

✅ Verification successful

Based on the search results, I can now provide a final response about the dialog deletion mechanism:

Dialog deletion is properly implemented with soft delete pattern

The codebase shows a robust implementation of dialog deletion:

  • The Deleted property is part of ISoftDeletableEntity interface with proper soft delete functionality
  • Deletion is handled through SoftDelete() method which sets Deleted = true and DeletedAt timestamp
  • The deletion state is consistently checked across queries and commands
  • Tests verify that deletion sets DeletedAt timestamp correctly
  • Domain events (DialogDeletedDomainEvent) are raised when a dialog is deleted
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify dialog deletion implementation
# Expected: Find where Deleted property is set

# Search for dialog deletion logic
ast-grep --pattern 'dialog.Deleted = $_'

# Search for soft delete configuration
ast-grep --pattern 'modelBuilder.Entity<DialogEntity>().$_Delete$_'

Length of output: 171


Script:

#!/bin/bash
# Let's try different approaches to find dialog deletion related code

# Search for dialog deletion in method implementations
ast-grep --pattern 'void Delete($$$) { $$$dialog$$$Deleted$$$}'

# Search for Deleted property definition
ast-grep --pattern 'public bool Deleted { get; set; }'

# Search for any references to dialog deletion using ripgrep
rg -i "dialog.*delet" -A 2 -B 2

# Look for soft delete configurations in DbContext
rg -i "softdelete|deletefilter" -A 2 -B 2

Length of output: 76949

tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs (4)

3-3: LGTM: Import addition is appropriate

The added import for DeleteDialogCommand is necessary for the new test case and follows the existing import organization pattern.


43-43: LGTM: Good refactoring to reduce code duplication

The extraction of query creation logic into a shared method improves maintainability and follows the DRY principle.


78-78: LGTM: Consistent refactoring application

The test maintains its behavior while benefiting from the shared query creation method.


112-120: LGTM: Well-structured helper method

The CreateNotificationConditionQuery method is well-designed with sensible defaults and improves code maintainability.

@oskogstad oskogstad merged commit 198bebd into main Nov 4, 2024
24 checks passed
@oskogstad oskogstad deleted the feat/notification-condition-return-410-gone-for-soft-deleted-dialogs branch November 4, 2024 12:31
arealmaas added a commit that referenced this pull request Nov 5, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.28.0](v1.27.1...v1.28.0)
(2024-11-05)


### Features

* update swagger name generation
([#1350](#1350))
([94c5544](94c5544))
* **webapi:** Add ExternalReference to dialog search result
([#1384](#1384))
([431fe16](431fe16))
* **webapi:** Return 410 GONE for notification checks on deleted dialogs
([#1387](#1387))
([198bebd](198bebd))


### Bug Fixes

* Add system user id to identifying claims
([#1362](#1362))
([16f160d](16f160d))
* **e2e:** Use pagination in sentinel
([#1372](#1372))
([a1df0ff](a1df0ff))
* fixed placement of referenced workflow-file
([#1365](#1365))
([49c1d80](49c1d80))
* workaround for github number error in dispatch workflow
([#1367](#1367))
([06ee356](06ee356))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@coderabbitai coderabbitai bot mentioned this pull request Nov 5, 2024
4 tasks
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