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

Fix compatibility code in ActionsController to properly handle the obsolete UpdatedDataModels #885

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
30 changes: 19 additions & 11 deletions src/Altinn.App.Api/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
[ProducesResponseType(409)]
[ProducesResponseType(500)]
[ProducesResponseType(401)]
public async Task<ActionResult<UserActionResponse>> Perform(

Check warning on line 77 in src/Altinn.App.Api/Controllers/ActionsController.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
[FromRoute] string org,
[FromRoute] string app,
[FromRoute] int instanceOwnerPartyId,
Expand Down Expand Up @@ -179,6 +179,25 @@
);
}

#pragma warning disable CS0618 // Type or member is obsolete

// Ensure that the data mutator has the previous binary data for the data elements
// that were updated so that it shows up in diff for validation
// and ensures that it gets saved to storage
if (result.UpdatedDataModels is { Count: > 0 })
{
await Task.WhenAll(
result.UpdatedDataModels.Select(row => dataMutator.GetFormData(new DataElementIdentifier(row.Key)))
);
foreach (var (elementId, data) in result.UpdatedDataModels)
{
// If the data mutator missed a that was returned with the deprecated UpdatedDataModels
// we still need to return it to the frontend, but we assume it was already saved to storage
dataMutator.SetFormData(new DataElementIdentifier(elementId), data);
}
}
#pragma warning restore CS0618 // Type or member is obsolete

var changes = dataMutator.GetDataElementChanges(initializeAltinnRowId: true);

await dataMutator.UpdateInstanceData(changes);
Expand All @@ -198,17 +217,6 @@
c => c.CurrentFormData
);

#pragma warning disable CS0618 // Type or member is obsolete
if (result.UpdatedDataModels is { Count: > 0 })
{
foreach (var (elementId, data) in result.UpdatedDataModels)
{
// If the data mutator missed a that was returned with the deprecated UpdatedDataModels
// we still need to return it to the frontend, but we assume it was already saved to storage
updatedDataModels.TryAdd(elementId, data);
}
}
#pragma warning restore CS0618 // Type or member is obsolete
return Ok(
new UserActionResponse()
{
Expand All @@ -233,7 +241,7 @@
{
var taskId =
dataAccessor.Instance.Process?.CurrentTask?.ElementId
?? throw new Exception("Unable to validate instance without a started process.");

Check warning on line 244 in src/Altinn.App.Api/Controllers/ActionsController.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

'System.Exception' should not be thrown by user code. (https://rules.sonarsource.com/csharp/RSPEC-112)
var validationIssues = await _validationService.ValidateIncrementalFormData(
dataAccessor,
taskId,
Expand Down
Loading