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

feat: Add current user flag to parties dto #993

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,9 @@
"hasKeyRole": {
"type": "boolean"
},
"isCurrentUser": {
"type": "boolean"
},
"isMainAdministrator": {
"type": "boolean"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AuthorizedParty
public AuthorizedPartyType PartyType { get; init; }
public bool IsDeleted { get; init; }
public bool HasKeyRole { get; init; }
public bool IsCurrentUser { get; set; }
public bool IsMainAdministrator { get; init; }
public bool IsAccessManager { get; init; }
public bool HasOnlyAccessToSubParties { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AuthorizedPartyDto
public string PartyType { get; init; } = null!;
public bool IsDeleted { get; init; }
public bool HasKeyRole { get; init; }
public bool IsCurrentUser { get; init; }
public bool IsMainAdministrator { get; init; }
public bool IsAccessManager { get; init; }
public bool HasOnlyAccessToSubParties { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private async Task<AuthorizedPartiesResult> PerformAuthorizedPartiesRequest(Auth
CancellationToken token)
{
var authorizedPartiesDto = await SendAuthorizedPartiesRequest(authorizedPartiesRequest, token);
return AuthorizedPartiesHelper.CreateAuthorizedPartiesResult(authorizedPartiesDto);
return AuthorizedPartiesHelper.CreateAuthorizedPartiesResult(authorizedPartiesDto, authorizedPartiesRequest);
}

private async Task<DialogSearchAuthorizationResult> PerformNonScalableDialogSearchAuthorization(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Xml;
using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization;
using Digdir.Domain.Dialogporten.Domain.Parties;

Expand All @@ -11,21 +12,23 @@ internal static class AuthorizedPartiesHelper
private const string MainAdministratorRoleCode = "HADM";
private const string AccessManagerRoleCode = "ADMAI";
private static readonly string[] KeyRoleCodes = ["DAGL", "LEDE", "INNH", "DTPR", "DTSO", "BEST"];
public static AuthorizedPartiesResult CreateAuthorizedPartiesResult(List<AuthorizedPartiesResultDto>? authorizedPartiesDto)
public static AuthorizedPartiesResult CreateAuthorizedPartiesResult(
List<AuthorizedPartiesResultDto>? authorizedPartiesDto,
AuthorizedPartiesRequest authorizedPartiesRequest)
{
var result = new AuthorizedPartiesResult();
if (authorizedPartiesDto is not null)
{
foreach (var authorizedPartyDto in authorizedPartiesDto)
{
result.AuthorizedParties.Add(MapFromDto(authorizedPartyDto));
result.AuthorizedParties.Add(MapFromDto(authorizedPartyDto, authorizedPartiesRequest.Value));
}
}

return result;
}

private static AuthorizedParty MapFromDto(AuthorizedPartiesResultDto dto)
private static AuthorizedParty MapFromDto(AuthorizedPartiesResultDto dto, string currentUserValue)
{
var party = dto.Type switch
{
Expand All @@ -46,11 +49,12 @@ private static AuthorizedParty MapFromDto(AuthorizedPartiesResultDto dto)
},
IsDeleted = dto.IsDeleted,
HasKeyRole = dto.AuthorizedRoles.Exists(role => KeyRoleCodes.Contains(role)),
IsCurrentUser = dto.PersonId == currentUserValue,
IsMainAdministrator = dto.AuthorizedRoles.Contains(MainAdministratorRoleCode),
IsAccessManager = dto.AuthorizedRoles.Contains(AccessManagerRoleCode),
HasOnlyAccessToSubParties = dto.OnlyHierarchyElementWithNoAccess,
AuthorizedResources = GetPrefixedResources(dto.AuthorizedResources),
SubParties = dto.Subunits.Count > 0 ? dto.Subunits.Select(MapFromDto).ToList() : null
SubParties = dto.Subunits.Count > 0 ? dto.Subunits.Select(x => MapFromDto(x, currentUserValue)).ToList() : null
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ public async Task<DialogSearchAuthorizationResult> GetAuthorizedResourcesForSear
}

public async Task<AuthorizedPartiesResult> GetAuthorizedParties(IPartyIdentifier authenticatedParty, CancellationToken cancellationToken = default)
=> await Task.FromResult(new AuthorizedPartiesResult { AuthorizedParties = [new() { Name = "Local Party", Party = authenticatedParty.FullId }] });
=> await Task.FromResult(new AuthorizedPartiesResult { AuthorizedParties = [new() { Name = "Local Party", Party = authenticatedParty.FullId, IsCurrentUser = true }] });
}
Loading