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

Customizable notification recipient #529

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Altinn.Correspondence.Application.InitializeCorrespondences;
using Altinn.Correspondence.Core.Models.Entities;
using Altinn.Correspondence.Core.Models.Enums;
using Altinn.Correspondence.Core.Models.Notifications;

namespace Altinn.Correspondence.Mappers;

Expand Down Expand Up @@ -33,7 +34,8 @@ internal static NotificationRequest MapToRequest(InitializeCorrespondenceNotific
ReminderSmsBody = correspondenceNotificationExt.ReminderSmsBody,
ReminderNotificationChannel = (NotificationChannel?)correspondenceNotificationExt.ReminderNotificationChannel,
SmsBody = correspondenceNotificationExt.SmsBody,
SendReminder = correspondenceNotificationExt.SendReminder
SendReminder = correspondenceNotificationExt.SendReminder,
Recipients = NotificationMapper.MapExternalRecipientsToRequest(correspondenceNotificationExt.Recipients) ?? new List<Recipient>(),
};
return notification;
}
Expand Down
18 changes: 16 additions & 2 deletions src/Altinn.Correspondence.API/Mappers/NotificationMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private static NotificationStatusDetailsExt MapNotificationsStatusSummaryExtToEx
Recipient = new NotificationRecipientExt()
{
EmailAddress = status.Email.Recipient.EmailAddress,
IsReserved = status.Email.Recipient.IsReserved,
MobileNumber = status.Email.Recipient.MobileNumber,
NationalIdentityNumber = status.Email.Recipient.NationalIdentityNumber,
OrganizationNumber = status.Email.Recipient.OrganizationNumber
Expand All @@ -73,7 +72,6 @@ private static NotificationStatusDetailsExt MapNotificationsStatusSummaryExtToEx
Recipient = new NotificationRecipientExt()
{
EmailAddress = status.Sms.Recipient.EmailAddress,
IsReserved = status.Sms.Recipient.IsReserved,
MobileNumber = status.Sms.Recipient.MobileNumber,
NationalIdentityNumber = status.Sms.Recipient.NationalIdentityNumber,
OrganizationNumber = status.Sms.Recipient.OrganizationNumber
Expand All @@ -88,4 +86,20 @@ private static NotificationStatusDetailsExt MapNotificationsStatusSummaryExtToEx
} : null,
};
}

public static List<Recipient> MapExternalRecipientsToRequest(List<NotificationRecipientExt> recipients)
{
var recipientsRequest = new List<Recipient>();
foreach (var recipient in recipients)
{
recipientsRequest.Add(new Recipient()
{
EmailAddress = recipient.EmailAddress,
MobileNumber = recipient.MobileNumber,
NationalIdentityNumber = recipient.NationalIdentityNumber,
OrganizationNumber = recipient.OrganizationNumber
});
}
return recipientsRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,11 @@ public class InitializeCorrespondenceNotificationExt
/// </summary>
[JsonPropertyName("requestedSendTime")]
public DateTimeOffset? RequestedSendTime { get; set; }

/// <summary>
/// A list of recipients for the notification. If not set, the notification will be sent to the recipient of the Correspondence
/// </summary>
[JsonPropertyName("recipients")]
public List<NotificationRecipientExt>? Recipients { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ public class NotificationRecipientExt
/// </summary>
[JsonPropertyName("nationalIdentityNumber")]
public string? NationalIdentityNumber { get; set; }

/// <summary>
/// Boolean indicating if the recipient is reserved
/// </summary>
[JsonPropertyName("isReserved")]
public bool? IsReserved { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,22 @@ private List<NotificationOrderRequest> CreateNotifications(NotificationRequest n
personNr = correspondence.Recipient;
content = contents.FirstOrDefault(c => c.RecipientType == RecipientType.Person || c.RecipientType == null);
}
var notificationOrder = new NotificationOrderRequest

List<Recipient> recipients = new List<Recipient>();

if (notification.Recipients.Count == 0)
{
IgnoreReservation = correspondence.IgnoreReservation,
Recipients = new List<Recipient>{
new Recipient{
recipients.Add(new Recipient
{
OrganizationNumber = orgNr,
NationalIdentityNumber = personNr
},
},
});
}
else recipients = notification.Recipients;
var notificationOrder = new NotificationOrderRequest
{
IgnoreReservation = correspondence.IgnoreReservation,
Recipients = recipients,
ResourceId = correspondence.ResourceId,
RequestedSendTime = correspondence.RequestedPublishTime.UtcDateTime <= DateTime.UtcNow ? DateTime.UtcNow.AddMinutes(5) : correspondence.RequestedPublishTime.UtcDateTime.AddMinutes(5),
SendersReference = correspondence.SendersReference,
Expand All @@ -323,14 +330,7 @@ private List<NotificationOrderRequest> CreateNotifications(NotificationRequest n
notifications.Add(new NotificationOrderRequest
{
IgnoreReservation = correspondence.IgnoreReservation,
Recipients = new List<Recipient>
{
new Recipient
{
OrganizationNumber = orgNr,
NationalIdentityNumber = personNr
},
},
Recipients = recipients,
ResourceId = correspondence.ResourceId,
RequestedSendTime = _hostEnvironment.IsProduction() ? notificationOrder.RequestedSendTime.Value.AddDays(7) : notificationOrder.RequestedSendTime.Value.AddHours(1),
ConditionEndpoint = CreateConditionEndpoint(correspondence.Id.ToString()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Correspondence.Core.Models.Enums;
using Altinn.Correspondence.Core.Models.Notifications;
namespace Altinn.Correspondence.Application.InitializeCorrespondences
{
public class NotificationRequest
Expand All @@ -19,6 +20,8 @@ public class NotificationRequest

public string? ReminderSmsBody { get; set; }

public List<Recipient> Recipients { get; set; }

public required NotificationChannel NotificationChannel { get; set; }

public NotificationChannel? ReminderNotificationChannel { get; set; }
Expand Down
Loading