Skip to content

Commit

Permalink
update settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit committed Sep 21, 2023
1 parent ee4527a commit 618ab86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
14 changes: 12 additions & 2 deletions src/Altinn.App.Core/Configuration/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,18 @@ public string GetResourceFolder()
public string AppVersion { get; set; }

Check warning on line 224 in src/Altinn.App.Core/Configuration/AppSettings.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 224 in src/Altinn.App.Core/Configuration/AppSettings.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 224 in src/Altinn.App.Core/Configuration/AppSettings.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (windows-latest)

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 224 in src/Altinn.App.Core/Configuration/AppSettings.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

Non-nullable property 'AppVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

/// <summary>
/// Enable the preview functionality to load layout in backend and remove data from hidden components before validation and task completion
/// Enable the functionality to load layout in backend and remove data from hidden components before task completion
/// </summary>
public bool RemoveHiddenDataPreview { get; set; } = false;
public bool RemoveHiddenData { get; set; } = false;

/// <summary>
/// Enable the functionality to load layout in backend and validate required fields as defined in the layout
/// </summary>
public bool RequiredValidation { get; set; } = false;

/// <summary>
/// Enable the functionality to run expression validation in backend
/// </summary>
public bool ExpressionValidation { get; set; } = false;
}
}
26 changes: 18 additions & 8 deletions src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,29 @@ public async Task<List<ValidationIssue>> ValidateDataElement(Instance instance,
object data = await _dataClient.GetFormData(
instanceGuid, modelType, instance.Org, app, instanceOwnerPartyId, Guid.Parse(dataElement.Id));

if (_appSettings.RemoveHiddenDataPreview)
LayoutEvaluatorState? evaluationState = null;

// Remove hidden data before validation
if (_appSettings.RequiredValidation || _appSettings.ExpressionValidation)
{

var layoutSet = _appResourcesService.GetLayoutSetForTask(dataType.TaskId);
var evaluationState = await _layoutEvaluatorStateInitializer.Init(instance, data, layoutSet?.Id);
// Remove hidden data before validation
evaluationState = await _layoutEvaluatorStateInitializer.Init(instance, data, layoutSet?.Id);
LayoutEvaluator.RemoveHiddenData(evaluationState);
// Evaluate expressions in layout and validate that all required data is included and that maxLength
// is respected on groups
var layoutErrors = LayoutEvaluator.RunLayoutValidationsForRequired(evaluationState, dataElement.Id);
}

// Evaluate expressions in layout and validate that all required data is included and that maxLength
// is respected on groups
if (_appSettings.RequiredValidation)
{
var layoutErrors = LayoutEvaluator.RunLayoutValidationsForRequired(evaluationState!, dataElement.Id);
messages.AddRange(layoutErrors);
}

// Run expression validations
var expressionErrors = ExpressionValidator.Validate(dataType.Id, _appResourcesService, new DataModel(data), evaluationState, _logger);
// Run expression validations
if (_appSettings.ExpressionValidation)
{
var expressionErrors = ExpressionValidator.Validate(dataType.Id, _appResourcesService, new DataModel(data), evaluationState!, _logger);
messages.AddRange(expressionErrors);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Altinn.App.Core/Implementation/DefaultTaskEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task OnEndProcessTask(string endEvent, Instance instance)

private async Task RunRemoveHiddenData(Instance instance, Guid instanceGuid, List<DataType>? dataTypesToLock)
{
if (_appSettings?.RemoveHiddenDataPreview == true)
if (_appSettings?.RemoveHiddenData == true)
{
await RemoveHiddenData(instance, instanceGuid, dataTypesToLock);
}
Expand Down Expand Up @@ -269,9 +269,9 @@ private async Task RemoveHiddenData(Instance instance, Guid instanceGuid, List<D
object data = await _dataClient.GetFormData(
instanceGuid, modelType, instance.Org, app, instanceOwnerPartyId, dataElementId);

if (_appSettings?.RemoveHiddenDataPreview == true)
if (_appSettings?.RemoveHiddenData == true)
{
// Remove hidden data before validation
// Remove hidden data before process next
var layoutSet = _appResources.GetLayoutSetForTask(dataType.TaskId);
var evaluationState = await _layoutEvaluatorStateInitializer.Init(instance, data, layoutSet?.Id);
LayoutEvaluator.RemoveHiddenData(evaluationState, true);
Expand Down

0 comments on commit 618ab86

Please sign in to comment.