Skip to content

Commit 667881c

Browse files
authored
Move loading customers for agent system users to BFF (#1359)
* move loading agent system users customers to backend * fixes * fix spacing
1 parent 1d50a59 commit 667881c

File tree

6 files changed

+71
-126
lines changed

6 files changed

+71
-126
lines changed

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Services/Interfaces/ISystemUserAgentDelegationService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ namespace Altinn.AccessManagement.UI.Core.Services.Interfaces
1111
public interface ISystemUserAgentDelegationService
1212
{
1313
/// <summary>
14-
/// Return all customers of a specific type for party
14+
/// Return all customers for given system user
1515
/// </summary>
16-
/// <param name="partyUuid">The party UUID of the party to retrieve customers from</param>
17-
/// <param name="customerType">Customer type to get</param>
16+
/// <param name="partyId">The party id of the party owning system user</param>
17+
/// <param name="partyUuid">The party uuid of the party owning system user</param>
18+
/// <param name="systemUserGuid">The system user UUID to get customers from</param>
1819
/// <param name="cancellationToken">Cancellation token</param>
19-
/// <returns>List of all party customers</returns>
20-
Task<List<AgentDelegationPartyFE>> GetPartyCustomers(Guid partyUuid, CustomerRoleType customerType, CancellationToken cancellationToken);
20+
/// <returns>List of all systemuser customers</returns>
21+
Task<List<AgentDelegationPartyFE>> GetSystemUserCustomers(int partyId, Guid partyUuid, Guid systemUserGuid, CancellationToken cancellationToken);
2122

2223
/// <summary>
2324
/// Return delegated customers for this system user

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Services/SystemUserAgentDelegationService.cs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,56 @@ namespace Altinn.AccessManagement.UI.Core.Services
1212
public class SystemUserAgentDelegationService : ISystemUserAgentDelegationService
1313
{
1414
private readonly ISystemUserAgentDelegationClient _systemUserAgentDelegationClient;
15+
private readonly ISystemUserClient _systemUserClient;
1516
private readonly IRegisterClient _registerClient;
1617

1718
/// <summary>
1819
/// Initializes a new instance of the <see cref="SystemUserAgentDelegationService"/> class.
1920
/// </summary>
2021
/// <param name="systemUserAgentDelegationClient">The system user client administration client.</param>
22+
/// <param name="systemUserClient">The system user client</param>
2123
/// <param name="registerClient">The register client</param>
2224
public SystemUserAgentDelegationService(
2325
ISystemUserAgentDelegationClient systemUserAgentDelegationClient,
26+
ISystemUserClient systemUserClient,
2427
IRegisterClient registerClient)
2528
{
2629
_systemUserAgentDelegationClient = systemUserAgentDelegationClient;
30+
_systemUserClient = systemUserClient;
2731
_registerClient = registerClient;
2832
}
29-
30-
/// <inheritdoc />
31-
public async Task<List<AgentDelegationPartyFE>> GetPartyCustomers(Guid partyUuid, CustomerRoleType customerType, CancellationToken cancellationToken)
33+
34+
/// <inheritdoc />
35+
public async Task<List<AgentDelegationPartyFE>> GetSystemUserCustomers(int partyId, Guid partyUuid, Guid systemUserGuid, CancellationToken cancellationToken)
3236
{
33-
CustomerList regnskapsforerCustomers = await _registerClient.GetPartyCustomers(partyUuid, customerType, cancellationToken);
34-
return MapCustomerListToCustomerFE(regnskapsforerCustomers);
37+
// get access packages from systemuser
38+
SystemUser systemUser = await _systemUserClient.GetAgentSystemUser(partyId, systemUserGuid, cancellationToken);
39+
IEnumerable<string> accessPackageUrns = systemUser.AccessPackages.Select(x => x.Urn);
40+
CustomerRoleType customerType;
41+
42+
List<string> regnskapsforerPackages = ["urn:altinn:accesspackage:regnskapsforer-med-signeringsrettighet", "urn:altinn:accesspackage:regnskapsforer-uten-signeringsrettighet", "urn:altinn:accesspackage:regnskapsforer-lonn"];
43+
List<string> revisorPackages = ["urn:altinn:accesspackage:ansvarlig-revisor", "urn:altinn:accesspackage:revisormedarbeider"];
44+
List<string> forretningsforerPackages = ["urn:altinn:accesspackage:skattegrunnlag"];
45+
46+
if (accessPackageUrns.Any(x => regnskapsforerPackages.Contains(x)))
47+
{
48+
customerType = CustomerRoleType.Regnskapsforer;
49+
}
50+
else if (accessPackageUrns.Any(x => revisorPackages.Contains(x)))
51+
{
52+
customerType = CustomerRoleType.Revisor;
53+
}
54+
else if (accessPackageUrns.Any(x => forretningsforerPackages.Contains(x)))
55+
{
56+
customerType = CustomerRoleType.Forretningsforer;
57+
}
58+
else
59+
{
60+
customerType = CustomerRoleType.None;
61+
}
62+
63+
CustomerList customers = await _registerClient.GetPartyCustomers(partyUuid, customerType, cancellationToken);
64+
return MapCustomerListToCustomerFE(customers);
3565
}
3666

3767
/// <inheritdoc />

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Tests/Controllers/SystemUserAgentDelegationControllerTest.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ public async Task GetRegnskapsforerCustomers_ReturnsCustomers()
4444
{
4545
// Arrange
4646
string partyUuid = "cd35779b-b174-4ecc-bbef-ece13611be7f";
47+
string partyId = "51329012";
48+
string systemUserId = _regnskapsforerSystemUserId;
4749
string path = Path.Combine(_expectedDataPath, "SystemUser", "regnskapsforerCustomers.json");
4850
List<AgentDelegationPartyFE> expectedResponse = Util.GetMockData<List<AgentDelegationPartyFE>>(path);
4951

5052
// Act
51-
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyUuid}/customers/regnskapsforer");
53+
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyId}/{partyUuid}/{systemUserId}/customers");
5254
List<AgentDelegationPartyFE> actualResponse = await httpResponse.Content.ReadFromJsonAsync<List<AgentDelegationPartyFE>>();
5355

5456
// Assert
@@ -65,11 +67,13 @@ public async Task GetRevisorCustomers_ReturnsCustomers()
6567
{
6668
// Arrange
6769
string partyUuid = "cd35779b-b174-4ecc-bbef-ece13611be7f";
70+
string partyId = "51329012";
71+
string systemUserId = _revisorSystemUserId;
6872
string path = Path.Combine(_expectedDataPath, "SystemUser", "revisorCustomers.json");
6973
List<AgentDelegationPartyFE> expectedResponse = Util.GetMockData<List<AgentDelegationPartyFE>>(path);
7074

7175
// Act
72-
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyUuid}/customers/revisor");
76+
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyId}/{partyUuid}/{systemUserId}/customers");
7377
List<AgentDelegationPartyFE> actualResponse = await httpResponse.Content.ReadFromJsonAsync<List<AgentDelegationPartyFE>>();
7478

7579
// Assert
@@ -86,11 +90,13 @@ public async Task GetForretningsforerCustomers_ReturnsCustomers()
8690
{
8791
// Arrange
8892
string partyUuid = "cd35779b-b174-4ecc-bbef-ece13611be7f";
93+
string partyId = "51329012";
94+
string systemUserId = _forretningsforerSystemUserId;
8995
string path = Path.Combine(_expectedDataPath, "SystemUser", "forretningsforerCustomers.json");
9096
List<AgentDelegationPartyFE> expectedResponse = Util.GetMockData<List<AgentDelegationPartyFE>>(path);
9197

9298
// Act
93-
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyUuid}/customers/forretningsforer");
99+
HttpResponseMessage httpResponse = await _client.GetAsync($"accessmanagement/api/v1/systemuser/agentdelegation/{partyId}/{partyUuid}/{systemUserId}/customers");
94100
List<AgentDelegationPartyFE> actualResponse = await httpResponse.Content.ReadFromJsonAsync<List<AgentDelegationPartyFE>>();
95101

96102
// Assert

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Controllers/SystemUserAgentDelegationController.cs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,18 @@ public SystemUserAgentDelegationController(ISystemUserAgentDelegationService sys
2828
}
2929

3030
/// <summary>
31-
/// Get all regnskapsforer customers for the party
31+
/// Get all customers for the party
3232
/// </summary>
33-
/// <param name="partyUuid">Party user represents</param>
34-
/// <param name="cancellationToken">Cancellation token</param>
35-
/// <returns>List of customer party</returns>
36-
[Authorize]
37-
[HttpGet("{partyUuid}/customers/regnskapsforer")]
38-
public async Task<ActionResult> GetPartyRegnskapsforerCustomers([FromRoute] Guid partyUuid, CancellationToken cancellationToken)
39-
{
40-
List<AgentDelegationPartyFE> customers = await _systemUserAgentDelegationService.GetPartyCustomers(partyUuid, CustomerRoleType.Regnskapsforer, cancellationToken);
41-
return Ok(customers);
42-
}
43-
44-
/// <summary>
45-
/// Get all revisor customers for the party
46-
/// </summary>
47-
/// <param name="partyUuid">Party user represents</param>
48-
/// <param name="cancellationToken">Cancellation token</param>
49-
/// <returns>List of customer party</returns>
50-
[Authorize]
51-
[HttpGet("{partyUuid}/customers/revisor")]
52-
public async Task<ActionResult> GetPartyRevisorCustomers([FromRoute] Guid partyUuid, CancellationToken cancellationToken)
53-
{
54-
List<AgentDelegationPartyFE> customers = await _systemUserAgentDelegationService.GetPartyCustomers(partyUuid, CustomerRoleType.Revisor, cancellationToken);
55-
return Ok(customers);
56-
}
57-
58-
/// <summary>
59-
/// Get all forretningsforer customers for the party
60-
/// </summary>
61-
/// <param name="partyUuid">Party user represents</param>
33+
/// <param name="partyId">Party user represents</param>
34+
/// <param name="partyUuid">Party uuid user represents</param>
35+
/// <param name="systemUserGuid">System user to get customers from</param>
6236
/// <param name="cancellationToken">Cancellation token</param>
6337
/// <returns>List of customer party</returns>
6438
[Authorize]
65-
[HttpGet("{partyUuid}/customers/forretningsforer")]
66-
public async Task<ActionResult> GetPartyForretningsforerCustomers([FromRoute] Guid partyUuid, CancellationToken cancellationToken)
39+
[HttpGet("{partyId}/{partyUuid}/{systemUserGuid}/customers")]
40+
public async Task<ActionResult> GetSystemUserCustomers([FromRoute] int partyId, [FromRoute] Guid partyUuid, [FromRoute] Guid systemUserGuid, CancellationToken cancellationToken)
6741
{
68-
List<AgentDelegationPartyFE> customers = await _systemUserAgentDelegationService.GetPartyCustomers(partyUuid, CustomerRoleType.Forretningsforer, cancellationToken);
42+
List<AgentDelegationPartyFE> customers = await _systemUserAgentDelegationService.GetSystemUserCustomers(partyId, partyUuid, systemUserGuid, cancellationToken);
6943
return Ok(customers);
7044
}
7145

src/features/amUI/systemUser/SystemUserAgentDelegationPage/SystemUserAgentDelegationPage.tsx

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,15 @@ import { useParams } from 'react-router';
66
import {
77
useGetAssignedCustomersQuery,
88
useGetAgentSystemUserQuery,
9-
useGetRegnskapsforerCustomersQuery,
10-
useGetRevisorCustomersQuery,
11-
useGetForretningsforerCustomersQuery,
9+
useGetCustomersQuery,
1210
} from '@/rtk/features/systemUserApi';
1311
import { getCookie } from '@/resources/Cookie/CookieMethods';
1412
import { PageWrapper } from '@/components';
1513
import { useDocumentTitle } from '@/resources/hooks/useDocumentTitle';
1614
import { PageLayoutWrapper } from '@/features/amUI/common/PageLayoutWrapper';
1715

18-
import type { SystemUser } from '../types';
19-
2016
import { SystemUserAgentDelegationPageContent } from './SystemUserAgentDelegationPageContent';
2117

22-
const regnskapsforerUrns = [
23-
'urn:altinn:accesspackage:regnskapsforer-med-signeringsrettighet',
24-
'urn:altinn:accesspackage:regnskapsforer-uten-signeringsrettighet',
25-
'urn:altinn:accesspackage:regnskapsforer-lonn',
26-
];
27-
const revisorUrns = [
28-
'urn:altinn:accesspackage:ansvarlig-revisor',
29-
'urn:altinn:accesspackage:revisormedarbeider',
30-
];
31-
const forretningsforerUrns = ['urn:altinn:accesspackage:skattegrunnlag'];
32-
33-
enum SystemUserCustomerType {
34-
UNKNOWN = 'UNKNOWN',
35-
REGNSKAPSFORER = 'REGNSKAPSFORER',
36-
REVISOR = 'REVISOR',
37-
FORRETNINGSFORER = 'FORRETNINGSFORER',
38-
}
39-
40-
const getSystemUserCustomerType = (systemUser: SystemUser | undefined): SystemUserCustomerType => {
41-
const accessPackageUrns = systemUser?.accessPackages.map((ap) => ap.urn) ?? [];
42-
if (accessPackageUrns.some((urn) => regnskapsforerUrns.includes(urn))) {
43-
return SystemUserCustomerType.REGNSKAPSFORER;
44-
} else if (accessPackageUrns.some((urn) => revisorUrns.includes(urn))) {
45-
return SystemUserCustomerType.REVISOR;
46-
} else if (accessPackageUrns.some((urn) => forretningsforerUrns.includes(urn))) {
47-
return SystemUserCustomerType.FORRETNINGSFORER;
48-
}
49-
return SystemUserCustomerType.UNKNOWN;
50-
};
51-
5218
export const SystemUserAgentDelegationPage = (): React.ReactNode => {
5319
const { id } = useParams();
5420
const { t } = useTranslation();
@@ -64,53 +30,27 @@ export const SystemUserAgentDelegationPage = (): React.ReactNode => {
6430
} = useGetAgentSystemUserQuery({ partyId, systemUserId: id || '' });
6531

6632
const {
67-
data: regnskapsforerCustomers,
68-
isError: isLoadRegnskapsforerCustomersError,
69-
isLoading: isLoadingRegnskapsforerCustomers,
70-
} = useGetRegnskapsforerCustomersQuery(partyUuid, {
71-
skip: getSystemUserCustomerType(systemUser) !== SystemUserCustomerType.REGNSKAPSFORER,
72-
});
73-
74-
const {
75-
data: revisorCustomers,
76-
isError: isLoadRevisorCustomersError,
77-
isLoading: isLoadingRevisorCustomers,
78-
} = useGetRevisorCustomersQuery(partyUuid, {
79-
skip: getSystemUserCustomerType(systemUser) !== SystemUserCustomerType.REVISOR,
80-
});
81-
82-
const {
83-
data: forretningsforerCustomers,
84-
isError: isLoadForretningsforerCustomersError,
85-
isLoading: isLoadingForretningsforerCustomers,
86-
} = useGetForretningsforerCustomersQuery(partyUuid, {
87-
skip: getSystemUserCustomerType(systemUser) !== SystemUserCustomerType.FORRETNINGSFORER,
88-
});
33+
data: customers,
34+
isError: isLoadCustomersError,
35+
isLoading: isLoadingCustomers,
36+
} = useGetCustomersQuery({ partyId, partyUuid, systemUserId: id ?? '' });
8937

9038
const {
9139
data: agentDelegations,
9240
isError: isLoadAssignedCustomersError,
9341
isLoading: isLoadingAssignedCustomers,
9442
} = useGetAssignedCustomersQuery({ partyId, systemUserId: id || '' });
9543

96-
const customers = regnskapsforerCustomers || revisorCustomers || forretningsforerCustomers;
97-
9844
return (
9945
<PageWrapper>
10046
<PageLayoutWrapper>
101-
{(isLoadingSystemUser ||
102-
isLoadingRegnskapsforerCustomers ||
103-
isLoadingRevisorCustomers ||
104-
isLoadingForretningsforerCustomers ||
105-
isLoadingAssignedCustomers) && (
47+
{(isLoadingSystemUser || isLoadingCustomers || isLoadingAssignedCustomers) && (
10648
<Spinner aria-label={t('systemuser_detailpage.loading_systemuser')} />
10749
)}
10850
{isLoadSystemUserError && (
10951
<Alert data-color='danger'>{t('systemuser_detailpage.load_systemuser_error')}</Alert>
11052
)}
111-
{(isLoadRevisorCustomersError ||
112-
isLoadRegnskapsforerCustomersError ||
113-
isLoadForretningsforerCustomersError) && (
53+
{isLoadCustomersError && (
11454
<Alert data-color='danger'>{t('systemuser_agent_delegation.load_customers_error')}</Alert>
11555
)}
11656
{isLoadAssignedCustomersError && (

src/rtk/features/systemUserApi.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,12 @@ export const systemUserApi = createApi({
8383
getAgentSystemUser: builder.query<SystemUser, { partyId: string; systemUserId: string }>({
8484
query: ({ partyId, systemUserId }) => `systemuser/agent/${partyId}/${systemUserId}`,
8585
}),
86-
getRegnskapsforerCustomers: builder.query<AgentDelegationCustomer[], string>({
87-
query: (partyUuid) => `systemuser/agentdelegation/${partyUuid}/customers/regnskapsforer`,
88-
keepUnusedDataFor: Infinity,
89-
}),
90-
getRevisorCustomers: builder.query<AgentDelegationCustomer[], string>({
91-
query: (partyUuid) => `systemuser/agentdelegation/${partyUuid}/customers/revisor`,
92-
keepUnusedDataFor: Infinity,
93-
}),
94-
getForretningsforerCustomers: builder.query<AgentDelegationCustomer[], string>({
95-
query: (partyUuid) => `systemuser/agentdelegation/${partyUuid}/customers/forretningsforer`,
86+
getCustomers: builder.query<
87+
AgentDelegationCustomer[],
88+
{ partyId: string; partyUuid: string; systemUserId: string }
89+
>({
90+
query: ({ partyId, partyUuid, systemUserId }) =>
91+
`systemuser/agentdelegation/${partyId}/${partyUuid}/${systemUserId}/customers`,
9692
keepUnusedDataFor: Infinity,
9793
}),
9894
getAssignedCustomers: builder.query<
@@ -200,9 +196,7 @@ export const {
200196
useDeleteSystemuserMutation,
201197
useGetSystemUserQuery,
202198
useGetSystemUsersQuery,
203-
useGetRegnskapsforerCustomersQuery,
204-
useGetRevisorCustomersQuery,
205-
useGetForretningsforerCustomersQuery,
199+
useGetCustomersQuery,
206200
useGetAssignedCustomersQuery,
207201
useAssignCustomerMutation,
208202
useRemoveCustomerMutation,

0 commit comments

Comments
 (0)