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

fix(app): Sub-parties sometimes missing from authorized parties #1534

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
10 changes: 1 addition & 9 deletions src/Digdir.Domain.Dialogporten.GraphQL/appsettings.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,5 @@
}
]
}
},
"Serilog": {
"MinimumLevel": {
"Override": {
"Digdir.Domain.Dialogporten.Infrastructure.Altinn.Authorization.AltinnAuthorizationClient": "Information",
"Digdir.Domain.Dialogporten.GraphQL.EndUser.Queries": "Information"
}
}
},
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
Expand All @@ -9,7 +8,6 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Parties.Abstractions;
using Digdir.Domain.Dialogporten.Infrastructure.Common.Exceptions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using ZiggyCreatures.Caching.Fusion;

Expand Down Expand Up @@ -84,31 +82,9 @@ public async Task<AuthorizedPartiesResult> GetAuthorizedParties(IPartyIdentifier
{
var authorizedPartiesRequest = new AuthorizedPartiesRequest(authenticatedParty);

var cacheKey = authorizedPartiesRequest.GenerateCacheKey();
var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token
var authorizedParties = await _partiesCache.GetOrSetAsync(authorizedPartiesRequest.GenerateCacheKey(), async token
=> await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken);

// Testing https://github.com/digdir/dialogporten/issues/1226
try
{
var mcaField = typeof(FusionCache).GetField("_mca", BindingFlags.NonPublic | BindingFlags.Instance);
var mcaValue = mcaField?.GetValue(_partiesCache);
var mcField = mcaValue!.GetType().GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
var mcValue = mcField?.GetValue(mcaValue) as IMemoryCache;

var inMemoryCacheValue = mcValue!.TryGetValue(cacheKey, out var inMemoryCacheEntry);
var inMemoryCacheEntryValue = inMemoryCacheEntry?.GetType().GetProperty("Value")?.GetValue(inMemoryCacheEntry);

_logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}",
cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to reflect on FusionCache MemoryCache");
}

_logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties);

return flatten ? GetFlattenedAuthorizedParties(authorizedParties) : authorizedParties;
}

Expand Down Expand Up @@ -144,7 +120,10 @@ void Flatten(AuthorizedParty party, AuthorizedParty? parent = null)
}

if (parent != null) party.ParentParty = parent.Party;
party.SubParties = [];

// TODO: https://github.com/digdir/dialogporten/issues/1533
// Disabling this for now, fixes https://github.com/digdir/dialogporten/issues/1226
// party.SubParties = [];

flattenedAuthorizedParties.AuthorizedParties.Add(party);
}
Expand Down
Loading