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 #117

Merged
merged 4 commits 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
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
Loading