From e0c1cf205c66200f024431dc3392c988b99fdb30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Mon, 23 Sep 2024 21:51:28 +0200 Subject: [PATCH] feat(breaking): Move notification check endpoint to /actions (#1175) * 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. --- docs/schema/V1/swagger.verified.json | 156 +++++++++--------- .../NotificationConditionQuery.cs | 21 +-- .../NotificationConditionEndpoint.cs | 2 +- 3 files changed, 85 insertions(+), 94 deletions(-) diff --git a/docs/schema/V1/swagger.verified.json b/docs/schema/V1/swagger.verified.json index 5b48dd490..4f86d1c70 100644 --- a/docs/schema/V1/swagger.verified.json +++ b/docs/schema/V1/swagger.verified.json @@ -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", @@ -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).", diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs index a46688d39..6b20fc235 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs @@ -38,8 +38,9 @@ public async Task 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); @@ -48,20 +49,10 @@ public async Task Handle(NotificationConditionQuery return new EntityNotFound(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 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; } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs index f3df96f7f..ec4efa3e4 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs @@ -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();