From 9c75f113acc77afd27b08199a0b1e4bd49778e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Fri, 22 Nov 2024 10:45:06 +0100 Subject: [PATCH] feat(graphql): Create separate type for sub-parties (#1510) ## Description ## Related Issue(s) - #1226 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) ## Summary by CodeRabbit - **New Features** - Introduced new fields in the `AuthorizedParty` and `AuthorizedSubParty` types to enhance user representation and relationships. - Added a new type `AuthorizedSubParty` to support nested party structures. - **Bug Fixes** - Improved the `GetAuthorizedParties` method to return a more complex structure, including nested sub-party information. - **Refactor** - Updated class structure and inheritance for `AuthorizedParty` and `AuthorizedSubParty` to facilitate better organization and relationships. --- docs/schema/V1/schema.verified.graphql | 14 +++++++++++++- .../EndUser/Parties/MappingProfile.cs | 1 + .../EndUser/Parties/ObjectTypes.cs | 10 ++++++++-- .../LocalDevelopmentAltinnAuthorization.cs | 19 ++++++++++++++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/docs/schema/V1/schema.verified.graphql b/docs/schema/V1/schema.verified.graphql index c705e8600..d875b0ff8 100644 --- a/docs/schema/V1/schema.verified.graphql +++ b/docs/schema/V1/schema.verified.graphql @@ -66,6 +66,19 @@ type AttachmentUrl { } type AuthorizedParty { + subParties: [AuthorizedSubParty!] + party: String! + name: String! + partyType: String! + isDeleted: Boolean! + hasKeyRole: Boolean! + isCurrentEndUser: Boolean! + isMainAdministrator: Boolean! + isAccessManager: Boolean! + hasOnlyAccessToSubParties: Boolean! +} + +type AuthorizedSubParty { party: String! name: String! partyType: String! @@ -75,7 +88,6 @@ type AuthorizedParty { isMainAdministrator: Boolean! isAccessManager: Boolean! hasOnlyAccessToSubParties: Boolean! - subParties: [AuthorizedParty!] } type Content { diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/MappingProfile.cs index 107c39f61..ff109493b 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/MappingProfile.cs @@ -8,5 +8,6 @@ public sealed class MappingProfile : Profile public MappingProfile() { CreateMap(); + CreateMap(); } } diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/ObjectTypes.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/ObjectTypes.cs index ba9cd46a3..be8bf33fb 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/ObjectTypes.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/Parties/ObjectTypes.cs @@ -1,6 +1,6 @@ namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.Parties; -public sealed class AuthorizedParty +public class AuthorizedPartyBase { public string Party { get; init; } = null!; public string Name { get; init; } = null!; @@ -11,5 +11,11 @@ public sealed class AuthorizedParty public bool IsMainAdministrator { get; init; } public bool IsAccessManager { get; init; } public bool HasOnlyAccessToSubParties { get; init; } - public List? SubParties { get; init; } } + +public sealed class AuthorizedParty : AuthorizedPartyBase +{ + public List? SubParties { get; init; } +} + +public sealed class AuthorizedSubParty : AuthorizedPartyBase; diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/LocalDevelopmentAltinnAuthorization.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/LocalDevelopmentAltinnAuthorization.cs index 2a6be6313..6f7f5c07c 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/LocalDevelopmentAltinnAuthorization.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Authorization/LocalDevelopmentAltinnAuthorization.cs @@ -3,6 +3,7 @@ using Digdir.Domain.Dialogporten.Application.Externals; using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; +using Digdir.Domain.Dialogporten.Domain.Parties; using Digdir.Domain.Dialogporten.Domain.Parties.Abstractions; using Microsoft.EntityFrameworkCore; @@ -53,7 +54,23 @@ public async Task GetAuthorizedResourcesForSear [SuppressMessage("Performance", "CA1822:Mark members as static")] public async Task GetAuthorizedParties(IPartyIdentifier authenticatedParty, bool _ = false, CancellationToken __ = default) - => await Task.FromResult(new AuthorizedPartiesResult { AuthorizedParties = [new() { Name = "Local Party", Party = authenticatedParty.FullId, IsCurrentEndUser = true }] }); + => await Task.FromResult(new AuthorizedPartiesResult + { + AuthorizedParties = [new() + { + Name = "Local Party", + Party = authenticatedParty.FullId, + IsCurrentEndUser = true, + SubParties = [ + new() + { + Name = "Local Sub Party", + Party = NorwegianOrganizationIdentifier.PrefixWithSeparator + "123456789", + IsCurrentEndUser = true + } + ] + }] + }); public Task HasListAuthorizationForDialog(DialogEntity dialog, CancellationToken cancellationToken) => Task.FromResult(true); }