Skip to content

Commit

Permalink
Treat FlowType=AbandonCurrentMoveToNext as reject action (#117)
Browse files Browse the repository at this point in the history
* Associates `AbandonCurrentMoveToNext` with `reject` action
  • Loading branch information
danielskovli authored Oct 10, 2024
1 parent 3a2d775 commit 2823e2a
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions src/Controllers/Storage/ProcessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,45 @@ public ProcessController(
[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;
Instance existingInstance = await _instanceRepository.GetOne(
instanceOwnerPartyId,
instanceGuid
);

existingInstance = await _instanceRepository.GetOne(instanceOwnerPartyId, instanceGuid);

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

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

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

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 @@ -114,7 +109,7 @@ public async Task<ActionResult<Instance>> PutProcess(
}

// Archiving instance if process was ended
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 Down

0 comments on commit 2823e2a

Please sign in to comment.