Skip to content

Commit

Permalink
fix: Authorize access to dialog details for any mainresource action
Browse files Browse the repository at this point in the history
  • Loading branch information
elsand committed Sep 11, 2024
1 parent ca81e2b commit 2b705c7
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public sealed class DialogDetailsAuthorizationResult
// e.g. urn:altinn:resource:some-other-resource
public List<AltinnAction> AuthorizedAltinnActions { get; init; } = [];

public bool HasReadAccessToMainResource() =>
AuthorizedAltinnActions.Contains(new(Constants.ReadAction, Constants.MainResource));
public bool HasAccessToMainResource() =>
AuthorizedAltinnActions.Any(action => action.AuthorizationAttribute == Constants.MainResource);

public bool HasReadAccessToDialogTransmission(string? authorizationAttribute)
{
return authorizationAttribute is not null
? ( // Dialog transmissions are authorized by either the read or read action, depending on the authorization attribute type
? ( // Dialog transmissions are authorized by either the read or transmissionRead action, depending on the authorization attribute type
// The infrastructure will ensure that the correct action is used, so here we just check for either
AuthorizedAltinnActions.Contains(new(Constants.TransmissionReadAction, authorizationAttribute))
|| AuthorizedAltinnActions.Contains(new(Constants.ReadAction, authorizationAttribute))
) : HasReadAccessToMainResource();
) : HasAccessToMainResource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<GetDialogActivityResult> Handle(GetDialogActivityQuery request
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to any of the activity history
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<SearchDialogActivityResult> Handle(SearchDialogActivityQuery r
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to any of the activity history
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<GetDialogSeenLogResult> Handle(GetDialogSeenLogQuery request,
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to the seen log
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<SearchDialogSeenLogResult> Handle(SearchDialogSeenLogQuery req
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to the seen log
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<GetDialogTransmissionResult> Handle(GetDialogTransmissionQuery
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to any of the dialog transmissions.
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<SearchDialogTransmissionResult> Handle(SearchDialogTransmissio
cancellationToken: cancellationToken);

// If we cannot read the dialog at all, we don't allow access to any of the activity history
if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo
dialog,
cancellationToken: cancellationToken);

if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo
request.EndUserId,
cancellationToken);

if (!authorizationResult.HasReadAccessToMainResource())
if (!authorizationResult.HasAccessToMainResource())
{
return new EntityNotFound<DialogEntity>(request.DialogId);
}
Expand Down

0 comments on commit 2b705c7

Please sign in to comment.