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

Update correspondence scope #943

Merged
merged 4 commits into from
Dec 2, 2024
Merged
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 @@ -13,7 +13,7 @@ internal static class BuilderUtils
/// </summary>
/// <param name="value">The value to assert</param>
/// <param name="errorMessage">The error message to throw, if the value was null</param>
/// <exception cref="CorrespondenceValueException"></exception>
/// <exception cref="CorrespondenceArgumentException"></exception>
internal static void NotNullOrEmpty([NotNull] object? value, string? errorMessage = null)
{
if (
Expand All @@ -23,7 +23,7 @@ value is null
|| value is DateTimeOffset dt && dt == DateTimeOffset.MinValue
)
{
throw new CorrespondenceValueException(errorMessage);
throw new CorrespondenceArgumentException(errorMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class CorrespondenceAuthorisationFactory
_maskinportenClient ??= _serviceProvider.GetRequiredService<IMaskinportenClient>();

return await _maskinportenClient.GetAltinnExchangedToken(
["altinn:correspondence.write", "altinn:serviceowner/instances.read"]
["altinn:correspondence.write", "altinn:serviceowner"]
);
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ public sealed record CorrespondenceAttachmentResponse
[JsonPropertyName("name")]
public required string Name { get; init; }

/// <summary>
/// The name of the restriction policy restricting access to this element
/// </summary>
/// <remarks>
/// An empty value indicates no restriction above the ones governing the correspondence referencing this attachment
/// </remarks>
[JsonPropertyName("restrictionName")]
public string? RestrictionName { get; init; }

/// <summary>
/// Indicates if the attachment is encrypted or not
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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);
}

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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)))
);
Expand Down Expand Up @@ -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()}`"
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public void Build_WithAllProperties_ShouldReturnValidCorrespondence()
data = "attachment-data-1",
dataLocationType = CorrespondenceDataLocationType.ExistingCorrespondenceAttachment,
isEncrypted = false,
restrictionName = "restriction-name-1",
},
new
{
Expand All @@ -116,7 +115,6 @@ public void Build_WithAllProperties_ShouldReturnValidCorrespondence()
data = "attachment-data-2",
dataLocationType = CorrespondenceDataLocationType.NewCorrespondenceAttachment,
isEncrypted = true,
restrictionName = "restriction-name-2",
},
new
{
Expand All @@ -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() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}
}
Loading