Skip to content

Commit

Permalink
return source in validation issues (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit authored Aug 30, 2023
1 parent 8e355e3 commit a77266b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ private List<ValidationIssue> MapModelStateToIssueList(
{
InstanceId = instance.Id,
DataElementId = dataElementId,
Source = ValidationIssueSources.ModelState,
Code = severityAndMessage.Message,
Field = ModelKeyToField(modelKey, modelType)!,
Severity = severityAndMessage.Severity,
Expand Down
3 changes: 2 additions & 1 deletion src/Altinn.App.Core/Internal/Expressions/LayoutEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -108,6 +108,7 @@ private static void RunLayoutValidationsForRequiredRecurs(List<ValidationIssue>
Field = field,
Description = $"{field} is required in component with id {context.Component.Id}",
Code = "required",
Source = ValidationIssueSources.Required
});
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Altinn.App.Core/Models/Validation/ValidationIssueSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

namespace Altinn.App.Core.Models.Validation
{
/// <summary>
/// Specifies the source of a validation issue
/// </summary>
public static class ValidationIssueSources
{
/// <summary>
/// File attachment validation
/// </summary>
public static readonly string File = nameof(File);

/// <summary>
/// Data model validation
/// </summary>
public static readonly string ModelState = nameof(ModelState);

/// <summary>
/// Required field validation
/// </summary>
public static readonly string Required = nameof(Required);
}
}
4 changes: 2 additions & 2 deletions test/Altinn.App.Api.Tests/Controllers/DataControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)}"
Expand Down

0 comments on commit a77266b

Please sign in to comment.