Skip to content

Commit

Permalink
Send language to IUserAction's when running process/next (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarne authored Nov 1, 2024
1 parent ee9f294 commit 44b20b4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
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 @@ -181,7 +181,9 @@ await _appMetadata.GetApplicationMetadata(),

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

0 comments on commit 44b20b4

Please sign in to comment.