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(breaking): Move notification check endpoint to /actions #1175

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Sep 23, 2024

  • Moved query logic to DB query
  • Remove ignore query filters, should not send notifications on deleted dialogs
  • Moved endpoint path to /actions/should-send-notification

Summary by CodeRabbit

  • New Features

    • Improved querying mechanism for dialog activities, allowing for more precise notification conditions.
    • Updated endpoint for determining if a notification should be sent, enhancing clarity on its purpose.
    • Introduced a new API endpoint for checking notification conditions with specific parameters.
  • Bug Fixes

    • Simplified logic for evaluating notification conditions, improving reliability and performance.

@oskogstad oskogstad requested a review from a team as a code owner September 23, 2024 08:25
Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

Walkthrough

The pull request introduces modifications to the notification condition querying process in the application. It updates the NotificationConditionQuery to include filtering logic for dialog activities based on TransmissionId and ActivityType. The logic for determining whether to send notifications has been simplified by removing the CheckDialogActivitiesCondition method and consolidating the evaluation directly in the Handle method. Additionally, the endpoint for checking notification conditions has been renamed to better reflect its functionality.

Changes

Files Change Summary
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs Updated query logic to include filtering for activities based on TransmissionId and ActivityType. Removed CheckDialogActivitiesCondition method, simplifying notification condition evaluation in the Handle method.
src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs Updated endpoint path from dialogs/{dialogId}/notification-condition to dialogs/{dialogId}/actions/should-send-notification and introduced a new API endpoint for determining notification sending conditions.

Possibly related PRs

  • chore: Updated validator messages #1133: This PR modifies the validation rules for the TransmissionId property in the NotificationConditionQueryValidator, which is directly related to the changes made in the NotificationConditionQuery.cs file regarding how notifications are evaluated based on the TransmissionId.

Suggested reviewers

  • elsand: Suggested reviewer for the changes made in the pull request.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 75fbee2 and cee23e2.

Files selected for processing (2)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs (1 hunks)
Additional comments not posted (2)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs (2)

41-43: Improved query efficiency with filtered Include

The changes to the Include method for activities are a significant improvement:

  1. It now filters activities at the database level, which is more efficient than fetching all activities and filtering in memory.
  2. The TransmissionId filter is optional, allowing flexibility in the query.
  3. The ActivityType filter ensures only relevant activities are included, further optimizing the query.

These changes align well with the PR objective of moving query logic to the database and should improve overall performance.


Line range hint 1-58: Overall improvements to notification condition querying

The changes in this file significantly improve the notification condition querying process:

  1. The query logic has been moved to the database level, improving efficiency.
  2. The implementation now ensures that notifications are not sent for deleted dialogs, aligning with the PR objectives.
  3. The code has been simplified, making it easier to maintain and understand.

These changes should result in a more reliable and performant notification system. Great work on the refactoring!

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

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between cee23e2 and ea1e158.

Files selected for processing (1)
  • docs/schema/V1/swagger.verified.json (1 hunks)

Comment on lines +5564 to +5641
"/api/v1/serviceowner/dialogs/{dialogId}/actions/should-send-notification": {
"get": {
"description": "Used by Altinn Notification only. Takes a dialogId and returns a boolean value based on conditions used to determine if a notification is to be sent.",
"operationId": "GetDialogActivityNotificationConditionSO",
"parameters": [
{
"in": "path",
"name": "dialogId",
"required": true,
"schema": {
"format": "guid",
"type": "string"
}
},
{
"in": "query",
"name": "conditionType",
"required": true,
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/NotificationConditionType"
}
]
}
},
{
"in": "query",
"name": "activityType",
"required": true,
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/DialogActivityType_Values"
}
]
}
},
{
"in": "query",
"name": "transmissionId",
"schema": {
"format": "guid",
"nullable": true,
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {}
},
"text/plain": {
"schema": {}
}
},
"description": "Successfully returned the notification determination."
},
"401": {
"description": "Missing or invalid authentication token. Requires a Maskinporten-token with the scope \u0022altinn:system/notifications.condition.check\u0022."
},
"403": {
"description": "Forbidden"
}
},
"security": [
{
"JWTBearerAuth": []
}
],
"summary": "Returns a boolean value based on conditions used to determine if a notification is to be sent",
"tags": [
"Serviceowner"
]
}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Suggested improvements not implemented

The proposed enhancements in the review comment have not been fully addressed:

  1. 400 Bad Request Response Missing: The new endpoint /api/v1/serviceowner/dialogs/{dialogId}/actions/should-send-notification does not include a 400 Bad Request response for invalid query parameters.
  2. Endpoint Naming: The endpoint naming remains /api/v1/serviceowner/dialogs/{dialogId}/actions/should-send-notification instead of adopting a more RESTful convention like /api/v1/serviceowner/dialogs/{dialogId}/notification-conditions.
  3. Response Schema: The response still returns only a boolean value without additional details, such as a reason for the notification decision.
Analysis chain

New endpoint for checking notification conditions added

A new GET endpoint /api/v1/serviceowner/dialogs/{dialogId}/actions/should-send-notification has been added to the API. This endpoint is specifically for Altinn Notification use and determines if a notification should be sent based on certain conditions. The implementation looks good overall, but there are a few points to consider:

  1. The endpoint is well-documented with a clear description and purpose.
  2. Required query parameters (conditionType, activityType) are properly specified.
  3. The response is a boolean value, which is appropriate for the use case.
  4. The security scheme requires a Maskinporten token with the scope "altinn:system/notifications.condition.check", which is different from other endpoints in this API.

Consider the following suggestions to improve the endpoint:

  1. Add more detailed error responses, such as 400 Bad Request for invalid query parameters.
  2. Consider using a more RESTful naming convention for the endpoint, e.g., /api/v1/serviceowner/dialogs/{dialogId}/notification-conditions instead of using an "actions" subfolder.
  3. If possible, provide more information in the response, such as a reason for the decision, which could be useful for debugging or logging purposes.

Example of a more detailed response schema:

{
  "shouldSendNotification": true,
  "reason": "Condition met: New activity of type 'Information' added"
}

To ensure this endpoint is properly integrated with the rest of the API, let's check for any related models or references:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for references to the new endpoint or its models
grep -rn "should-send-notification" .
grep -rn "NotificationConditionType" .
grep -rn "altinn:system/notifications.condition.check" .

Length of output: 1922


Script:

#!/bin/bash
# Check for additional error responses like 400 Bad Request
grep -rn '"400"' ./docs/schema/V1/swagger.verified.json

# Check if the endpoint naming follows a more RESTful convention
grep -rn "/api/v1/serviceowner/dialogs/{dialogId}/notification-conditions" ./docs/schema/V1/swagger.verified.json

# Inspect the response schema for additional details
grep -rn '"shouldSendNotification"' ./docs/schema/V1/swagger.verified.json

Length of output: 370

Copy link

@oskogstad oskogstad changed the title chore(webapi): Refactor and move notification endpoint feat(breaking): Refactor and move notification endpoint Sep 23, 2024
@oskogstad oskogstad changed the title feat(breaking): Refactor and move notification endpoint feat(breaking): Move notification check endpoint to /actions Sep 23, 2024
@oskogstad oskogstad merged commit e0c1cf2 into main Sep 23, 2024
23 checks passed
@oskogstad oskogstad deleted the chore/remove-ignore-query-filter branch September 23, 2024 19:51
arealmaas pushed a commit that referenced this pull request Sep 24, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.19.0](v1.18.1...v1.19.0)
(2024-09-24)


### Features

* **breaking:** Move notification check endpoint to /actions
([#1175](#1175))
([e0c1cf2](e0c1cf2))


### Bug Fixes

* **janitor:** ensure Redis is configured correctly
([#1182](#1182))
([37fe982](37fe982))

---
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
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant