From a77266be3fe21b03e3047dcb9bff0acc82687d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20=C3=98sttveit?= <47412359+bjosttveit@users.noreply.github.com> Date: Wed, 30 Aug 2023 10:48:56 +0200 Subject: [PATCH] return source in validation issues (#289) --- .../Features/Validation/ValidationAppSI.cs | 1 + .../Internal/Expressions/LayoutEvaluator.cs | 3 ++- .../Validation/ValidationIssueSource.cs | 24 +++++++++++++++++++ .../Controllers/DataControllerTests.cs | 4 ++-- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/Altinn.App.Core/Models/Validation/ValidationIssueSource.cs diff --git a/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs b/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs index a61be9c38..6b470d90d 100644 --- a/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs +++ b/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs @@ -282,6 +282,7 @@ private List MapModelStateToIssueList( { InstanceId = instance.Id, DataElementId = dataElementId, + Source = ValidationIssueSources.ModelState, Code = severityAndMessage.Message, Field = ModelKeyToField(modelKey, modelType)!, Severity = severityAndMessage.Severity, diff --git a/src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs index c7ac084d2..7bdb31619 100644 --- a/src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs @@ -37,7 +37,7 @@ private static void HiddenFieldsForRemovalReucrs(LayoutEvaluatorState state, Has foreach (var (bindingName, binding) in context.Component.DataModelBindings) { - if(bindingName == "group") + if (bindingName == "group") { continue; } @@ -108,6 +108,7 @@ private static void RunLayoutValidationsForRequiredRecurs(List Field = field, Description = $"{field} is required in component with id {context.Component.Id}", Code = "required", + Source = ValidationIssueSources.Required }); } } diff --git a/src/Altinn.App.Core/Models/Validation/ValidationIssueSource.cs b/src/Altinn.App.Core/Models/Validation/ValidationIssueSource.cs new file mode 100644 index 000000000..00d493a11 --- /dev/null +++ b/src/Altinn.App.Core/Models/Validation/ValidationIssueSource.cs @@ -0,0 +1,24 @@ + +namespace Altinn.App.Core.Models.Validation +{ + /// + /// Specifies the source of a validation issue + /// + public static class ValidationIssueSources + { + /// + /// File attachment validation + /// + public static readonly string File = nameof(File); + + /// + /// Data model validation + /// + public static readonly string ModelState = nameof(ModelState); + + /// + /// Required field validation + /// + public static readonly string Required = nameof(Required); + } +} diff --git a/test/Altinn.App.Api.Tests/Controllers/DataControllerTests.cs b/test/Altinn.App.Api.Tests/Controllers/DataControllerTests.cs index d341e654a..0a72fb397 100644 --- a/test/Altinn.App.Api.Tests/Controllers/DataControllerTests.cs +++ b/test/Altinn.App.Api.Tests/Controllers/DataControllerTests.cs @@ -31,7 +31,7 @@ public async Task CreateDataElement_BinaryPdf_AnalyserShouldRunOk() string org = "tdd"; string app = "contributer-restriction"; HttpClient client = GetRootedClient(org, app); - + Guid guid = new Guid("0fc98a23-fe31-4ef5-8fb9-dd3f479354cd"); TestData.DeleteInstance(org, app, 1337, guid); TestData.PrepareInstance(org, app, 1337, guid); @@ -161,7 +161,7 @@ public class MimeTypeValidatorStub : IFileValidator { ValidationIssue error = new() { - Source = "File", + Source = ValidationIssueSources.File, Code = ValidationIssueCodes.DataElementCodes.ContentTypeNotAllowed, Severity = ValidationIssueSeverity.Error, Description = $"The {fileMimeTypeResult?.Filename + " "}file does not appear to be of the allowed content type according to the configuration for data type {dataType.Id}. Allowed content types are {string.Join(", ", dataType.AllowedContentTypes)}"