Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webapi): Only allow transmissionId on TransmissionOpened activities #1631

Merged

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Dec 23, 2024

Description

The validator activity validator allows setting TransmissionId on every activity type except DialogOpened.
It should only allow on TransmissionOpened.

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)

@oskogstad oskogstad requested a review from a team as a code owner December 23, 2024 00:32
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the validation logic for dialog activities, specifically focusing on the TransmissionId property. The changes ensure that only activities of type TransmissionOpened can reference a transmission. This involves updates to validator classes in the application layer and the addition of corresponding unit tests to verify the new validation rules. The modifications aim to improve the consistency and correctness of activity type handling in the dialog management system.

Changes

File Change Summary
src/Digdir.Domain.Dialogporten.Application/.../Create/CreateDialogCommandValidator.cs Updated validation rules for TransmissionId to only allow TransmissionOpened activities to reference a transmission
src/Digdir.Domain.Dialogporten.Application/.../Update/UpdateDialogCommandValidator.cs Modified validation logic to ensure only TransmissionOpened activities can set TransmissionId
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/.../ActivityValidatorTests.cs New unit test class added to validate activity type and TransmissionId rules, including test methods for comprehensive validation coverage

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

Quality Gate Failed Quality Gate failed

Failed conditions
8.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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)
tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs (2)

20-22: Consider enhancing test data generation.

The current implementation tests all activity types, but consider adding specific test cases for edge cases such as:

  • Null TransmissionId
  • Invalid TransmissionId format
  • Empty TransmissionId

55-59: Strengthen error message assertions.

The error message assertions could be more specific by checking the exact error message content instead of just checking if it contains "TransmissionOpened".

-createValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened");
-updateValidation.Errors.First().ErrorMessage.Should().Contain("TransmissionOpened");
+createValidation.Errors.First().ErrorMessage.Should().Be("Only activities of type TransmissionOpened can reference a transmission.");
+updateValidation.Errors.First().ErrorMessage.Should().Be("Only activities of type TransmissionOpened can reference a transmission.");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44aecdb and 672fa5f.

📒 Files selected for processing (3)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Unit.Tests/Features/V1/ServiceOwner/Activities/ActivityValidatorTests.cs (1 hunks)
🔇 Additional comments (2)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs (1)

403-404: LGTM! Validation rules correctly implement the requirement.

The validation rules properly enforce that:

  1. Only TransmissionOpened activities can have a TransmissionId
  2. TransmissionOpened activities must have a TransmissionId

Also applies to: 407-408

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs (1)

437-438: Verify consistent validation behavior.

The validation rules match those in UpdateDialogCommandValidator. Let's verify the behavior is consistent across both validators.

Also applies to: 441-442

✅ Verification successful

Validation rules for TransmissionId are consistent across both validators

After reviewing both validator implementations, I can confirm that the validation rules for TransmissionId in activities are identical in both CreateDialogCommandValidator and UpdateDialogCommandValidator. Both validators enforce:

  1. TransmissionId must be null when activity type is not TransmissionOpened
  2. TransmissionId must not be empty when activity type is TransmissionOpened
  3. The error messages are exactly the same in both validators

The validation behavior is consistent and correctly implemented in both cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that both validators implement identical validation rules

# Compare the validation rules in both validators
diff <(rg -A 3 "TransmissionId.*Null" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs) <(rg -A 3 "TransmissionId.*Null" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs)

# Compare the error messages in both validators
diff <(rg -A 3 "WithMessage.*TransmissionOpened" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs) <(rg -A 3 "WithMessage.*TransmissionOpened" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs)

Length of output: 887


Script:

#!/bin/bash
# Let's try a different approach to compare the validation rules

# First, let's verify both files exist and get their content
echo "=== CreateDialogCommandValidator.cs ==="
rg -l "CreateDialogCommandValidator" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/
cat src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs

echo -e "\n=== UpdateDialogCommandValidator.cs ==="
rg -l "UpdateDialogCommandValidator" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/
cat src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs

Length of output: 35966

@oskogstad oskogstad merged commit 80261d1 into main Dec 23, 2024
25 of 26 checks passed
@oskogstad oskogstad deleted the fix/only-allow-transmissionid-on-transmissionopened-activities branch December 23, 2024 12:48
oskogstad pushed a commit that referenced this pull request Dec 26, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.42.1](v1.42.0...v1.42.1)
(2024-12-25)


### Bug Fixes

* **webapi:** Only allow transmissionId on TransmissionOpened activities
([#1631](#1631))
([80261d1](80261d1))

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