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: restore dialog action #1702

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

Fargekritt
Copy link
Contributor

Description

Created new endpoint for restoration of soft deleted dialogs
Modified enitity librarty enabling granular opting out of individual features

Related Issue(s)

#1543

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)

@Fargekritt Fargekritt requested a review from a team as a code owner January 16, 2025 14:37
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive implementation for dialog restoration in the Dialogporten system. The changes span multiple components, including the domain, application, infrastructure, and web API layers. Key modifications include adding a new restoration endpoint, creating domain events for dialog restoration, updating entity handling mechanisms, and introducing more granular filter controls for unit of work operations. The implementation allows for restoring soft-deleted dialogs while preserving their original state and generating appropriate domain events.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.Application/Externals/IUnitOfWork.cs Removed WithoutAggregateSideEffects() method, added DisableAggregateFilter(), DisableVersionableFilter(), DisableUpdatableFilter(), and DisableSoftDeletableFilter() methods
src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs Added IAggregateRestoredHandler interface implementation, added OnRestore method
src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs New record type for dialog restoration events
src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs Replaced WithoutAggregateSideEffects() with new filter disable methods, added SaveChangesOptions class
src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpoint.cs New endpoint for restoring dialogs
src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs Renamed HandleAggregateEntities to HandleAuditableEntities, added more comprehensive entity handling

Possibly related issues

  • Implement restoration of dialogs #1543: This PR directly implements the dialog restoration feature described in the issue, addressing all the specified acceptance criteria, including generating restoration events, retaining system labels, and handling both deleted and non-deleted dialog scenarios.

Possibly related PRs

Suggested reviewers

  • elsand
  • arealmaas

Finishing Touches

  • 📝 CodeRabbit is generating docstrings... (♻️ Check again to generate again)

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

🧹 Nitpick comments (5)
src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs (1)

5-10: LGTM! Consider adding XML documentation.

The domain event structure is well-designed with appropriate properties for tracking dialog restoration. Consider adding XML documentation to describe the purpose of each property, especially the relationship between Process and PrecedingProcess.

 public sealed record DialogRestoredDomainEvent(
+    /// <summary>
+    /// The unique identifier of the restored dialog.
+    /// </summary>
     Guid DialogId,
+    /// <summary>
+    /// The service resource associated with the dialog.
+    /// </summary>
     string ServiceResource,
+    /// <summary>
+    /// The party involved in the dialog.
+    /// </summary>
     string Party,
+    /// <summary>
+    /// The current process identifier, if any.
+    /// </summary>
     string? Process,
+    /// <summary>
+    /// The preceding process identifier, if any.
+    /// </summary>
     string? PrecedingProcess) : DomainEvent, IProcessEvent;
src/Digdir.Library.Entity.EntityFrameworkCore/IEntityOptions.cs (2)

3-47: Consider providing default values documentation.

The interface is well-structured and documented. However, it would be beneficial to document the default behavior when these options are not explicitly set.

Add default value documentation to each property:

     /// <summary>
     /// Gets a value indicating whether the soft deletable filter is enabled.
+    /// Default value: true
     /// </summary>
     bool EnableSoftDeletableFilter { get; }

6-47: Consider providing implementation guidance.

The interface provides good flexibility for entity handling, but consider adding implementation examples or guidance in the interface documentation.

Add interface-level documentation:

 /// <summary>
 /// Interface for configuring entity handling behavior options.
+/// <example>
+/// Typical implementation might look like:
+/// <code>
+/// public class EntityOptions : IEntityOptions
+/// {
+///     public bool EnableSoftDeletableFilter => true;
+///     public bool EnableImmutableFilter => true;
+///     // ... other properties
+/// }
+/// </code>
+/// </example>
 /// </summary>
 public interface IEntityOptions
tests/k6/tests/serviceowner/dialogRestore.js (1)

49-64: Add test for concurrent modification scenario.

While the current test thoroughly verifies successful restoration, consider adding a test case for concurrent modification where an incorrect ETag is provided. This would verify the 412 Precondition Failed response.

describe('Restore with incorrect ETag', () => {
    let incorrectEtag = '00000000-0000-0000-0000-000000000000';
    let r = restoreDialog(dialogId, incorrectEtag);
    expectStatusFor(r).to.equal(412);
});
src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs (1)

65-67: Add XML documentation explaining the IsModified state preservation.

The logic for preserving the IsModified state is correct, but it would benefit from documentation explaining why this state needs to be preserved and its implications for concurrency control.

+    /// <summary>
+    /// Attempts to set the original revision while preserving the IsModified state.
+    /// This is crucial for maintaining proper concurrency control during operations
+    /// like restoration where we need to track both the original revision and any
+    /// modifications made during the current transaction.
+    /// </summary>
     internal bool TrySetOriginalRevision<TEntity>(
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86b84c5 and 3355c89.

📒 Files selected for processing (15)
  • src/Digdir.Domain.Dialogporten.Application/Externals/IUnitOfWork.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Restore/RestoreDialogCommand.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogQuery.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs (4 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpoint.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpointSummary.cs (1 hunks)
  • src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs (2 hunks)
  • src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs (2 hunks)
  • src/Digdir.Library.Entity.EntityFrameworkCore/IEntityOptions.cs (1 hunks)
  • tests/k6/tests/serviceowner/all-tests.js (2 hunks)
  • tests/k6/tests/serviceowner/dialogRestore.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpointSummary.cs
🔇 Additional comments (17)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Restore/RestoreDialogCommand.cs (1)

59-63: Verify the necessity of disabling multiple filters

Lines 59-63 disable several entity framework filters before saving changes. Confirm that disabling Updatable, SoftDeletable, and enabling concurrency checks are required for the restore operation and do not have unintended side effects on other entities or operations.

src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs (2)

54-56: Review the impact of moving BeginTransactionAsync

The BeginTransactionAsync method has been moved to a different location in the file (lines 54-56). Verify that this relocation does not affect the initialization order or any dependencies that rely on the method's position within the class.


113-116: Ensure proper usage of HandleAuditableEntities

In lines 113-116, HandleAuditableEntities is called with _saveChangesOptions. Confirm that _saveChangesOptions is configured correctly and that the method handles all necessary entity types as intended.

src/Digdir.Domain.Dialogporten.Application/Externals/IUnitOfWork.cs (1)

19-22: Breaking change: Verify all usages of WithoutAggregateSideEffects()

The removal of WithoutAggregateSideEffects() in favor of granular filter controls is a good architectural decision. However, this is a breaking change that requires verification of all existing usages.

tests/k6/tests/serviceowner/all-tests.js (1)

12-12: LGTM! Test integration looks good.

The dialogRestore test has been properly integrated into the test suite following the existing pattern.

Also applies to: 27-27

src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpoint.cs (3)

20-32: LGTM! Well-structured endpoint configuration.

The endpoint follows RESTful conventions and properly documents response types. Authorization is correctly configured using the ServiceProvider policy.


34-50: LGTM! Robust request handling with proper error cases.

The implementation correctly:

  • Handles concurrency using ETags
  • Returns appropriate status codes (204, 404, 412)
  • Uses pattern matching for clean error handling

53-59: LGTM! Clean and focused request model.

The request model correctly handles the dialog ID and optional ETag for concurrency control.

tests/k6/tests/serviceowner/dialogRestore.js (3)

14-23: LGTM! Well-structured test setup.

The helper function and test variables are properly initialized. The restoreDialog function correctly handles the optional ETag parameter.


43-47: LGTM! Good idempotency test.

The test correctly verifies that restoring a non-deleted dialog is idempotent by checking both the status code and unchanged ETag.


66-68: LGTM! Proper test cleanup.

The cleanup ensures proper test isolation by purging the test dialog.

src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs (2)

22-23: LGTM! Appropriate interface implementations.

The entity correctly implements IEventPublisher and IAggregateRestoredHandler to support the restoration functionality.


88-90: Consider handling related entities during restoration.

While the basic restoration event is correctly published, consider whether related entities (Transmissions, Content, SearchTags, etc.) need special handling during restoration. For example, you might need to:

  • Restore related entities' states
  • Validate relationships
  • Update timestamps
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogQuery.cs (1)

118-119: LGTM! Granular control over entity tracking.

The replacement of .WithoutAggregateSideEffects() with .DisableUpdatableFilter() and .DisableVersionableFilter() provides more precise control over which entity tracking features are disabled when saving changes.

src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs (1)

129-130: LGTM! Consistent implementation of granular entity tracking.

The changes align with the service owner implementation, maintaining consistency across the codebase in how entity tracking is controlled.

src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs (2)

18-18: LGTM! Enhanced flexibility with options parameter.

The addition of IEntityOptions parameter allows for more configurable entity handling behavior.


27-57: LGTM! Well-structured conditional feature handling.

The implementation properly segregates different entity features:

  • Aggregate operations (create, update, delete, restore)
  • Updatable entity handling
  • Versionable entity handling

Each feature can now be independently controlled through the options parameter, improving modularity and maintainability.

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Caution

No docstrings were generated.

Comment on lines +205 to +208
// Although the entity framework supports all the options,
// enabling some of them ia an incredibly bad idea. Therefore,
// only some of them have setters until the day we actually
// have a use case for them.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Although the entity framework supports all the options,
// enabling some of them ia an incredibly bad idea. Therefore,
// only some of them have setters until the day we actually
// have a use case for them.
// Although the Entity Framework supports all the options,
// enabling some of them is an incredibly bad idea. Therefore,
// only some of them have setters until the day we actually
// have a use case for them.

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.

3 participants