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): Add legacy HTML support for MainContentReference #1256

Merged
merged 6 commits into from
Oct 9, 2024

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Oct 9, 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

    • Introduced new media type constants for legacy embeddable HTML.
    • Enhanced XML documentation for supported media types in dialog properties.
    • Added new enum schemas for improved API structure.
  • Bug Fixes

    • Improved validation for dialog creation with specific media types based on user scopes.
  • Tests

    • Added new test cases to validate dialog creation behavior with HTML media types.
  • Documentation

    • Updated API schemas and descriptions in the Swagger documentation, including new properties and security schemes.

@oskogstad oskogstad requested a review from a team as a code owner October 9, 2024 09:08
Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Caution

Review failed

The pull request is closed.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the ContentValueDtoValidator class, including the introduction of a new interface to prevent automatic registration in dependency injection. The class now has two constructors and a refactored method for allowed media types. Additionally, new constants for LegacyEmbeddableHtml and LegacyHtml are added to the MediaTypes class. New test cases have been created to validate dialog creation with HTML media types, ensuring proper scope handling. Updates to XML documentation and schema definitions are also included.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/... - Added interface IIgnoreOnAssemblyScan.
- Updated constructor overloads.
- Refactored GetAllowedMediaTypes method.
- Added method UserHasLegacyHtmlScope.
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/... - Updated XML documentation for MediaType property in ContentValueDto.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/... - Updated XML documentation for properties in CreateDialogContentDto to clarify supported media types.
src/Digdir.Domain.Dialogporten.Domain/MediaTypes.cs - Added constants LegacyEmbeddableHtml and LegacyHtml.
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/... - Added tests for dialog creation with LegacyEmbeddableHtml media type, including scope validation.
docs/schema/V1/swagger.verified.json - Added new enum schemas and updated existing schemas with new properties and descriptions.

Possibly related PRs

Suggested reviewers

  • MagnusSandgren

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

🧹 Outside diff range and nitpick comments (4)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (3)

355-383: LGTM! Consider adding a comment explaining the test's purpose.

The test case is well-structured and follows the existing patterns in the file. It correctly verifies that title content cannot use the LegacyEmbeddableHtml media type, even with the appropriate scope.

Consider adding a brief comment at the beginning of the test method to explain why title content should not allow embeddable HTML, as this might not be immediately obvious to other developers.


385-411: LGTM! Consider adding a verification step.

The test case is well-structured and correctly verifies that main content reference can use the LegacyEmbeddableHtml media type when the user has the appropriate scope.

Consider adding a verification step to ensure that the created dialog actually contains the expected main content reference with the LegacyEmbeddableHtml media type. This could be done by retrieving the created dialog and asserting its properties.


355-411: Overall, the new tests look good. Consider additional scenarios.

The two new test methods effectively cover the creation of dialogs with embeddable HTML content for both title and main content reference. They align well with the existing test structure and naming conventions.

To ensure comprehensive coverage of the new feature:

  1. Consider adding tests for other content types (e.g., AdditionalInfo) with embeddable HTML.
  2. Add tests to verify behavior when a user doesn't have the correct scope for embeddable HTML.
  3. If not already present, ensure there are tests for the actual rendering or processing of the embeddable HTML content in the main application code.
src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Content/ContentValueDtoValidator.cs (1)

Line range hint 28-31: Ensure consistent use of StringComparison in StartsWith method

There is an inconsistency in the StringComparison parameter used in the StartsWith method within the two constructors:

  • In the first constructor, StringComparison.OrdinalIgnoreCase is used.
  • In the second constructor, StringComparison.InvariantCultureIgnoreCase is used.

For consistency and to prevent potential bugs due to different string comparison behaviors, consider using the same StringComparison option in both constructors.

Here's how you can unify the StringComparison parameter:

Option 1: Use StringComparison.OrdinalIgnoreCase in both constructors.

// In the second constructor:
- && x.MediaType.StartsWith(MediaTypes.EmbeddablePrefix, StringComparison.InvariantCultureIgnoreCase),
+ && x.MediaType.StartsWith(MediaTypes.EmbeddablePrefix, StringComparison.OrdinalIgnoreCase),

Option 2: Use StringComparison.InvariantCultureIgnoreCase in both constructors.

// In the first constructor:
- && x.MediaType.StartsWith(MediaTypes.EmbeddablePrefix, StringComparison.OrdinalIgnoreCase),
+ && x.MediaType.StartsWith(MediaTypes.EmbeddablePrefix, StringComparison.InvariantCultureIgnoreCase),

Choose the option that aligns with your application's standards for string comparisons.

Also applies to: 55-58

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ca37063 and 7af2951.

📒 Files selected for processing (3)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Content/ContentValueDtoValidator.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.Domain/MediaTypes.cs (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (2 hunks)
🧰 Additional context used
📓 Learnings (1)
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs (2)
Learnt from: oskogstad
PR: digdir/dialogporten#1210
File: tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs:282-282
Timestamp: 2024-10-08T15:39:24.789Z
Learning: Using square brackets `[]` for collection initialization is acceptable in the codebase's C# code.
Learnt from: oskogstad
PR: digdir/dialogporten#1210
File: tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/Dialogs/Commands/CreateDialogTests.cs:282-282
Timestamp: 2024-10-01T17:03:49.291Z
Learning: Using square brackets `[]` for collection initialization is acceptable in the codebase's C# code.
🔇 Additional comments (2)
src/Digdir.Domain.Dialogporten.Domain/MediaTypes.cs (1)

7-7: LGTM! New constant for legacy HTML support added correctly.

The addition of LegacyEmbeddableHtml constant aligns well with the PR objective of adding legacy HTML support for MainContentReference. The implementation follows the existing naming convention and structure, maintaining consistency within the MediaTypes class.

To ensure proper integration, let's verify the usage of this new constant in the codebase:

This will help identify if the new constant is being used appropriately throughout the codebase and if there are any places where the string literal is used directly instead of referencing the constant.

✅ Verification successful

Verified! The LegacyEmbeddableHtml constant is consistently used across the codebase, and no hard-coded string literals matching its value were found. This ensures maintainability and consistency in handling legacy HTML media types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of the new LegacyEmbeddableHtml constant

# Search for direct usage of the constant
echo "Searching for direct usage of LegacyEmbeddableHtml:"
rg --type csharp "MediaTypes\.LegacyEmbeddableHtml"

# Search for string literal that matches the constant value
echo "Searching for string literal matching the constant value:"
rg --type csharp "application/vnd\.dialogporten\.frontchannelembed\+json;type=html"

Length of output: 1149

src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Content/ContentValueDtoValidator.cs (1)

72-82: LGTM! Implementation correctly extends allowed media types based on user scope

The changes appropriately extend the allowed media types for DialogContentType.Values.AdditionalInfo and DialogContentType.Values.MainContentReference when the user has the LegacyHtmlScope. The use of a switch expression simplifies the logic and enhances code readability.

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

🧹 Outside diff range and nitpick comments (4)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (4)

212-213: LGTM! Consider clarifying if HTML is supported.

The updated documentation clarifies that text/plain is a supported media type for the Title property. This change aligns with the PR objective of adding legacy HTML support.

Consider explicitly mentioning whether HTML is also supported for this property, to align fully with the PR's objective of adding legacy HTML support.


218-219: LGTM! Consider clarifying if HTML is supported.

The updated documentation clarifies that text/plain is a supported media type for the Summary property. This change is consistent with the PR objective of adding legacy HTML support.

Consider explicitly mentioning whether HTML is also supported for this property, to fully align with the PR's objective of adding legacy HTML support.


230-231: LGTM! Consider clarifying HTML support.

The updated documentation for the AdditionalInfo property now includes support for both text/plain and text/markdown. This is a positive change that allows for richer text formatting.

To fully align with the PR's objective of adding legacy HTML support, consider clarifying whether HTML is also supported for this property or if markdown is intended as an alternative to HTML for rich text formatting.


236-237: LGTM! Consider clarifying if HTML is supported.

The updated documentation clarifies that text/plain is a supported media type for the ExtendedStatus property. This change is consistent with the PR objective of adding legacy HTML support.

Consider explicitly mentioning whether HTML is also supported for this property, to fully align with the PR's objective of adding legacy HTML support.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7af2951 and 4f3eab0.

📒 Files selected for processing (3)
  • docs/schema/V1/swagger.verified.json (6 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Content/ContentValueDto.cs (0 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Content/ContentValueDto.cs
🧰 Additional context used
🔇 Additional comments (9)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (2)

225-225: LGTM! Documentation update is consistent.

The updated documentation for the SenderName property maintains that text/plain is the supported media type, which is consistent with the previous requirement.


243-243: LGTM! Please clarify the relationship to legacy HTML support.

The updated documentation for the MainContentReference property introduces support for a JSON-based media type with markdown content. This is a significant change that allows for rich text formatting.

Could you please clarify how this change relates to the PR objective of adding legacy HTML support? Is the markdown-in-JSON approach intended as an alternative to direct HTML support, or will HTML support be added in a different way?

To verify the implementation of this new media type, please run the following script:

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

Line range hint 5-24: New enum schemas added: ActorType_Values and AttachmentUrlConsumerType_Values

These new enum schemas provide more structure and clarity to the API. They define specific values for actor types and attachment URL consumer types, which should improve consistency and reduce errors in API usage.


Line range hint 299-349: Updates to CreateDialogContentDto schema

The CreateDialogContentDto schema has been updated with more detailed descriptions for its properties. These changes improve the API documentation and provide clearer guidance for API consumers.

Key improvements:

  1. More specific media type information for each property.
  2. Clearer descriptions of the purpose and usage of each field.

Line range hint 4476-4627: New path operations for dialog activities, transmissions, and seen logs

Several new path operations have been added to the API, including:

  • GET, POST operations for dialog activities
  • GET, POST operations for dialog transmissions
  • GET operations for dialog seen logs

These additions expand the API's functionality and provide more granular control over dialog-related data. The new operations follow a consistent pattern and include proper authentication and authorization checks.


Line range hint 4628-4731: Updates to existing path operations

Existing path operations have been updated with more detailed descriptions, additional query parameters, and improved response documentation. These changes enhance the API's usability and provide clearer guidance for API consumers.

Notable improvements:

  1. More detailed descriptions of operation behavior and requirements.
  2. Additional query parameters for filtering and customizing responses.
  3. Clearer documentation of response structures and possible status codes.

Line range hint 6469-6475: Addition of JWT Bearer authentication scheme

A JWT Bearer authentication scheme has been added to the API specification. This improves the API's security model by requiring a valid JWT token for authentication.

The security scheme is well-defined and includes a clear description of its purpose and usage.


Line range hint 1-6476: Consistent application of security requirements

After reviewing the entire file, it's evident that the JWT Bearer authentication scheme is consistently applied across all path operations that require authentication. This ensures a uniform security model throughout the API.

Each protected endpoint includes the following security requirement:

"security": [
  {
    "JWTBearerAuth": []
  }
]

This consistent application of security requirements is a good practice and helps prevent unauthorized access to sensitive operations.


Line range hint 1-6476: Overall improvements to the Dialogporten API specification

This update to the Dialogporten API specification includes several significant improvements:

  1. New enum schemas (ActorType_Values and AttachmentUrlConsumerType_Values) that provide more structure and clarity.
  2. Updates to existing schemas with more detailed descriptions and clearer documentation.
  3. New path operations for managing dialog activities, transmissions, and seen logs, expanding the API's functionality.
  4. Improvements to existing path operations with more detailed descriptions, additional query parameters, and better response documentation.
  5. Addition of a JWT Bearer authentication scheme and consistent application of security requirements across protected endpoints.

These changes enhance the API's functionality, improve its documentation, and strengthen its security model. The updates follow API best practices and maintain consistency throughout the specification.

Copy link

sonarqubecloud bot commented Oct 9, 2024

@oskogstad oskogstad merged commit 482b38a into main Oct 9, 2024
21 checks passed
@oskogstad oskogstad deleted the feat/add-legacy-html-support-for-main-content-ref branch October 9, 2024 13:54
oskogstad pushed a commit that referenced this pull request Oct 10, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.23.0](v1.22.0...v1.23.0)
(2024-10-10)


### Features

* **infra:** upgrade postgresql SKU in test
([#1257](#1257))
([5a751af](5a751af))
* **webAPI:** Add legacy HTML support for MainContentReference
([#1256](#1256))
([482b38a](482b38a))


### Bug Fixes

* Add missing return types for Transmissions and Activities in OpenAPI
spec ([#1244](#1244))
([972870d](972870d))
* **graphQL:** Missing MediaType on dialog attachment url
([#1264](#1264))
([3919343](3919343))
* Refactor probes and add more health checks
([#1159](#1159))
([6889a96](6889a96))
* **webapi:** ensure correct health checks are used in probes
([#1249](#1249))
([f951152](f951152))

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