Skip to content

Commit

Permalink
feat(breaking): Move notification check endpoint to /actions (#1175)
Browse files Browse the repository at this point in the history
* 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`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
oskogstad authored Sep 23, 2024
1 parent 3092260 commit e0c1cf2
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 94 deletions.
156 changes: 78 additions & 78 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -5561,6 +5561,84 @@
]
}
},
"/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"
]
}
},
"/api/v1/serviceowner/dialogs/{dialogId}/activities": {
"get": {
"description": "Gets the list of activities belonging to a dialog",
Expand Down Expand Up @@ -5767,84 +5845,6 @@
]
}
},
"/api/v1/serviceowner/dialogs/{dialogId}/notification-condition": {
"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"
]
}
},
"/api/v1/serviceowner/dialogs/{dialogId}/seenlog": {
"get": {
"description": "Gets all seen log records for a dialog. For more information see the documentation (link TBD).",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
{
var dialog = await _db.Dialogs
.AsNoTracking()
.Include(x => x.Activities)
.IgnoreQueryFilters()
.Include(x => x.Activities
.Where(x => request.TransmissionId == null || x.TransmissionId == request.TransmissionId)
.Where(x => x.TypeId == request.ActivityType))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);

Expand All @@ -48,20 +49,10 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
return new EntityNotFound<DialogEntity>(request.DialogId);
}

var conditionMet = CheckDialogActivitiesCondition(dialog.Activities, request.ConditionType, request.ActivityType, request.TransmissionId);
var conditionMet = dialog.Activities.Count == 0
? request.ConditionType == NotificationConditionType.NotExists
: request.ConditionType == NotificationConditionType.Exists;

return new NotificationConditionDto { SendNotification = conditionMet };
}

private static bool CheckDialogActivitiesCondition(
List<DialogActivity> activities,
NotificationConditionType conditionType,
DialogActivityType.Values activityType,
Guid? transmissionId) =>
activities.Where(
x => x.TypeId == activityType
&& (transmissionId is null || x.TransmissionId == transmissionId)).ToList()
.Count == 0
? conditionType == NotificationConditionType.NotExists
: conditionType == NotificationConditionType.Exists;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public NotificationConditionEndpoint(ISender sender)

public override void Configure()
{
Get("dialogs/{dialogId}/notification-condition");
Get("dialogs/{dialogId}/actions/should-send-notification");
Policies(AuthorizationPolicy.NotificationConditionCheck);
Group<ServiceOwnerGroup>();

Expand Down

0 comments on commit e0c1cf2

Please sign in to comment.