Skip to content

Commit aba5d9d

Browse files
authored
Instantiation notification (#1703)
* add temp log * add temp log * remove sendingtime from email - not supported * use email for SI * add sms settings for si * refactor: allow anonymous * feat: log any errors from problemdetails * chore: format * chore: unused using * test: update snapshots * snapshot * feat: add maskinporten for notification callback to storage * test: callback * snapshots * chore: fix log text * refactor: update path * deps: add code from pr 1599 * refactor: add custom sms support for si * refactor: forward ct * intergration snapshots * refactor: using
1 parent c8f17e6 commit aba5d9d

28 files changed

Lines changed: 1366 additions & 301 deletions

src/Altinn.App.Api/Controllers/InstancesController.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,25 @@ CancellationToken cancellationToken
166166

167167
try
168168
{
169-
Instance instance = await _instanceClient.GetInstance(app, org, instanceOwnerPartyId, instanceGuid);
169+
Instance instance = await _instanceClient.GetInstance(
170+
app,
171+
org,
172+
instanceOwnerPartyId,
173+
instanceGuid,
174+
ct: cancellationToken
175+
);
170176
SelfLinkHelper.SetInstanceAppSelfLinks(instance, Request);
171177

172178
string? userOrgClaim = User.GetOrg();
173179

174180
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.OrdinalIgnoreCase))
175181
{
176-
await _instanceClient.UpdateReadStatus(instanceOwnerPartyId, instanceGuid, "read");
182+
await _instanceClient.UpdateReadStatus(
183+
instanceOwnerPartyId,
184+
instanceGuid,
185+
"read",
186+
ct: cancellationToken
187+
);
177188
}
178189

179190
var instanceOwnerParty = await _registerClient.GetPartyUnchecked(instanceOwnerPartyId, cancellationToken);

src/Altinn.App.Api/Controllers/NotificationCallbackController.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Text.Json.Serialization;
2+
using Altinn.App.Core.Features;
23
using Altinn.App.Core.Features.Notifications.Cancellation;
34
using Altinn.App.Core.Internal.Instances;
45
using Altinn.Platform.Storage.Interface.Models;
6+
using Microsoft.AspNetCore.Authorization;
57
using Microsoft.AspNetCore.Mvc;
68

79
namespace Altinn.App.Api.Controllers;
@@ -10,8 +12,9 @@ namespace Altinn.App.Api.Controllers;
1012
/// Endpoint(s) for the Altinn Notification microservice callback
1113
/// </summary>
1214
[ApiController]
15+
[AllowAnonymous]
1316
[ApiExplorerSettings(IgnoreApi = true)]
14-
[Route("{org}/{app}/notifications")]
17+
[Route("{org}/{app}/api/v1/notification-webhook-listener")]
1518
public class NotificationCallbackController(
1619
ILogger<NotificationCallbackController> logger,
1720
ICancelInstantiationNotification instantiationNotification,
@@ -30,12 +33,33 @@ public async Task<ActionResult<NotificationCallbackResponse>> NotificationCallba
3033
[FromRoute] Guid instanceGuid
3134
)
3235
{
33-
Instance instance = await instanceClient.GetInstance(app, org, instanceOwnerPartyId, instanceGuid);
3436
logger.LogInformation(
35-
$"Received callback for org:{org}, app:{app}, instanceOwnerPartyId:{instanceOwnerPartyId}, instanceGuid:{instanceGuid}."
37+
"Received callback for org:{Org}, app:{App}, instanceOwnerPartyId:{InstanceOwnerPartyId}, instanceGuid:{InstanceGuid}.",
38+
org,
39+
app,
40+
instanceOwnerPartyId,
41+
instanceGuid
3642
);
3743

38-
bool shouldSend = instantiationNotification.ShouldSend(instance);
44+
Instance? instance = null;
45+
try
46+
{
47+
instance = await instanceClient.GetInstance(
48+
app,
49+
org,
50+
instanceOwnerPartyId,
51+
instanceGuid,
52+
StorageAuthenticationMethod.ServiceOwner()
53+
);
54+
}
55+
catch
56+
{
57+
logger.LogWarning(
58+
"Unable to get instance on notification callback - cannot cancel scheduled notification. Does the app support Maskinporten?"
59+
);
60+
}
61+
62+
bool shouldSend = instance is null || instantiationNotification.ShouldSend(instance);
3963

4064
NotificationCallbackResponse response = new() { SendNotification = shouldSend };
4165
return response;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace Altinn.App.Core.Constants;
2+
3+
/// <summary>
4+
/// Constants for Altinn task types.
5+
/// </summary>
6+
internal static class AltinnTaskTypes
7+
{
8+
/// <summary>
9+
/// The payment task type.
10+
/// </summary>
11+
public const string Payment = "payment";
12+
13+
/// <summary>
14+
/// The signing task type.
15+
/// </summary>
16+
public const string Signing = "signing";
17+
18+
/// <summary>
19+
/// The data task type for collecting data from the user in a form.
20+
/// </summary>
21+
public const string Data = "data";
22+
23+
/// <summary>
24+
/// The feedback task type for waiting for a service owner integration to push update the instance.
25+
/// </summary>
26+
public const string Feedback = "feedback";
27+
28+
/// <summary>
29+
/// Service task type for generating a pdf document.
30+
/// </summary>
31+
public const string Pdf = "pdf";
32+
33+
/// <summary>
34+
/// The eFormidling task type when waiting for confirmation that the instance has been sent to eFormidling.
35+
/// </summary>
36+
public const string EFormidling = "eFormidling";
37+
38+
/// <summary>
39+
/// The FiksArkiv task type.
40+
/// </summary>
41+
public const string FiksArkiv = "fiksArkiv";
42+
43+
/// <summary>
44+
/// The confirmation task type. (Simple version of Sign without creating a signature document)
45+
/// </summary>
46+
public const string Confirmation = "confirmation";
47+
48+
/// <summary>
49+
/// Service task type for generating pdf documents from a subform.
50+
/// </summary>
51+
public const string SubformPdf = "subformPdf";
52+
}

src/Altinn.App.Core/Features/Notifications/NotificationService.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ internal static NotificationOrderRequest CreateNotificationOrderRequest(
9696
CustomEmail? customEmail = instantiationNotification.CustomEmail;
9797
EmailSendingOptions emailSettings = new()
9898
{
99-
SendingTimePolicy = sendingTimePolicy,
10099
Subject = customEmail is not null
101100
? NotificationTexts.ReplaceTokens(
102101
text: customEmail.Subject.GetTextForLanguage(language),
@@ -167,7 +166,9 @@ internal static NotificationOrderRequest CreateNotificationOrderRequest(
167166
Uri? conditionEndpoint = null;
168167
if (instantiationNotification.RequestedSendTime is not null)
169168
{
170-
conditionEndpoint = new Uri(callBackBaseUrl?.TrimEnd('/') + "/notifications/" + instance.Id);
169+
conditionEndpoint = new Uri(
170+
callBackBaseUrl?.TrimEnd('/') + "/api/v1/notification-webhook-listener/" + instance.Id
171+
);
171172
}
172173

173174
if (string.IsNullOrWhiteSpace(instanceOwner.OrganisationNumber) is false)
@@ -241,7 +242,8 @@ internal static NotificationOrderRequest CreateNotificationOrderRequest(
241242
RecipientExternalIdentity = new RecipientExternalIdentity
242243
{
243244
ExternalIdentity = instanceOwner.ExternalIdentifier,
244-
ChannelSchema = NotificationChannel.EmailPreferred, // Self identified users may have set a mobile number in profile
245+
ChannelSchema = NotificationChannel.EmailPreferred,
246+
SmsSettings = smsSettings,
245247
EmailSettings = emailSettings,
246248
ResourceId = resourceId.AsUrn,
247249
},
@@ -351,6 +353,9 @@ InstantiationNotificationReminder reminder
351353
EmailSettings = reminder.CustomEmail is not null
352354
? BuildEmailSettings(language, reminder.CustomEmail, ext.EmailSettings)
353355
: ext.EmailSettings,
356+
SmsSettings = reminder.CustomSms is not null
357+
? BuildSmsSettings(language, reminder.CustomSms, ext.SmsSettings)
358+
: ext.SmsSettings,
354359
},
355360
};
356361
}

0 commit comments

Comments
 (0)