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

Send language to IUserAction's when running process/next #872

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/Altinn.App.Api/Controllers/ProcessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ public async Task<ActionResult<AppProcessState>> NextElement(
{
Instance = instance,
User = User,
Action = checkedAction
Action = checkedAction,
Language = language
};
var validationProblem = await GetValidationProblemDetails(instance, currentTaskId, language);
if (validationProblem is not null)
Expand Down Expand Up @@ -546,7 +547,8 @@ instance.Process.EndEvent is null
{
Instance = instance,
User = User,
Action = altinnTaskType
Action = altinnTaskType,
Language = language,
};
var result = await _processEngine.Next(request);

Expand Down
4 changes: 3 additions & 1 deletion src/Altinn.App.Core/Internal/Process/ProcessEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
return result;
}

// TODO: assert can be removed when we improve nullability annotation in GetValidStartEventOrError

Check warning on line 107 in src/Altinn.App.Core/Internal/Process/ProcessEngine.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
Debug.Assert(
validStartElement is not null,
"validStartElement should always be nonnull when startEventError is null"
Expand Down Expand Up @@ -181,7 +181,9 @@

UserActionResult actionResult = actionHandler is null
? UserActionResult.SuccessResult()
: await actionHandler.HandleAction(new UserActionContext(cachedDataMutator, userId));
: await actionHandler.HandleAction(
new UserActionContext(cachedDataMutator, userId, language: request.Language)
);

if (actionResult.ResultType != ResultType.Success)
{
Expand Down
14 changes: 8 additions & 6 deletions src/Altinn.App.Core/Models/Process/ProcessNextRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ namespace Altinn.App.Core.Models.Process;
/// </summary>
public class ProcessNextRequest
{
#nullable disable
/// <summary>
/// The instance to be moved to the next task
/// </summary>
public Instance Instance { get; set; }
public required Instance Instance { get; init; }

/// <summary>
/// The user that is performing the action
/// </summary>
public ClaimsPrincipal User { get; set; }

#nullable restore
public required ClaimsPrincipal User { get; init; }

/// <summary>
/// The action that is performed
/// </summary>
public string? Action { get; set; }
public required string? Action { get; init; }

/// <summary>
/// The language the user sent with process/next (not required)
/// </summary>
public required string? Language { get; init; }
}
38 changes: 32 additions & 6 deletions test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ public async Task Next_returns_unsuccessful_when_process_null()
AppId = "org/app",
Process = null
};
ProcessNextRequest processNextRequest = new ProcessNextRequest() { Instance = instance };
ProcessNextRequest processNextRequest = new ProcessNextRequest()
{
Instance = instance,
Action = null,
User = null!,
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
result.Success.Should().BeFalse();
result.ErrorMessage.Should().Be("Instance does not have current task information!");
Expand All @@ -386,7 +392,13 @@ public async Task Next_returns_unsuccessful_when_process_currenttask_null()
AppId = "org/app",
Process = new ProcessState() { CurrentTask = null }
};
ProcessNextRequest processNextRequest = new ProcessNextRequest() { Instance = instance };
ProcessNextRequest processNextRequest = new ProcessNextRequest()
{
Instance = instance,
User = null!,
Action = null,
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
result.Success.Should().BeFalse();
result.ErrorMessage.Should().Be("Instance does not have current task information!");
Expand Down Expand Up @@ -448,7 +460,8 @@ public async Task Next_returns_unsuccessful_unauthorized_when_action_handler_ret
{
Instance = instance,
User = user,
Action = "sign"
Action = "sign",
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
result.Success.Should().BeFalse();
Expand Down Expand Up @@ -510,7 +523,13 @@ public async Task Next_moves_instance_to_next_task_and_produces_instanceevents()
}
)
);
ProcessNextRequest processNextRequest = new ProcessNextRequest() { Instance = instance, User = user };
ProcessNextRequest processNextRequest = new ProcessNextRequest()
{
Instance = instance,
User = user,
Action = null,
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
_processReaderMock.Verify(r => r.IsProcessTask("Task_1"), Times.Once);
_processReaderMock.Verify(r => r.IsEndEvent("Task_2"), Times.Once);
Expand Down Expand Up @@ -662,7 +681,8 @@ public async Task Next_moves_instance_to_next_task_and_produces_abandon_instance
{
Instance = instance,
User = user,
Action = "reject"
Action = "reject",
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
_processReaderMock.Verify(r => r.IsProcessTask("Task_1"), Times.Once);
Expand Down Expand Up @@ -800,7 +820,13 @@ public async Task Next_moves_instance_to_end_event_and_ends_proces()
}
)
);
ProcessNextRequest processNextRequest = new ProcessNextRequest() { Instance = instance, User = user };
ProcessNextRequest processNextRequest = new ProcessNextRequest()
{
Instance = instance,
User = user,
Action = null,
Language = null
};
ProcessChangeResult result = await processEngine.Next(processNextRequest);
_processReaderMock.Verify(r => r.IsProcessTask("Task_2"), Times.Once);
_processReaderMock.Verify(r => r.IsEndEvent("EndEvent_1"), Times.Once);
Expand Down
Loading