Skip to content

Commit 69542ad

Browse files
jonkjetiloyeJon Kjetil ØyeCopilot
authored
bug: get resources/instances empty response due to missing resource info (#2606)
* bug: get resources/instances empty response due to missing resource info #2605 - Rename properties on InstanceDto to just return instance refId - Utvidet connection query for å joine inn minimums info om ressurs knytt til instans-delegeringer * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jon Kjetil Øye <acn-joye@ai-dev.no> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 011b2d4 commit 69542ad

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/apps/Altinn.AccessManagement/src/Altinn.AccessMgmt.Core/Services/ConnectionService.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,13 @@ private async Task<List<InstancePermissionDto>> MapConnectionsToInstancePermissi
301301
foreach (var group in grouped)
302302
{
303303
var firstInstance = group.First().Instance;
304-
var firstConnection = group.First().Connection;
305-
306-
// Get the resource from the Resources collection
307-
var resource = firstConnection.Resources?.FirstOrDefault(r => r.Id == firstInstance.ResourceId);
308-
309-
if (resource == null)
310-
{
311-
continue; // Skip if resource not found
312-
}
313304

314305
var dto = new InstancePermissionDto
315306
{
316-
Resource = DtoMapper.Convert(resource),
307+
Resource = new ResourceDto { Id = firstInstance.ResourceId, RefId = firstInstance.ResourceRefId, Name = firstInstance.ResourceName },
317308
Instance = new InstanceDto
318309
{
319-
Id = firstInstance.InstanceId,
320-
Urn = $"urn:altinn:instance-id:{firstInstance.InstanceId}",
310+
RefId = firstInstance.InstanceId,
321311
Type = null // TODO: InstanceType support to be added later
322312
},
323313
Permissions = group.Select(x => DtoMapper.ConvertToPermission(x.Connection)).ToList()
@@ -1035,8 +1025,7 @@ public async Task<Result<InstanceCheckDto>> InstanceDelegationCheck(Guid authent
10351025
Resource = resourceDto,
10361026
Instance = new InstanceDto
10371027
{
1038-
Id = instanceId,
1039-
Urn = $"urn:altinn:instance-id:{instanceId}",
1028+
RefId = instanceId,
10401029
Type = null
10411030
},
10421031
Rights = checkRights
@@ -2134,7 +2123,7 @@ private async Task<List<InstanceRightDto>> GetInstanceRights(Guid? fromId, Guid?
21342123
{
21352124
Resource = DtoMapper.Convert(internalResource),
21362125
Instance = !string.IsNullOrEmpty(instanceId)
2137-
? new InstanceDto { Id = instanceId, Urn = $"urn:altinn:instance-id:{instanceId}" }
2126+
? new InstanceDto { RefId = instanceId }
21382127
: null,
21392128
Rights = new List<RightPermission>()
21402129
};

src/apps/Altinn.AccessManagement/src/Altinn.AccessMgmt.PersistenceEF/Queries/Connection/ConnectionQuery.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,11 @@ private async Task<ConnectionIndex<ConnectionQueryInstance>> LoadInstancesByKeyA
11751175
var flat = assignmentInstances.Select(x => new { x.c, x.ai.Id, x.ai.ResourceId, x.ai.InstanceId });
11761176

11771177
var rows = await flat
1178-
.Select(x => new
1178+
.Join(db.Resources, x => x.ResourceId, r => r.Id, (x, r) => new
11791179
{
11801180
Key = new ConnectionCompositeKey(x.c.FromId, x.c.ToId, x.c.RoleId, x.c.AssignmentId, x.c.DelegationId, x.c.ViaId, x.c.ViaRoleId),
1181-
Instance = new { x.Id, x.ResourceId, x.InstanceId }
1181+
Instance = new { x.Id, x.ResourceId, x.InstanceId },
1182+
Resource = new { r.Name, r.RefId }
11821183
})
11831184
.AsNoTracking()
11841185
.ToListAsync(ct);
@@ -1191,6 +1192,8 @@ private async Task<ConnectionIndex<ConnectionQueryInstance>> LoadInstancesByKeyA
11911192
Id = z.Instance.Id,
11921193
ResourceId = z.Instance.ResourceId,
11931194
InstanceId = z.Instance.InstanceId,
1195+
ResourceName = z.Resource.Name,
1196+
ResourceRefId = z.Resource.RefId,
11941197
}).DistinctBy(p => p.Id);
11951198

11961199
index.AddRange(g.Key, mapped);

src/apps/Altinn.AccessManagement/src/Altinn.AccessMgmt.PersistenceEF/Queries/Connection/Models/ConnectionQueryInstance.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ public sealed class ConnectionQueryInstance
1919
/// Instance identifier (e.g., "51599233/df333e75-5896-4254-a69f-146736eaf668")
2020
/// </summary>
2121
public string InstanceId { get; init; } = string.Empty;
22+
23+
/// <summary>
24+
/// Gets the name of the resource associated with this instance.
25+
/// </summary>
26+
public string ResourceName { get; init; } = string.Empty;
27+
28+
/// <summary>
29+
/// Gets the reference ID of the resource associated with this instance.
30+
/// </summary>
31+
public string ResourceRefId { get; init; } = string.Empty;
2232
}

src/libs/Altinn.Authorization.Api.Contracts/src/Altinn.Authorization.Api.Contracts/AccessManagement/InstanceDto.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
public class InstanceDto
77
{
88
/// <summary>
9-
/// InstanceId
9+
/// Instance RefId
1010
/// </summary>
11-
public string Id { get; set; }
12-
13-
/// <summary>
14-
/// InstanceUrn
15-
/// </summary>
16-
public string Urn { get; set; }
11+
public string RefId { get; set; }
1712

1813
/// <summary>
1914
/// Type

0 commit comments

Comments
 (0)