Skip to content

Commit

Permalink
fix(app): Sub-parties sometimes missing from authorized parties (#1534)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## 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)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Removed unnecessary logging and reflection in cache handling,
simplifying error management.
- Temporarily disabled setting of sub-parties in the party flattening
logic for ongoing development.

- **Chores**
- Removed the "Serilog" logging configuration from the app settings,
streamlining the configuration file.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
oskogstad authored Nov 26, 2024
1 parent 3275d0d commit f47112e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
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

0 comments on commit f47112e

Please sign in to comment.