Skip to content

Commit 470cb40

Browse files
authored
send partyUuid as query param instead of looking up partyuuid from partyid in registry (#1389)
1 parent 34590bd commit 470cb40

File tree

15 files changed

+89
-249
lines changed

15 files changed

+89
-249
lines changed

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/ClientInterfaces/IRegisterClient.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ public interface IRegisterClient
1818
/// </returns>
1919
Task<Party> GetPartyForOrganization(string organizationNumber);
2020

21-
/// <summary>
22-
/// Looks up party information for an organization based on the partyId
23-
/// </summary>
24-
/// <param name="partyId">The partyId</param>
25-
/// <returns>
26-
/// Party information
27-
/// </returns>
28-
Task<Party> GetPartyByPartyId(int partyId);
29-
3021
/// <summary>
3122
/// Looks up party information for a person based on the ssn
3223
/// </summary>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Altinn.AccessManagement.UI.Core.Enums;
21
using Altinn.AccessManagement.UI.Core.Models.SystemUser;
32
using Altinn.AccessManagement.UI.Core.Models.SystemUser.Frontend;
43
using Altinn.Authorization.ProblemDetails;
@@ -15,36 +14,40 @@ public interface ISystemUserAgentDelegationService
1514
/// </summary>
1615
/// <param name="partyId">The party id of the party owning system user</param>
1716
/// <param name="systemUserGuid">The system user UUID to get customers from</param>
17+
/// <param name="partyUuid">The party uuid of the party owning system user</param>
1818
/// <param name="cancellationToken">Cancellation token</param>
1919
/// <returns>List of all systemuser customers</returns>
20-
Task<Result<List<CustomerPartyFE>>> GetSystemUserCustomers(int partyId, Guid systemUserGuid, CancellationToken cancellationToken);
20+
Task<Result<List<CustomerPartyFE>>> GetSystemUserCustomers(int partyId, Guid systemUserGuid, Guid partyUuid, CancellationToken cancellationToken);
2121

2222
/// <summary>
2323
/// Return delegated customers for this system user
2424
/// </summary>
25-
/// <param name="partyId">The party UUID of the party owning system user to retrieve delegated customers from</param>
25+
/// <param name="partyId">The party id of the party owning system user to retrieve delegated customers from</param>
2626
/// <param name="systemUserGuid">The system user UUID to retrieve delegated customers from</param>
27+
/// <param name="partyUuid">The party UUID of the party owning system user to retrieve delegated customers from</param>
2728
/// <param name="cancellationToken">Cancellation token</param>
2829
/// <returns>List of delegated customers for system user</returns>
29-
Task<Result<List<AgentDelegationFE>>> GetSystemUserAgentDelegations(int partyId, Guid systemUserGuid, CancellationToken cancellationToken);
30+
Task<Result<List<AgentDelegationFE>>> GetSystemUserAgentDelegations(int partyId, Guid systemUserGuid, Guid partyUuid, CancellationToken cancellationToken);
3031

3132
/// <summary>
3233
/// Add client to system user
3334
/// </summary>
3435
/// <param name="partyId">The party id of the party owning system user to add customer to</param>
3536
/// <param name="systemUserGuid">The system user UUID to add customer to</param>
37+
/// <param name="partyUuid">The party uuid of the party owning system user to add customer to</param>
3638
/// <param name="delegationRequestFe">Payload to send to add client</param>
3739
/// <param name="cancellationToken">Cancellation token</param>
3840
/// <returns>AgentDelegationFE with assignment id and customer id</returns>
39-
Task<Result<AgentDelegationFE>> AddClient(int partyId, Guid systemUserGuid, AgentDelegationRequestFE delegationRequestFe, CancellationToken cancellationToken);
41+
Task<Result<AgentDelegationFE>> AddClient(int partyId, Guid systemUserGuid, Guid partyUuid, AgentDelegationRequestFE delegationRequestFe, CancellationToken cancellationToken);
4042

4143
/// <summary>
4244
/// Remove client from system user
4345
/// </summary>
4446
/// <param name="partyId">The party id of the party owning system user to remove customer from</param>
4547
/// <param name="delegationId">The delegation id to remove</param>
48+
/// <param name="partyUuid">The party uuid of the party owning system user to remove customer from</param>
4649
/// <param name="cancellationToken">Cancellation token</param>
4750
/// <returns>Boolean result of remove</returns>
48-
Task<Result<bool>> RemoveClient(int partyId, Guid delegationId, CancellationToken cancellationToken);
51+
Task<Result<bool>> RemoveClient(int partyId, Guid delegationId, Guid partyUuid, CancellationToken cancellationToken);
4952
}
5053
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ public interface ISystemUserService
5050
/// <summary>
5151
/// Deletes agent system user
5252
/// </summary>
53-
/// <param name="partyId">The party Id of the party to retrieve</param>
53+
/// <param name="partyId">The party Id of the party</param>
5454
/// <param name="systemUserId">Id of system user to delete</param>
55+
/// <param name="partyUuid">The party uuid of the party</param>
5556
/// <param name="cancellationToken">Cancellation token</param>
5657
/// <returns>Boolean whether delete was successful or not</returns>
57-
Task<Result<bool>> DeleteAgentSystemUser(int partyId, Guid systemUserId, CancellationToken cancellationToken);
58+
Task<Result<bool>> DeleteAgentSystemUser(int partyId, Guid systemUserId, Guid partyUuid, CancellationToken cancellationToken);
5859

5960
/// <summary>
6061
/// Create a new system user

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

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Altinn.AccessManagement.UI.Core.Models.SystemUser.Frontend;
77
using Altinn.AccessManagement.UI.Core.Services.Interfaces;
88
using Altinn.Authorization.ProblemDetails;
9-
using Altinn.Platform.Register.Models;
109

1110
namespace Altinn.AccessManagement.UI.Core.Services
1211
{
@@ -34,15 +33,8 @@ public SystemUserAgentDelegationService(
3433
}
3534

3635
/// <inheritdoc />
37-
public async Task<Result<List<CustomerPartyFE>>> GetSystemUserCustomers(int partyId, Guid systemUserGuid, CancellationToken cancellationToken)
36+
public async Task<Result<List<CustomerPartyFE>>> GetSystemUserCustomers(int partyId, Guid systemUserGuid, Guid partyUuid, CancellationToken cancellationToken)
3837
{
39-
// get access packages from systemuser
40-
Party party = await _registerClient.GetPartyByPartyId(partyId);
41-
if (party == null || party.PartyUuid == null)
42-
{
43-
return Problem.Reportee_Orgno_NotFound;
44-
}
45-
4638
SystemUser systemUser = await _systemUserClient.GetAgentSystemUser(partyId, systemUserGuid, cancellationToken);
4739
IEnumerable<string> accessPackageUrns = systemUser.AccessPackages.Select(x => x.Urn);
4840
CustomerRoleType customerType;
@@ -68,20 +60,14 @@ public async Task<Result<List<CustomerPartyFE>>> GetSystemUserCustomers(int part
6860
customerType = CustomerRoleType.None;
6961
}
7062

71-
CustomerList customers = await _registerClient.GetPartyCustomers((Guid)party.PartyUuid, customerType, cancellationToken);
63+
CustomerList customers = await _registerClient.GetPartyCustomers(partyUuid, customerType, cancellationToken);
7264
return MapCustomerListToCustomerFE(customers);
7365
}
7466

7567
/// <inheritdoc />
76-
public async Task<Result<List<AgentDelegationFE>>> GetSystemUserAgentDelegations(int partyId, Guid systemUserGuid, CancellationToken cancellationToken)
68+
public async Task<Result<List<AgentDelegationFE>>> GetSystemUserAgentDelegations(int partyId, Guid systemUserGuid, Guid partyUuid, CancellationToken cancellationToken)
7769
{
78-
Party party = await _registerClient.GetPartyByPartyId(partyId);
79-
if (party == null || party.PartyUuid == null)
80-
{
81-
return Problem.Reportee_Orgno_NotFound;
82-
}
83-
84-
List<AgentDelegation> delegations = await _systemUserAgentDelegationClient.GetSystemUserAgentDelegations(partyId, (Guid)party.PartyUuid, systemUserGuid, cancellationToken);
70+
List<AgentDelegation> delegations = await _systemUserAgentDelegationClient.GetSystemUserAgentDelegations(partyId, partyUuid, systemUserGuid, cancellationToken);
8571

8672
return delegations.Select(delegation =>
8773
{
@@ -95,18 +81,12 @@ public async Task<Result<List<AgentDelegationFE>>> GetSystemUserAgentDelegations
9581
}
9682

9783
/// <inheritdoc />
98-
public async Task<Result<AgentDelegationFE>> AddClient(int partyId, Guid systemUserGuid, AgentDelegationRequestFE delegationRequestFe, CancellationToken cancellationToken)
84+
public async Task<Result<AgentDelegationFE>> AddClient(int partyId, Guid systemUserGuid, Guid partyUuid, AgentDelegationRequestFE delegationRequestFe, CancellationToken cancellationToken)
9985
{
100-
Party party = await _registerClient.GetPartyByPartyId(partyId);
101-
if (party == null || party.PartyUuid == null)
102-
{
103-
return Problem.Reportee_Orgno_NotFound;
104-
}
105-
10686
AgentDelegationRequest delegationRequest = new()
10787
{
10888
CustomerId = delegationRequestFe.CustomerId,
109-
FacilitatorId = (Guid)party.PartyUuid
89+
FacilitatorId = partyUuid
11090
};
11191

11292
Result<List<AgentDelegation>> newAgentDelegations = await _systemUserAgentDelegationClient.AddClient(partyId, systemUserGuid, delegationRequest, cancellationToken);
@@ -131,15 +111,9 @@ public async Task<Result<AgentDelegationFE>> AddClient(int partyId, Guid systemU
131111
}
132112

133113
/// <inheritdoc />
134-
public async Task<Result<bool>> RemoveClient(int partyId, Guid delegationId, CancellationToken cancellationToken)
114+
public async Task<Result<bool>> RemoveClient(int partyId, Guid delegationId, Guid partyUuid, CancellationToken cancellationToken)
135115
{
136-
Party party = await _registerClient.GetPartyByPartyId(partyId);
137-
if (party == null || party.PartyUuid == null)
138-
{
139-
return Problem.Reportee_Orgno_NotFound;
140-
}
141-
142-
Result<bool> response = await _systemUserAgentDelegationClient.RemoveClient(partyId, (Guid)party.PartyUuid, delegationId, cancellationToken);
116+
Result<bool> response = await _systemUserAgentDelegationClient.RemoveClient(partyId, partyUuid, delegationId, cancellationToken);
143117
if (response.IsProblem)
144118
{
145119
return new Result<bool>(response.Problem);

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@ public async Task<SystemUserFE> GetAgentSystemUser(int partyId, Guid id, string
8585
}
8686

8787
/// <inheritdoc />
88-
public async Task<Result<bool>> DeleteAgentSystemUser(int partyId, Guid systemUserId, CancellationToken cancellationToken)
88+
public async Task<Result<bool>> DeleteAgentSystemUser(int partyId, Guid systemUserId, Guid partyUuid, CancellationToken cancellationToken)
8989
{
90-
Party party = await _registerClient.GetPartyByPartyId(partyId);
91-
if (party == null || party.PartyUuid == null)
92-
{
93-
return Problem.Reportee_Orgno_NotFound;
94-
}
95-
96-
return await _systemUserClient.DeleteAgentSystemUser(partyId, systemUserId, (Guid)party.PartyUuid, cancellationToken);
90+
return await _systemUserClient.DeleteAgentSystemUser(partyId, systemUserId, partyUuid, cancellationToken);
9791
}
9892

9993
/// <inheritdoc />

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Integration/Clients/RegisterClient.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,6 @@ public async Task<Party> GetPartyForOrganization(string organizationNumber)
8787
}
8888
}
8989

90-
/// <inheritdoc/>
91-
public async Task<Party> GetPartyByPartyId(int partyId)
92-
{
93-
try
94-
{
95-
string endpointUrl = $"parties/{partyId}";
96-
string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _platformSettings.JwtCookieName);
97-
var accessToken = await _accessTokenProvider.GetAccessToken();
98-
99-
HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, accessToken);
100-
string responseContent = await response.Content.ReadAsStringAsync();
101-
102-
if (response.StatusCode == HttpStatusCode.OK)
103-
{
104-
return JsonSerializer.Deserialize<Party>(responseContent, _serializerOptions);
105-
}
106-
107-
_logger.LogError("AccessManagement.UI // RegisterClient // GetPartyByPartyId // Unexpected HttpStatusCode: {StatusCode}\n {responseBody}", response.StatusCode, responseContent);
108-
return null;
109-
}
110-
catch (Exception ex)
111-
{
112-
_logger.LogError(ex, "AccessManagement.UI // RegisterClient // GetPartyByPartyId // Exception");
113-
throw;
114-
}
115-
}
116-
11790
/// <inheritdoc/>
11891
public async Task<Party> GetPartyForPerson(string ssn)
11992
{

backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Mocks/Mocks/RegisterClientMock.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ public Task<Party> GetPartyForOrganization(string organizationNumber)
4141
return Task.FromResult(party);
4242
}
4343

44-
/// <inheritdoc/>
45-
public Task<Party> GetPartyByPartyId(int partyId)
46-
{
47-
Party party = null;
48-
string testDataPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(RegisterClientMock).Assembly.Location).LocalPath), "Data", "Register", "Parties", "parties.json");
49-
if (File.Exists(testDataPath))
50-
{
51-
string content = File.ReadAllText(testDataPath);
52-
List<Party> partyList = JsonSerializer.Deserialize<List<Party>>(content);
53-
party = partyList?.FirstOrDefault(p => p.PartyId == partyId);
54-
}
55-
56-
return Task.FromResult(party);
57-
}
58-
5944
/// <inheritdoc/>
6045
public Task<List<Party>> GetPartyList(List<Guid> uuidList)
6146
{

0 commit comments

Comments
 (0)