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

Merged
merged 25 commits into from
Feb 10, 2025
Merged

feat: Restore dialog action #1702

merged 25 commits into from
Feb 10, 2025

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

Warning

Rate limit exceeded

@oskogstad has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b79609b and e01e4e7.

📒 Files selected for processing (1)
  • docs/schema/V1/swagger.verified.json (1 hunks)
📝 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.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs Updated Handle method to use new filter methods instead of WithoutAggregateSideEffects()
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Restore/RestoreDialogCommand.cs Added RestoreDialogCommand and RestoreDialogCommandHandler for dialog restoration logic
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogQuery.cs Updated Handle method to use new filter methods instead of WithoutAggregateSideEffects()
src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs Added IAggregateRestoredHandler interface implementation and OnRestore method
src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs New record type for dialog restoration events
src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs Modified TrySetOriginalRevision method to preserve original IsModified state
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.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpointSummary.cs New summary class for RestoreDialogEndpoint
src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs Renamed HandleAggregateEntities to HandleAuditableEntities, added more comprehensive entity handling
src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs Updated HandleAggregateEntities method to use IEntityOptions for conditional execution
src/Digdir.Library.Entity.EntityFrameworkCore/IEntityOptions.cs New interface defining configuration options for entity handling
tests/k6/tests/serviceowner/all-tests.js Imported dialogRestore function
tests/k6/tests/serviceowner/dialogRestore.js Added test suite for restoring dialogs
docs/schema/V1/swagger.verified.json New endpoint added for restoring dialogs with appropriate response codes
src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs Added constant for successful dialog restoration message
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs Updated to handle DialogRestoredDomainEvent
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Common/Events/DomainEventsTests.cs New test for cloud event generation upon dialog restoration
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/AltinnForwarders/DialogEventToAltinnForwarder.cs New handler for DialogRestoredDomainEvent
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Endpoints.verified.txt Added entry for DialogRestoredDomainEvent
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Events.verified.txt Added entry for DialogRestoredDomainEvent

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

  • feat(webapi): Add option to disable Altinn event generation #1633: The changes in the main PR, which involve modifications to the IUnitOfWork interface and the introduction of methods to disable specific filters, are related to the changes in the retrieved PR, where the CreateDialogCommand and other commands have been updated to include a property for disabling Altinn events, indicating a direct connection in functionality regarding event handling.
  • chore: Misc. typos #1740: The changes in the main PR, which involve the addition and removal of methods in the IUnitOfWork interface, are related to the modifications in the retrieved PR, where the Handle method in GetDialogQueryHandler replaces a call to WithoutAggregateSideEffects() with calls to DisableUpdatableFilter() and DisableVersionableFilter(), both of which are new methods introduced in the main PR. Thus, they are directly connected at the code level.

Suggested reviewers

  • MagnusSandgren
  • arealmaas

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.

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.Infrastructure/UnitOfWork.cs (2)

57-79: Consider adding XML documentation for the filter methods.

The implementation looks good and follows a consistent pattern. Consider adding XML documentation to describe the purpose and impact of disabling each filter, especially since these methods are part of the public API.


209-219: Consider documenting the impact of each filter.

The SaveChangesOptions class implementation looks good, but it would be helpful to document:

  1. The purpose of each filter
  2. The impact of disabling each filter
  3. Which scenarios might require disabling specific filters
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3355c89 and 6c934e0.

📒 Files selected for processing (1)
  • src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs (4 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 (4)
src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs (4)

28-28: LGTM!

The field initialization follows proper conventions and immutability principles.


54-56: LGTM!

The method is concise and correctly handles transaction initialization using null-coalescing assignment.


205-208: Documentation improvement appreciated.

The comment now better explains the rationale for limiting setters without the previous negative connotation.


113-116: Verify Entity library compatibility.

The change in the HandleAuditableEntities method signature suggests a breaking change in the Entity library. Please ensure that the Entity library version is compatible with this change.

✅ Verification successful

Implementation is compatible with Entity library

The HandleAuditableEntities implementation in EntityLibraryEfCoreExtensions.cs matches the usage in UnitOfWork.cs. Since both the Entity library and its consumers are part of the same solution, the changes are properly coordinated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Entity library version and changes
rg -l "HandleAuditableEntities.*IEntityOptions" .
cat $(fd -g "*csproj" .) | grep -A 5 "Digdir.Library.Entity"

Length of output: 3844


Script:

#!/bin/bash
# Find HandleAuditableEntities implementation and related types
ast-grep --pattern 'public $_ HandleAuditableEntities($_)'
rg -A 5 "HandleAuditableEntities" .
rg -l "interface.*EntityOptions" .

Length of output: 1499

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 (5)
src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpointSummary.cs (1)

16-19: Consider adding 409 Conflict response.

The endpoint should handle the case where a dialog cannot be restored because it's already active.

Add the following response code:

 Responses[StatusCodes.Status204NoContent] = Constants.SwaggerSummary.Restored.FormatInvariant("aggregate");
 Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound;
 Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch;
+Responses[StatusCodes.Status409Conflict] = "Dialog cannot be restored because it is already active.";
docs/schema/V1/swagger.verified.json (4)

6373-6373: Consider enhancing the endpoint description.

The description could be more detailed to explain:

  • What happens when a dialog is restored
  • Any side effects or constraints
  • Any related activity events that are generated

6399-6401: Add more details to the 401 error description.

The 401 error description should specify the required scope, similar to other endpoints in the API that mention "Requires a Maskinporten-token with the scope 'digdir:dialogporten.serviceprovider'".


6402-6404: Add more details to the 403 error description.

The 403 error description should explain the authorization requirements, similar to other endpoints that mention "Unauthorized to restore the supplied dialog (not owned by authenticated organization or has additional scope requirements defined in policy)".


6396-6398: Add ETag header to successful response.

For consistency with other endpoints that modify dialogs (create, update, delete), the 204 response should include the ETag header to return the new revision.

Apply this change to add the ETag header:

          "204": {
-            "description": "The dialog aggregate was restored successfully."
+            "description": "The dialog aggregate was restored successfully.",
+            "headers": {
+              "Etag": {
+                "description": "The new UUID ETag of the dialog",
+                "example": "123e4567-e89b-12d3-a456-426614174000",
+                "schema": {
+                  "type": "string"
+                }
+              }
+            }
           },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c934e0 and a527ae3.

📒 Files selected for processing (3)
  • docs/schema/V1/swagger.verified.json (2 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialogs/Restore/RestoreDialogEndpointSummary.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build / build-and-test
🔇 Additional comments (5)
src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs (1)

16-16: LGTM! Well-structured constant addition.

The new Restored constant follows the established pattern and maintains consistency with other dialog operation messages. It's appropriately positioned within the SwaggerSummary class and will integrate well with the new dialog restoration functionality.

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

1-5: LGTM! Clean and minimal imports.

The imports are relevant and the namespace follows the project's structure.


7-10: LGTM! Follows FastEndpoints conventions.

The class is appropriately sealed and inherits from the correct base class.


11-14: Update the documentation link.

The description contains a placeholder "(link TBD)" that needs to be updated with the actual documentation link.

Would you like me to help create a documentation issue to track this? The PR objectives mention that documentation updates should be made either in the docs directory, Altinnpedia, or through a separate PR in the Altinn studio documentation repository.

docs/schema/V1/swagger.verified.json (1)

6371-6436: LGTM! The restore dialog endpoint is well-defined.

The endpoint follows REST best practices:

  • Uses POST for the restore action
  • Follows the resource/action pattern in the URL
  • Includes proper optimistic concurrency control via If-Match header
  • Has appropriate response codes and descriptions
  • Requires proper authentication and authorization

@oskogstad oskogstad changed the title feat: restore dialog action feat: Restore dialog action Jan 23, 2025
oskogstad
oskogstad previously approved these changes Feb 3, 2025
@oskogstad oskogstad self-requested a review February 3, 2025 15:47
@oskogstad oskogstad dismissed their stale review February 3, 2025 15:47

Forgot stuff 🤔

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

🧹 Nitpick comments (1)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Common/Events/DomainEventsTests.cs (1)

256-256: Use consistent test data generation method.

The test uses GenerateSimpleFakeCreateDialogCommand while other tests use GenerateFakeCreateDialogCommand. Consider using the same method for consistency.

Apply this diff to align with other tests:

-        var createDialogCommand = DialogGenerator.GenerateSimpleFakeCreateDialogCommand(dialogId);
+        var createDialogCommand = DialogGenerator.GenerateFakeCreateDialogCommand(
+            id: dialogId,
+            attachments: [],
+            activities: []);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a527ae3 and 869c9ba.

📒 Files selected for processing (6)
  • docs/schema/V1/swagger.verified.json (2 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Common/Events/DomainEventsTests.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogRestoredDomainEvent.cs
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • 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
🔇 Additional comments (3)
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs (1)

11-11: LGTM!

The new cloud event type follows the established naming convention and is correctly placed in the "Dialog" section.

docs/schema/V1/swagger.verified.json (2)

6382-6447: New endpoint for restoring soft-deleted dialogs

The new endpoint /api/v1/serviceowner/dialogs/{dialogId}/actions/restore has been added with the following characteristics:

  • HTTP Method: POST
  • Path Parameters: dialogId (GUID)
  • Headers: if-Match (optional GUID for optimistic concurrency)
  • Authentication: JWT Bearer token required
  • Response Codes:
    • 204: Successful restoration
    • 401: Unauthorized
    • 403: Forbidden
    • 404: Dialog not found
    • 412: Precondition failed (if-Match header mismatch)

The endpoint follows RESTful principles and matches the pattern of other action endpoints in the API.

Let's verify the consistency of the restore functionality across the API:

✅ Verification successful

Restore functionality is implemented consistently.

  • The /api/v1/serviceowner/dialogs/{dialogId}/actions/restore endpoint is properly defined with the expected POST method, parameters, and responses.
  • The domain events and activity types (e.g., DialogRestored) are integrated across the codebase—evidenced in the domain events, migrations, and tests.
  • The command handler (RestoreDialogCommandHandler) and endpoint implementations confirm the correct implementation of restore logic and validations.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the restore functionality is consistently implemented

# Test 1: Check if restore is properly handled in activity types
ast-grep --pattern 'DialogActivityType" {
  $$$
  "DialogRestored"
  $$$
}'

# Test 2: Check if restore is handled in domain events
rg -A 5 "DialogRestored"

# Test 3: Check for restore-related handlers and validators
rg -A 5 "RestoreDialog"

Length of output: 23743


7131-7135: Verify server URL configuration

The server URL is configured to point to the development environment. Ensure this is the intended configuration for the swagger documentation.

Let's check if there are any environment-specific configurations:

✅ Verification successful

Action: Confirm Intended Swagger Server URL Configuration

The shell script output shows that the development URL ("https://altinn-dev-api.azure-api.net/dialogporten") is consistently used not only in the Swagger documentation (docs/schema/V1/swagger.verified.json) but also across several test and configuration files. This indicates that the current configuration is intentionally pointing to the development environment.

  • The Swagger file and multiple test configurations (e.g., in appsettings.test.json files and tests/k6 configurations) all use the same development URL.
  • No conflicting environment-specific URLs were found in the relevant configurations.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for environment-specific configurations

# Test: Look for environment-specific URLs
rg -A 5 "altinn-dev-api.azure-api.net"

Length of output: 3346

oskogstad and others added 2 commits February 3, 2025 17:23
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
MagnusSandgren
MagnusSandgren previously approved these changes Feb 4, 2025
Copy link
Collaborator

@MagnusSandgren MagnusSandgren left a comment

Choose a reason for hiding this comment

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

God hjelp fra @oskogstad 🙌

Co-authored-by: Magnus Sandgren <5285192+MagnusSandgren@users.noreply.github.com>
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: 1

🧹 Nitpick comments (3)
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Endpoints.verified.txt (1)

8-8: Formatting Consistency Notice – End Bracket.
It appears the closing bracket line has been modified (possibly removing or adjusting a trailing newline). Verify that this formatting aligns with the project’s style guidelines to maintain consistency across test files.

tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Events.verified.txt (1)

8-8: Minor Formatting Change – Review End Bracket Syntax.
The change on the closing bracket (line 8) may indicate a modification in newline handling or spacing. Please confirm that this style conforms with other test files in the repository.

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

205-208: Improve comment clarity.

The current comment is unclear and has grammatical issues. Consider this revision:

-    // Although Digdir.Library.Entity.EntityFrameworkCore supports all the options,
-    // But we only have use cases for some of them. Therefore,
-    // only some of them have setters until the day we actually
-    // have a use case for them.
+    // Although Digdir.Library.Entity.EntityFrameworkCore supports all options,
+    // we currently only have use cases for some of them. Therefore,
+    // only the necessary options have setters enabled. Additional
+    // setters will be enabled when use cases arise.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 869c9ba and df05eba.

📒 Files selected for processing (5)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/AltinnForwarders/DialogEventToAltinnForwarder.cs (3 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/UnitOfWork.cs (4 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Common/Events/DomainEventsTests.cs (2 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Endpoints.verified.txt (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Events.verified.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Common/Events/DomainEventsTests.cs
⏰ 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 (3)
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Endpoints.verified.txt (1)

5-5: Added New Restoration Event Entry.
The new event DialogEventToAltinnForwarder_DialogRestoredDomainEvent has been inserted into the list, which aligns with the new dialog restoration feature. Please ensure that any related documentation and test references are updated accordingly.

tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/Common/Utils/ApplicationEventHandlerUtilsTests.Developer_Should_Use_Caution_When_Modifying_Events.verified.txt (1)

5-5: New Domain Event for Dialog Restoration Added.
The event Digdir.Domain.Dialogporten.Domain.Dialogs.Events.DialogRestoredDomainEvent has been added to the events list. This change supports the restoration workflow by including the new domain event. Double-check that the event’s structure and its usage in the domain logic are consistent with existing events.

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

57-79: LGTM! Well-structured filter control implementation.

The implementation of granular filter control is well-designed:

  • Each filter has a dedicated method for disabling it
  • Methods follow a consistent pattern
  • Good use of fluent interface pattern with method chaining
  • Clear separation of concerns

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 (1)
docs/schema/V1/swagger.verified.json (1)

6424-6424: Clarify error description for dialog restore

The error description "The given dialog ID was not found or is already deleted" is ambiguous and could be improved. A deleted dialog should be restorable, so "already deleted" shouldn't be an error condition.

Consider updating the error description to be more precise:

-"description": "The given dialog ID was not found or is already deleted."
+"description": "The given dialog ID was not found."
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df05eba and d507a43.

📒 Files selected for processing (2)
  • docs/schema/V1/swagger.verified.json (1 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Dry run deploy apps / Deploy job sync-subject-resource-mappings-job to test
🔇 Additional comments (1)
docs/schema/V1/swagger.verified.json (1)

6382-6447: New endpoint for restoring soft-deleted dialogs

The new endpoint /api/v1/serviceowner/dialogs/{dialogId}/actions/restore has been added with appropriate security controls and error handling:

  1. Authentication & Authorization:
  • Requires JWT bearer authentication
  • Proper 401/403 responses for unauthorized access
  1. Input Validation:
  • Required dialogId path parameter
  • Optional if-Match header for optimistic concurrency control
  1. Error Handling:
  • 404 for non-existent dialogs
  • 412 for concurrency conflicts
  • Returns problem details for errors
  1. Response:
  • 204 No Content on successful restore

Let's verify the endpoint's integration with the domain events system:

oskogstad and others added 3 commits February 6, 2025 11:56
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Fargekritt Fargekritt merged commit 331d492 into main Feb 10, 2025
23 checks passed
@Fargekritt Fargekritt deleted the feat/restore-dialog-action branch February 10, 2025 07:25
arealmaas pushed a commit that referenced this pull request Feb 10, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.49.0](v1.48.5...v1.49.0)
(2025-02-10)


### Features

* Restore dialog action
([#1702](#1702))
([331d492](331d492))
* **webapi:** Option to include deleted dialogs in ServiceOwner dialog
search ([#1816](#1816))
([5403063](5403063))


### Miscellaneous Chores

* **ci:** Increase container app verification timeout
([#1819](#1819))
([fe5377a](fe5377a))
* **deps:** update dependency fastendpoints.swagger to 5.34.0
([#1822](#1822))
([8ce7e0e](8ce7e0e))
* **deps:** update dependency uuidnext to 4.1.0
([#1823](#1823))
([dfa5ce0](dfa5ce0))
* **deps:** update masstransit monorepo to 8.3.6
([#1821](#1821))
([6fbb41f](6fbb41f))
* refactor and add filters for telemetry
([#1813](#1813))
([fd10351](fd10351))

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

4 participants