From 503f0bbf95ede539355d87138ac08fabdf2cabc4 Mon Sep 17 00:00:00 2001 From: CelineTrammi Date: Fri, 22 Nov 2024 09:28:05 +0100 Subject: [PATCH 1/5] change response body to not include needsConfirmation and history object --- .../LegacyGetCorrespondenceHistoryHandler.cs | 43 ++++++++----------- .../LegacyGetCorrespondenceHistoryResponse.cs | 6 --- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs index f382c2e9..272869a5 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs @@ -7,23 +7,20 @@ using System.Security.Claims; namespace Altinn.Correspondence.Application.GetCorrespondenceHistory; -public class LegacyGetCorrespondenceHistoryHandler : IHandler +public class LegacyGetCorrespondenceHistoryHandler( + ICorrespondenceRepository correspondenceRepository, + IAltinnNotificationService altinnNotificationService, + IAltinnRegisterService altinnRegisterService, + IAltinnAuthorizationService altinnAuthorizationService, + UserClaimsHelper userClaimsHelper) : IHandler> { - private readonly ICorrespondenceRepository _correspondenceRepository; - private readonly IAltinnNotificationService _altinnNotificationService; - private readonly IAltinnRegisterService _altinnRegisterService; - private readonly IAltinnAuthorizationService _altinnAuthorizationService; - private readonly UserClaimsHelper _userClaimsHelper; + private readonly ICorrespondenceRepository _correspondenceRepository = correspondenceRepository; + private readonly IAltinnNotificationService _altinnNotificationService = altinnNotificationService; + private readonly IAltinnRegisterService _altinnRegisterService = altinnRegisterService; + private readonly IAltinnAuthorizationService _altinnAuthorizationService = altinnAuthorizationService; + private readonly UserClaimsHelper _userClaimsHelper = userClaimsHelper; - public LegacyGetCorrespondenceHistoryHandler(ICorrespondenceRepository correspondenceRepository, IAltinnNotificationService altinnNotificationService, IAltinnRegisterService altinnRegisterService, IAltinnAuthorizationService altinnAuthorizationService, UserClaimsHelper userClaimsHelper) - { - _correspondenceRepository = correspondenceRepository; - _altinnNotificationService = altinnNotificationService; - _altinnRegisterService = altinnRegisterService; - _altinnAuthorizationService = altinnAuthorizationService; - _userClaimsHelper = userClaimsHelper; - } - public async Task> Process(Guid correspondenceId, ClaimsPrincipal? user, CancellationToken cancellationToken) + public async Task, Error>> Process(Guid correspondenceId, ClaimsPrincipal? user, CancellationToken cancellationToken) { if (_userClaimsHelper.GetPartyId() is not int partyId) { @@ -52,7 +49,7 @@ public async Task> Process( var correspondenceHistory = correspondence.Statuses .Where(s => s.Status.IsAvailableForRecipient()) - .Select(s => new LegacyCorrespondenceStatus + .Select(s => new LegacyGetCorrespondenceHistoryResponse { Status = s.Status.ToString(), StatusChanged = s.StatusChanged, @@ -64,7 +61,7 @@ public async Task> Process( }, }).ToList(); - var notificationHistory = new List(); + var notificationHistory = new List(); foreach (var notification in correspondence.Notifications) { if (string.IsNullOrEmpty(notification.NotificationOrderId.ToString())) continue; @@ -92,18 +89,14 @@ public async Task> Process( (int)minimumAuthLevel)); } } + List joinedList = [.. correspondenceHistory.Concat(notificationHistory).OrderByDescending(s => s.StatusChanged)]; - var legacyHistory = new LegacyGetCorrespondenceHistoryResponse - { - History = [.. correspondenceHistory.Concat(notificationHistory).OrderByDescending(s => s.StatusChanged)], - NeedsConfirm = correspondence.IsConfirmationNeeded, - }; - return legacyHistory; + return joinedList; } - private static LegacyCorrespondenceStatus GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId, int authenticationLevel) + private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId, int authenticationLevel) { - return new LegacyCorrespondenceStatus + return new LegacyGetCorrespondenceHistoryResponse { Status = sendStatus.Status, StatusChanged = sendStatus.LastUpdate, diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs index 846c7cd0..e47079ab 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs @@ -3,12 +3,6 @@ namespace Altinn.Correspondence.Application.GetCorrespondenceHistory; public class LegacyGetCorrespondenceHistoryResponse -{ - public List History { get; set; } = new List(); - - public bool? NeedsConfirm { get; set; } -} -public class LegacyCorrespondenceStatus { public string Status { get; set; } public DateTimeOffset? StatusChanged { get; set; } From 9d528695b0db43d4279ebf0793a5063b10af6905 Mon Sep 17 00:00:00 2001 From: CelineTrammi Date: Fri, 22 Nov 2024 09:50:07 +0100 Subject: [PATCH 2/5] remove minimum auth from response --- .../LegacyGetCorrespondenceHistoryHandler.cs | 12 ++++-------- .../LegacyGetCorrespondenceHistoryResponse.cs | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs index 272869a5..e9dfe9ad 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs @@ -56,8 +56,7 @@ public async Task, Error>> Pr StatusText = $"[Correspondence] {s.StatusText}", User = new LegacyUser { - PartyId = recipientParty.PartyId, - AuthenticationLevel = (int)minimumAuthLevel + PartyId = recipientParty.PartyId }, }).ToList(); @@ -76,8 +75,7 @@ public async Task, Error>> Pr notificationDetails.NotificationsStatusDetails.Sms.SendStatus, notificationDetails.NotificationsStatusDetails.Sms.Recipient, notification.IsReminder, - senderParty.PartyId, - (int)minimumAuthLevel)); + senderParty.PartyId)); } if (notificationDetails.NotificationsStatusDetails.Email is not null) { @@ -85,8 +83,7 @@ public async Task, Error>> Pr notificationDetails.NotificationsStatusDetails.Email.SendStatus, notificationDetails.NotificationsStatusDetails.Email.Recipient, notification.IsReminder, - senderParty.PartyId, - (int)minimumAuthLevel)); + senderParty.PartyId)); } } List joinedList = [.. correspondenceHistory.Concat(notificationHistory).OrderByDescending(s => s.StatusChanged)]; @@ -94,7 +91,7 @@ public async Task, Error>> Pr return joinedList; } - private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId, int authenticationLevel) + private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId) { return new LegacyGetCorrespondenceHistoryResponse { @@ -104,7 +101,6 @@ private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(Stat User = new LegacyUser { PartyId = partyId, - AuthenticationLevel = authenticationLevel, Recipient = recipient }, }; diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs index e47079ab..4bf78f92 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs @@ -12,6 +12,5 @@ public class LegacyGetCorrespondenceHistoryResponse public class LegacyUser { public int PartyId { get; set; } - public int AuthenticationLevel { get; set; } public Recipient Recipient { get; set; } } \ No newline at end of file From 4e0df8d69e37b277bdfc5bf9da8cc4f91a42c98d Mon Sep 17 00:00:00 2001 From: CelineTrammi Date: Fri, 22 Nov 2024 10:24:28 +0100 Subject: [PATCH 3/5] use senderParty for User when correspondence is published --- .../LegacyGetCorrespondenceHistoryHandler.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs index e9dfe9ad..ff819ec7 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs @@ -1,4 +1,5 @@ using Altinn.Correspondence.Application.Helpers; +using Altinn.Correspondence.Core.Models.Entities; using Altinn.Correspondence.Core.Models.Enums; using Altinn.Correspondence.Core.Models.Notifications; using Altinn.Correspondence.Core.Repositories; @@ -49,16 +50,8 @@ public async Task, Error>> Pr var correspondenceHistory = correspondence.Statuses .Where(s => s.Status.IsAvailableForRecipient()) - .Select(s => new LegacyGetCorrespondenceHistoryResponse - { - Status = s.Status.ToString(), - StatusChanged = s.StatusChanged, - StatusText = $"[Correspondence] {s.StatusText}", - User = new LegacyUser - { - PartyId = recipientParty.PartyId - }, - }).ToList(); + .Select(s => GetCorrespondenceStatus(s, recipientParty, senderParty)) + .ToList(); var notificationHistory = new List(); foreach (var notification in correspondence.Notifications) @@ -75,7 +68,7 @@ public async Task, Error>> Pr notificationDetails.NotificationsStatusDetails.Sms.SendStatus, notificationDetails.NotificationsStatusDetails.Sms.Recipient, notification.IsReminder, - senderParty.PartyId)); + senderParty.PartyId)); // Notification recipient } if (notificationDetails.NotificationsStatusDetails.Email is not null) { @@ -83,7 +76,7 @@ public async Task, Error>> Pr notificationDetails.NotificationsStatusDetails.Email.SendStatus, notificationDetails.NotificationsStatusDetails.Email.Recipient, notification.IsReminder, - senderParty.PartyId)); + senderParty.PartyId)); // Notification recipient } } List joinedList = [.. correspondenceHistory.Concat(notificationHistory).OrderByDescending(s => s.StatusChanged)]; @@ -91,6 +84,24 @@ public async Task, Error>> Pr return joinedList; } + private static LegacyGetCorrespondenceHistoryResponse GetCorrespondenceStatus(CorrespondenceStatusEntity s, Party recipientParty, Party senderParty) + { + List statusBySender = + [ + CorrespondenceStatus.Published, + ]; + return new LegacyGetCorrespondenceHistoryResponse + { + Status = s.Status.ToString(), + StatusChanged = s.StatusChanged, + StatusText = $"[Correspondence] {s.StatusText}", + User = new LegacyUser + { + PartyId = statusBySender.Contains(s.Status) ? senderParty.PartyId : recipientParty.PartyId + } + }; + } + private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId) { return new LegacyGetCorrespondenceHistoryResponse From 9f0eca17b01339844264ac8d648020ef9984ab5d Mon Sep 17 00:00:00 2001 From: CelineTrammi Date: Fri, 22 Nov 2024 10:50:42 +0100 Subject: [PATCH 4/5] use PartyId for recipient in Notification Status --- .../LegacyGetCorrespondenceHistoryHandler.cs | 26 +++++++++++++++---- .../LegacyGetCorrespondenceHistoryResponse.cs | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs index ff819ec7..ef9a3129 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryHandler.cs @@ -64,19 +64,19 @@ public async Task, Error>> Pr if (notificationDetails.NotificationsStatusDetails.Sms is not null) { - notificationHistory.Add(GetNotificationStatus( + notificationHistory.Add(await GetNotificationStatus( notificationDetails.NotificationsStatusDetails.Sms.SendStatus, notificationDetails.NotificationsStatusDetails.Sms.Recipient, notification.IsReminder, - senderParty.PartyId)); // Notification recipient + cancellationToken)); } if (notificationDetails.NotificationsStatusDetails.Email is not null) { - notificationHistory.Add(GetNotificationStatus( + notificationHistory.Add(await GetNotificationStatus( notificationDetails.NotificationsStatusDetails.Email.SendStatus, notificationDetails.NotificationsStatusDetails.Email.Recipient, notification.IsReminder, - senderParty.PartyId)); // Notification recipient + cancellationToken)); } } List joinedList = [.. correspondenceHistory.Concat(notificationHistory).OrderByDescending(s => s.StatusChanged)]; @@ -102,8 +102,9 @@ private static LegacyGetCorrespondenceHistoryResponse GetCorrespondenceStatus(Co }; } - private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, int partyId) + private async Task GetNotificationStatus(StatusExt sendStatus, Recipient recipient, bool isReminder, CancellationToken cancellationToken) { + int? partyId = await GetPartyIdForNotfication(recipient, cancellationToken); return new LegacyGetCorrespondenceHistoryResponse { Status = sendStatus.Status, @@ -116,4 +117,19 @@ private static LegacyGetCorrespondenceHistoryResponse GetNotificationStatus(Stat }, }; } + + private async Task GetPartyIdForNotfication(Recipient recipient, CancellationToken cancellationToken) + { + if (recipient.NationalIdentityNumber is not null) + { + var p = await _altinnRegisterService.LookUpPartyById(recipient.NationalIdentityNumber, cancellationToken); + return p?.PartyId; + } + else if (recipient.OrganizationNumber is not null) + { + var party = await _altinnRegisterService.LookUpPartyById(recipient.OrganizationNumber, cancellationToken); + return party?.PartyId; + } + return null; + } } diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs index 4bf78f92..4ff6ef4c 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceHistory/LegacyGetCorrespondenceHistoryResponse.cs @@ -11,6 +11,6 @@ public class LegacyGetCorrespondenceHistoryResponse } public class LegacyUser { - public int PartyId { get; set; } + public int? PartyId { get; set; } public Recipient Recipient { get; set; } } \ No newline at end of file From 3c41c5de601f3ecc3b2f02c598185ca17811fbd7 Mon Sep 17 00:00:00 2001 From: CelineTrammi Date: Fri, 22 Nov 2024 10:52:47 +0100 Subject: [PATCH 5/5] update legacy tests --- .../Legacy/LegacyRetrievalTests.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Test/Altinn.Correspondence.Tests/TestingController/Legacy/LegacyRetrievalTests.cs b/Test/Altinn.Correspondence.Tests/TestingController/Legacy/LegacyRetrievalTests.cs index 347528c9..3330ddea 100644 --- a/Test/Altinn.Correspondence.Tests/TestingController/Legacy/LegacyRetrievalTests.cs +++ b/Test/Altinn.Correspondence.Tests/TestingController/Legacy/LegacyRetrievalTests.cs @@ -81,9 +81,9 @@ public async Task LegacyGetCorrespondenceOverview_ShouldAddFetchedToStatusHistor // Assert var historyResponse = await _legacyClient.GetAsync($"correspondence/api/v1/legacy/correspondence/{correspondence.CorrespondenceId}/history"); Assert.Equal(HttpStatusCode.OK, historyResponse.StatusCode); - var historyData = await historyResponse.Content.ReadFromJsonAsync(); + var historyData = await historyResponse.Content.ReadFromJsonAsync>(); Assert.NotNull(historyData); - Assert.Contains(historyData.History, status => status.Status.Contains(CorrespondenceStatus.Fetched.ToString())); + Assert.Contains(historyData, status => status.Status.Contains(CorrespondenceStatus.Fetched.ToString())); } [Fact] @@ -130,15 +130,13 @@ public async Task LegacyGetCorrespondenceHistory_WithCorrespondenceActions_Inclu Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Assert - var content = await response.Content.ReadFromJsonAsync(_serializerOptions); + var content = await response.Content.ReadFromJsonAsync>(_serializerOptions); Assert.NotNull(content); - Assert.Equal(content.NeedsConfirm, payload.Correspondence.IsConfirmationNeeded); - Assert.All(content.History, status => Assert.True(status.User.AuthenticationLevel > 0)); - Assert.Contains(content.History, status => status.User.PartyId == _digdirPartyId); - Assert.Contains(content.History, status => status.Status.Contains(CorrespondenceStatus.Published.ToString())); - Assert.Contains(content.History, status => status.Status.Contains(CorrespondenceStatus.Fetched.ToString())); - Assert.Contains(content.History, status => status.Status.Contains(CorrespondenceStatus.Confirmed.ToString())); - Assert.Contains(content.History, status => status.Status.Contains(CorrespondenceStatus.Archived.ToString())); + Assert.Contains(content, status => status.User.PartyId == _digdirPartyId); + Assert.Contains(content, status => status.Status.Contains(CorrespondenceStatus.Published.ToString())); + Assert.Contains(content, status => status.Status.Contains(CorrespondenceStatus.Fetched.ToString())); + Assert.Contains(content, status => status.Status.Contains(CorrespondenceStatus.Confirmed.ToString())); + Assert.Contains(content, status => status.Status.Contains(CorrespondenceStatus.Archived.ToString())); } [Fact]