diff --git a/src/Altinn.App.Core/Features/Validation/Default/ExpressionValidator.cs b/src/Altinn.App.Core/Features/Validation/Default/ExpressionValidator.cs index db0c37a72..121f731b5 100644 --- a/src/Altinn.App.Core/Features/Validation/Default/ExpressionValidator.cs +++ b/src/Altinn.App.Core/Features/Validation/Default/ExpressionValidator.cs @@ -51,12 +51,11 @@ IAppMetadata appMetadata public bool ShouldRunForTask(string taskId) => _appMetadata .GetApplicationMetadata() - .Result.DataTypes.Where(dt => + .Result.DataTypes.Exists(dt => dt.TaskId == taskId && dt.AppLogic?.ClassRef is not null && _appResourceService.GetValidationConfiguration(dt.Id) is not null - ) - .Any(); + ); /// /// This validator has the code "Expression" and this is known by the frontend, who may request this validator to not run for incremental validation. diff --git a/src/Altinn.App.Core/Features/Validation/Wrappers/DataElementValidatorWrapper.cs b/src/Altinn.App.Core/Features/Validation/Wrappers/DataElementValidatorWrapper.cs index 5e24d6241..e9ca6f06d 100644 --- a/src/Altinn.App.Core/Features/Validation/Wrappers/DataElementValidatorWrapper.cs +++ b/src/Altinn.App.Core/Features/Validation/Wrappers/DataElementValidatorWrapper.cs @@ -11,17 +11,11 @@ internal class DataElementValidatorWrapper : IValidator { private readonly IDataElementValidator _dataElementValidator; private readonly string _taskId; - private readonly List _dataTypes; - public DataElementValidatorWrapper( - IDataElementValidator dataElementValidator, - string taskId, - List dataTypes - ) + public DataElementValidatorWrapper(IDataElementValidator dataElementValidator, string taskId) { _dataElementValidator = dataElementValidator; _taskId = taskId; - _dataTypes = dataTypes; } /// diff --git a/src/Altinn.App.Core/Implementation/AppResourcesSI.cs b/src/Altinn.App.Core/Implementation/AppResourcesSI.cs index b0ce67d02..cf9e7e565 100644 --- a/src/Altinn.App.Core/Implementation/AppResourcesSI.cs +++ b/src/Altinn.App.Core/Implementation/AppResourcesSI.cs @@ -499,8 +499,8 @@ private static byte[] ReadFileContentsFromLegalPath(string legalPath, string fil public string? GetValidationConfiguration(string dataTypeId) { using var activity = _telemetry?.StartGetValidationConfigurationActivity(); - string legalPath = $"{_settings.AppBasePath}{_settings.ModelsFolder}"; - string filename = $"{legalPath}{dataTypeId}.{_settings.ValidationConfigurationFileName}"; + string legalPath = Path.Join(_settings.AppBasePath, _settings.ModelsFolder); + string filename = Path.Join(legalPath, $"{dataTypeId}.{_settings.ValidationConfigurationFileName}"); PathHelper.EnsureLegalPath(legalPath, filename); string? filedata = null; diff --git a/src/Altinn.App.Core/Internal/Validation/IValidatorFactory.cs b/src/Altinn.App.Core/Internal/Validation/IValidatorFactory.cs index 7979013c3..1b9480fb9 100644 --- a/src/Altinn.App.Core/Internal/Validation/IValidatorFactory.cs +++ b/src/Altinn.App.Core/Internal/Validation/IValidatorFactory.cs @@ -132,8 +132,7 @@ public IEnumerable GetValidators(string taskId) var dataTypes = _appMetadata.GetApplicationMetadata().Result.DataTypes; validators.AddRange( - GetDataElementValidators(taskId, dataTypes) - .Select(dev => new DataElementValidatorWrapper(dev, taskId, dataTypes)) + GetDataElementValidators(taskId, dataTypes).Select(dev => new DataElementValidatorWrapper(dev, taskId)) ); validators.AddRange( GetFormDataValidators(taskId, dataTypes).Select(fdv => new FormDataValidatorWrapper(fdv, taskId)) diff --git a/test/Altinn.App.Api.Tests/Controllers/ActionsControllerTests.cs b/test/Altinn.App.Api.Tests/Controllers/ActionsControllerTests.cs index 0a8c71ff4..dd23f41ec 100644 --- a/test/Altinn.App.Api.Tests/Controllers/ActionsControllerTests.cs +++ b/test/Altinn.App.Api.Tests/Controllers/ActionsControllerTests.cs @@ -580,7 +580,9 @@ public async Task HandleAction(UserActionContext context) ); break; case "update": - var originalDataElement = context.DataMutator.GetDataElementsForType("Scheme").First(); + var dataType = + context.DataMutator.GetDataType("Scheme") ?? throw new Exception("DataType \"Scheme\" not found"); + var originalDataElement = context.DataMutator.GetDataElementsForType(dataType).First(); var data = await context.DataMutator.GetFormData(originalDataElement); data.TestCustomButtonReadOnlyInput = "Her kommer det data fra backend"; diff --git a/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_FailingValidator_ReturnsValidationErrors.verified.txt b/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_FailingValidator_ReturnsValidationErrors.verified.txt index 59102fb39..baa654b72 100644 --- a/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_FailingValidator_ReturnsValidationErrors.verified.txt +++ b/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_FailingValidator_ReturnsValidationErrors.verified.txt @@ -4,6 +4,18 @@ ActivityName: ApplicationMetadata.Service.GetLayoutModel, IdFormat: W3C }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutModel, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSet, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSet, + IdFormat: W3C + }, { ActivityName: ApplicationMetadata.Service.GetLayoutSet, IdFormat: W3C @@ -28,20 +40,28 @@ ActivityName: ApplicationMetadata.Service.GetLayoutSets, IdFormat: W3C }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSets, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSets, + IdFormat: W3C + }, { ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, + ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetValidationConfiguration, + ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetValidationConfiguration, + ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, IdFormat: W3C }, { @@ -153,6 +173,21 @@ ], IdFormat: W3C }, + { + ActivityName: Validation.RunValidator, + Tags: [ + { + validation.issue_count: 0 + }, + { + validator.source: Expression + }, + { + validator.type: ExpressionValidator + } + ], + IdFormat: W3C + }, { ActivityName: Validation.RunValidator, Tags: [ diff --git a/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_PdfFails_DataIsUnlocked.verified.txt b/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_PdfFails_DataIsUnlocked.verified.txt index 27cd52551..3471d54fa 100644 --- a/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_PdfFails_DataIsUnlocked.verified.txt +++ b/test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.RunProcessNext_PdfFails_DataIsUnlocked.verified.txt @@ -4,6 +4,18 @@ ActivityName: ApplicationMetadata.Service.GetLayoutModel, IdFormat: W3C }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutModel, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSet, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSet, + IdFormat: W3C + }, { ActivityName: ApplicationMetadata.Service.GetLayoutSet, IdFormat: W3C @@ -28,28 +40,36 @@ ActivityName: ApplicationMetadata.Service.GetLayoutSets, IdFormat: W3C }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSets, + IdFormat: W3C + }, + { + ActivityName: ApplicationMetadata.Service.GetLayoutSets, + IdFormat: W3C + }, { ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, + ActivityName: ApplicationMetadata.Service.GetLayoutSetsForTask, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetTexts, + ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetTexts, + ActivityName: ApplicationMetadata.Service.GetLayoutSettingsForSet, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetValidationConfiguration, + ActivityName: ApplicationMetadata.Service.GetTexts, IdFormat: W3C }, { - ActivityName: ApplicationMetadata.Service.GetValidationConfiguration, + ActivityName: ApplicationMetadata.Service.GetTexts, IdFormat: W3C }, { @@ -283,6 +303,21 @@ ], IdFormat: W3C }, + { + ActivityName: Validation.RunValidator, + Tags: [ + { + validation.issue_count: 0 + }, + { + validator.source: Expression + }, + { + validator.type: ExpressionValidator + } + ], + IdFormat: W3C + }, { ActivityName: Validation.RunValidator, Tags: [ diff --git a/test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/default.validation.json b/test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/default.validation.json new file mode 100644 index 000000000..73f38c259 --- /dev/null +++ b/test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/default.validation.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/validation/validation.schema.v1.json", + "validations": { + "melding.name": [ + { + "condition": [ + "equals", + [ + "dataModel", + "melding.name" + ], + "Model" + ], + "message": "The file must be of type Model" + } + ] + } +}