Skip to content

Commit

Permalink
Bugfix for missing taskId (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjololo authored Jun 26, 2023
1 parent b60e7ad commit 6e09641
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Controllers/ProcessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public async Task<ActionResult<AppProcessState>> NextElement(

bool authorized;
string checkedAction = EnsureActionNotTaskType(processNext?.Action ?? altinnTaskType);
authorized = await AuthorizeAction(checkedAction, org, app, instanceOwnerPartyId, instanceGuid);
authorized = await AuthorizeAction(checkedAction, org, app, instanceOwnerPartyId, instanceGuid, instance.Process.CurrentTask?.ElementId);

if (!authorized)
{
Expand Down Expand Up @@ -372,7 +372,7 @@ public async Task<ActionResult<AppProcessState>> CompleteProcess(
{
string altinnTaskType = EnsureActionNotTaskType(instance.Process.CurrentTask?.AltinnTaskType);

bool authorized = await AuthorizeAction(altinnTaskType, org, app, instanceOwnerPartyId, instanceGuid);
bool authorized = await AuthorizeAction(altinnTaskType, org, app, instanceOwnerPartyId, instanceGuid, instance.Process.CurrentTask?.ElementId);
if (!authorized)
{
return Forbid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public UniqueSignatureAuthorizer(IProcessReader processReader, IInstanceClient i
/// <inheritdoc />
public async Task<bool> AuthorizeAction(UserActionAuthorizerContext context)
{
if (context.TaskId == null)
{
return true;
}
var flowElement = _processReader.GetFlowElement(context.TaskId) as ProcessTask;
if (flowElement?.ExtensionElements?.TaskExtension?.SignatureConfiguration?.UniqueFromSignaturesInDataTypes.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,37 @@ public async Task AuthorizeAction_returns_false_if_same_user_has_signed_previous
result.Should().BeFalse();
}

[Fact]
public async Task AuthorizeAction_returns_true_if_taskID_is_null()
{
ProcessElement processTask = new ProcessTask()
{
ExtensionElements = new()
{
TaskExtension = new()
{
SignatureConfiguration = new()
{
UniqueFromSignaturesInDataTypes = new()
{
"signature"
}
}
}
}
};
UniqueSignatureAuthorizer authorizer = CreateUniqueSignatureAuthorizer(processTask);
var user = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>()
{
new(AltinnCoreClaimTypes.UserId, "1337"),
new(AltinnCoreClaimTypes.AuthenticationLevel, "2"),
new(AltinnCoreClaimTypes.Org, "tdd")
}));

bool result = await authorizer.AuthorizeAction(new UserActionAuthorizerContext(user, new InstanceIdentifier("500001/abba2e90-f86f-4881-b0e8-38334408bcb4"), null, "sign"));
result.Should().BeTrue();
}

[Fact]
public async Task AuthorizeAction_returns_true_if_dataelement_not_of_type_SignDocument()
{
Expand Down

0 comments on commit 6e09641

Please sign in to comment.