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

Treat FlowType=AbandonCurrentMoveToNext as reject action #526

Merged
merged 1 commit into from
Oct 10, 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
51 changes: 20 additions & 31 deletions src/Storage/Controllers/ProcessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/// </summary>
[Route("storage/api/v1/instances/{instanceOwnerPartyId:int}/{instanceGuid:guid}/process")]
[ApiController]
public class ProcessController : ControllerBase

Check warning on line 28 in src/Storage/Controllers/ProcessController.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

This controller has multiple responsibilities and could be split into 2 smaller controllers. (https://rules.sonarsource.com/csharp/RSPEC-6960)
{
private readonly IInstanceRepository _instanceRepository;
private readonly IInstanceEventRepository _instanceEventRepository;
Expand Down Expand Up @@ -69,48 +69,39 @@
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Produces("application/json")]
public async Task<ActionResult<Instance>> PutProcess(
int instanceOwnerPartyId,
Guid instanceGuid,
[FromBody] ProcessState processState)
int instanceOwnerPartyId,
Guid instanceGuid,
[FromBody] ProcessState processState)
{
(Instance existingInstance, _) = await _instanceRepository.GetOne(instanceGuid, true);

if (existingInstance == null)
if (existingInstance is null)
{
return NotFound();
}

string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType;
string taskId = null;
string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType;

var moveNextFlows = new[] { "CompleteCurrentMoveToNext", "AbandonCurrentMoveToNext" };
if (processState?.CurrentTask?.FlowType is not null && !moveNextFlows.Contains(processState.CurrentTask.FlowType))
if (processState?.CurrentTask?.FlowType == "AbandonCurrentMoveToNext")
{
altinnTaskType = "reject";
}
else if (processState?.CurrentTask?.FlowType is not null
&& processState.CurrentTask.FlowType != "CompleteCurrentMoveToNext")
{
altinnTaskType = processState.CurrentTask.AltinnTaskType;
taskId = processState.CurrentTask.ElementId;
}

string action;

switch (altinnTaskType)
string action = altinnTaskType switch
{
case "data":
case "feedback":
action = "write";
break;
case "payment":
action = "pay";
break;
case "confirmation":
action = "confirm";
break;
case "signing":
action = "sign";
break;
default:
action = altinnTaskType;
break;
}
"data" or "feedback" => "write",
"payment" => "pay",
"confirmation" => "confirm",
"signing" => "sign",
_ => altinnTaskType,
};

bool authorized = await _authorizationService.AuthorizeInstanceAction(existingInstance, action, taskId);

Expand All @@ -125,7 +116,7 @@
nameof(existingInstance.LastChanged),
nameof(existingInstance.LastChangedBy)
];
if (existingInstance.Process.Ended == null && processState?.Ended != null)
if (existingInstance.Process?.Ended is null && processState?.Ended is not null)
{
existingInstance.Status ??= new InstanceStatus();
existingInstance.Status.IsArchived = true;
Expand All @@ -139,9 +130,7 @@
existingInstance.LastChangedBy = User.GetUserOrOrgId();
existingInstance.LastChanged = DateTime.UtcNow;

Instance updatedInstance;

updatedInstance = await _instanceRepository.Update(existingInstance, updateProperties);
Instance updatedInstance = await _instanceRepository.Update(existingInstance, updateProperties);

if (processState?.CurrentTask?.AltinnTaskType == "signing")
{
Expand Down
Loading