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

Implement party lookup in IParties (fixes #600) #601

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/Authorization/Services/Implementation/ContextHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
private readonly IProfile _profileWrapper;
private readonly IMemoryCache _memoryCache;
private readonly GeneralSettings _generalSettings;
private readonly IRegisterService _registerService;

Check warning on line 44 in src/Authorization/Services/Implementation/ContextHandler.cs

View workflow job for this annotation

GitHub Actions / Analyze

Remove this unread private field '_registerService' or refactor the code to use its value. (https://rules.sonarsource.com/csharp/RSPEC-4487)
private readonly IPolicyRetrievalPoint _prp;

/// <summary>
Expand Down Expand Up @@ -181,10 +181,10 @@
{
if (string.IsNullOrEmpty(resourceAttributes.ResourcePartyValue) && !string.IsNullOrEmpty(resourceAttributes.OrganizationNumber))
{
int partyId = await _registerService.PartyLookup(resourceAttributes.OrganizationNumber, null);
if (partyId != 0)
Party party = await _partiesWrapper.LookupPartyBySSNOrOrgNo(resourceAttributes.OrganizationNumber);
if (party != null)
{
resourceAttributes.ResourcePartyValue = partyId.ToString();
resourceAttributes.ResourcePartyValue = party.PartyId.ToString();
}
}
}
Expand Down Expand Up @@ -467,7 +467,7 @@
/// </summary>
/// <param name="from">the party which the role assignment provides access on behalf of</param>
/// <param name="to">the role assignment recipient party</param>
/// <returns>list of OED/Digitalt dødsbo Role Assignments</returns>
/// <returns>list of OED/Digitalt dødsbo Role Assignments</returns>
protected async Task<List<OedRoleAssignment>> GetOedRoleAssignments(string from, string to)
{
string cacheKey = GetOedRoleassignmentCacheKey(from, to);
Expand Down
29 changes: 29 additions & 0 deletions src/Authorization/Services/Implementation/PartiesWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,34 @@ public async Task<bool> ValidateSelectedParty(int userId, int partyId)

return result;
}

/// <inheritdoc />
public async Task<Party> LookupPartyBySSNOrOrgNo(string lookupValue)
{
try
{
Uri endpointUrl = new($"register/api/parties/lookupObject");
StringContent requestBody = new(JsonConvert.SerializeObject(lookupValue), Encoding.UTF8, "application/json");

HttpResponseMessage response = await _partyClient.Client.PostAsync(endpointUrl, requestBody);
var responseBody = await response.Content.ReadAsStringAsync();

if (response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<Party>(responseBody);
}
else
{
_logger.LogError("SBL-Bridge // PartiesWrapper // LookupPartyBySSNOrOrgNo // Failed // Unexpected HttpStatusCode: {response.StatusCode}\n {responseBody}", response.StatusCode, responseBody);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "SBL-Bridge // PartiesWrapper // LookupPartyBySSNOrOrgNo // Failed // Unexpected Exception");
throw;
}

return null;
}
}
}
7 changes: 7 additions & 0 deletions src/Authorization/Services/Interface/IParties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ public interface IParties
/// <param name="partyId">The party id"</param>
/// <returns> Boolean indicating whether or not the user can represent the selected party.</returns>
Task<bool> ValidateSelectedParty(int userId, int partyId);

/// <summary>
/// Method that fetches a party based on social security number or organisation number.
/// </summary>
/// <param name="lookupValue">SSN or org number</param>
/// <returns></returns>
Task<Party> LookupPartyBySSNOrOrgNo(string lookupValue);
}
}
11 changes: 11 additions & 0 deletions test/IntegrationTests/MockServices/PartiesMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public Task<Party> GetParty(int partyId)
return Task.FromResult(party);
}

public Task<Party> LookupPartyBySSNOrOrgNo(string lookupValue)
{
Party party = null;
if (lookupValue == "950474084")
{
party = new Party { PartyId = 500700 };
}

return Task.FromResult(party);
}

public Task<bool> ValidateSelectedParty(int userId, int partyId)
{
throw new NotImplementedException();
Expand Down
Loading