From cf3da989c4a85ba15bae28662ff37beb5d68a210 Mon Sep 17 00:00:00 2001 From: Daniel Skovli Date: Mon, 2 Dec 2024 13:30:20 +0100 Subject: [PATCH] Update correspondence scope (#943) --- .../Correspondence/Builder/BuilderUtils.cs | 4 ++-- .../CorrespondenceAuthorisationFactory.cs | 2 +- .../Exceptions/CorrespondenceValueException.cs | 18 ------------------ .../Models/CorrespondenceAttachmentResponse.cs | 9 --------- .../Models/CorrespondenceRequest.cs | 10 +++++----- .../Builder/CorrespondenceBuilderTests.cs | 3 --- .../CorrespondenceClientTests.cs | 4 +--- 7 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 src/Altinn.App.Core/Features/Correspondence/Exceptions/CorrespondenceValueException.cs diff --git a/src/Altinn.App.Core/Features/Correspondence/Builder/BuilderUtils.cs b/src/Altinn.App.Core/Features/Correspondence/Builder/BuilderUtils.cs index c6e6aeaec..7c27f9470 100644 --- a/src/Altinn.App.Core/Features/Correspondence/Builder/BuilderUtils.cs +++ b/src/Altinn.App.Core/Features/Correspondence/Builder/BuilderUtils.cs @@ -13,7 +13,7 @@ internal static class BuilderUtils /// /// The value to assert /// The error message to throw, if the value was null - /// + /// internal static void NotNullOrEmpty([NotNull] object? value, string? errorMessage = null) { if ( @@ -23,7 +23,7 @@ value is null || value is DateTimeOffset dt && dt == DateTimeOffset.MinValue ) { - throw new CorrespondenceValueException(errorMessage); + throw new CorrespondenceArgumentException(errorMessage); } } } diff --git a/src/Altinn.App.Core/Features/Correspondence/CorrespondenceAuthorisationFactory.cs b/src/Altinn.App.Core/Features/Correspondence/CorrespondenceAuthorisationFactory.cs index 50f91bec1..43bb91838 100644 --- a/src/Altinn.App.Core/Features/Correspondence/CorrespondenceAuthorisationFactory.cs +++ b/src/Altinn.App.Core/Features/Correspondence/CorrespondenceAuthorisationFactory.cs @@ -15,7 +15,7 @@ internal sealed class CorrespondenceAuthorisationFactory _maskinportenClient ??= _serviceProvider.GetRequiredService(); return await _maskinportenClient.GetAltinnExchangedToken( - ["altinn:correspondence.write", "altinn:serviceowner/instances.read"] + ["altinn:correspondence.write", "altinn:serviceowner"] ); }; diff --git a/src/Altinn.App.Core/Features/Correspondence/Exceptions/CorrespondenceValueException.cs b/src/Altinn.App.Core/Features/Correspondence/Exceptions/CorrespondenceValueException.cs deleted file mode 100644 index bac26c612..000000000 --- a/src/Altinn.App.Core/Features/Correspondence/Exceptions/CorrespondenceValueException.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Altinn.App.Core.Features.Correspondence.Exceptions; - -/// -/// An exception that indicates an invalid value is being used in a correspondence operation -/// -public class CorrespondenceValueException : CorrespondenceException -{ - /// - public CorrespondenceValueException() { } - - /// - public CorrespondenceValueException(string? message) - : base(message) { } - - /// - public CorrespondenceValueException(string? message, Exception? innerException) - : base(message, innerException) { } -} diff --git a/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceAttachmentResponse.cs b/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceAttachmentResponse.cs index e022f542f..9f7e06943 100644 --- a/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceAttachmentResponse.cs +++ b/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceAttachmentResponse.cs @@ -61,15 +61,6 @@ public sealed record CorrespondenceAttachmentResponse [JsonPropertyName("name")] public required string Name { get; init; } - /// - /// The name of the restriction policy restricting access to this element - /// - /// - /// An empty value indicates no restriction above the ones governing the correspondence referencing this attachment - /// - [JsonPropertyName("restrictionName")] - public string? RestrictionName { get; init; } - /// /// Indicates if the attachment is encrypted or not /// diff --git a/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceRequest.cs b/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceRequest.cs index 232c8af3e..7cb0361a4 100644 --- a/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceRequest.cs +++ b/src/Altinn.App.Core/Features/Correspondence/Models/CorrespondenceRequest.cs @@ -13,7 +13,7 @@ public abstract record MultipartCorrespondenceItem internal static void AddRequired(MultipartFormDataContent content, string value, string name) { if (string.IsNullOrWhiteSpace(value)) - throw new CorrespondenceValueException($"Required value is missing: {name}"); + throw new CorrespondenceArgumentException($"Required value is missing: {name}"); content.Add(new StringContent(value), name); } @@ -21,7 +21,7 @@ internal static void AddRequired(MultipartFormDataContent content, string value, internal static void AddRequired(MultipartFormDataContent content, DateTimeOffset value, string name) { if (value == default) - throw new CorrespondenceValueException($"Required value is missing: {name}"); + throw new CorrespondenceArgumentException($"Required value is missing: {name}"); var normalisedAndFormatted = NormaliseDateTime(value).ToString("O"); content.Add(new StringContent(normalisedAndFormatted), name); @@ -35,7 +35,7 @@ string filename ) { if (data.IsEmpty) - throw new CorrespondenceValueException($"Required value is missing: {name}"); + throw new CorrespondenceArgumentException($"Required value is missing: {name}"); content.Add(new ReadOnlyMemoryContent(data), name, filename); } @@ -165,7 +165,7 @@ internal void ValidateAllProperties(string dataTypeName) if (isValid is false) { - throw new CorrespondenceValueException( + throw new CorrespondenceArgumentException( $"Validation failed for {dataTypeName}", new AggregateException(validationResults.Select(x => new ValidationException(x.ErrorMessage))) ); @@ -355,7 +355,7 @@ private static string GetFormattedRecipient(OrganisationOrPersonIdentifier recip { OrganisationOrPersonIdentifier.Organisation org => org.Value.Get(OrganisationNumberFormat.International), OrganisationOrPersonIdentifier.Person person => person.Value.Value, - _ => throw new CorrespondenceValueException( + _ => throw new CorrespondenceArgumentException( $"Unknown {nameof(OrganisationOrPersonIdentifier)} type `{recipient.GetType()}`" ), }; diff --git a/test/Altinn.App.Core.Tests/Features/Correspondence/Builder/CorrespondenceBuilderTests.cs b/test/Altinn.App.Core.Tests/Features/Correspondence/Builder/CorrespondenceBuilderTests.cs index 37cd8c760..e403eec31 100644 --- a/test/Altinn.App.Core.Tests/Features/Correspondence/Builder/CorrespondenceBuilderTests.cs +++ b/test/Altinn.App.Core.Tests/Features/Correspondence/Builder/CorrespondenceBuilderTests.cs @@ -104,7 +104,6 @@ public void Build_WithAllProperties_ShouldReturnValidCorrespondence() data = "attachment-data-1", dataLocationType = CorrespondenceDataLocationType.ExistingCorrespondenceAttachment, isEncrypted = false, - restrictionName = "restriction-name-1", }, new { @@ -116,7 +115,6 @@ public void Build_WithAllProperties_ShouldReturnValidCorrespondence() data = "attachment-data-2", dataLocationType = CorrespondenceDataLocationType.NewCorrespondenceAttachment, isEncrypted = true, - restrictionName = "restriction-name-2", }, new { @@ -128,7 +126,6 @@ public void Build_WithAllProperties_ShouldReturnValidCorrespondence() data = "attachment-data-3", dataLocationType = CorrespondenceDataLocationType.ExisitingExternalStorage, isEncrypted = false, - restrictionName = "restriction-name-3", }, }, existingAttachments = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }, diff --git a/test/Altinn.App.Core.Tests/Features/Correspondence/CorrespondenceClientTests.cs b/test/Altinn.App.Core.Tests/Features/Correspondence/CorrespondenceClientTests.cs index 45e62b47f..168cace69 100644 --- a/test/Altinn.App.Core.Tests/Features/Correspondence/CorrespondenceClientTests.cs +++ b/test/Altinn.App.Core.Tests/Features/Correspondence/CorrespondenceClientTests.cs @@ -378,8 +378,6 @@ var path when path.EndsWith("/correspondence/upload") => TestHelpers.ResponseMes // Assert response.Should().BeEquivalentTo(correspondenceResponse); mockMaskinportenClient.Verify(); - capturedMaskinportenScopes - .Should() - .BeEquivalentTo(["altinn:correspondence.write", "altinn:serviceowner/instances.read"]); + capturedMaskinportenScopes.Should().BeEquivalentTo(["altinn:correspondence.write", "altinn:serviceowner"]); } }