Skip to content

feat: instance contextual layout fetching#1544

Open
Jondyr wants to merge 17 commits into
mainfrom
feat/instance-contextual-layout-fetching
Open

feat: instance contextual layout fetching#1544
Jondyr wants to merge 17 commits into
mainfrom
feat/instance-contextual-layout-fetching

Conversation

@Jondyr
Copy link
Copy Markdown
Member

@Jondyr Jondyr commented Oct 29, 2025

Description

Related PR: Altinn/app-frontend-react#3818

Adds new service ICustomLayoutForInstance, and endpoint in ResourcesController.
When used together with the featureFlag AddInstanceIdentifierToLayoutRequests, the frontend uses this new endpoint to fetch layouts. If the app implements ICustomLayoutForInstance this service is called instead of IAppResources, giving access to instance information when returning layouts.

Related Issue(s)

  • #{issue number}

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)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Added endpoints to retrieve layouts and layout settings specific to individual instances
    • Introduced feature flag to enable instance identifiers in layout requests
  • Improvements

    • Enhanced null-handling behavior for data element conversions to prevent errors

@Jondyr Jondyr changed the title Feat/instance contextual layout fetching feat: instance contextual layout fetching Oct 29, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 29, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d4c9129-c1a6-4398-a12d-2b5c2032fd93

📥 Commits

Reviewing files that changed from the base of the PR and between bffb111 and e90f9c8.

📒 Files selected for processing (2)
  • test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.json
  • test/Altinn.App.Api.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
✅ Files skipped from review due to trivial changes (1)
  • test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/Altinn.App.Api.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

📝 Walkthrough

Walkthrough

This pull request introduces support for instance-specific custom layouts. It adds a new ICustomLayoutForInstance interface, integrates it into the ResourceController with two new endpoints that prefer custom implementations while falling back to default resources, introduces a corresponding feature flag, and extends test coverage with new test cases and verified snapshots.

Changes

Cohort / File(s) Summary
API Endpoints for Instance Layouts
src/Altinn.App.Api/Controllers/ResourceController.cs, src/Altinn.App.Core/Internal/App/ICustomLayoutForInstance.cs
Added ICustomLayoutForInstance interface with methods for retrieving custom layouts and layout settings per instance. Enhanced ResourceController with two new endpoints (GetInstanceLayouts, GetInstanceLayoutSettings) that accept instance context and prefer custom implementations via dependency injection, falling back to IAppResources when unavailable.
Feature Flag Integration
src/Altinn.App.Core/Features/FeatureFlags.cs, src/Altinn.App.Core/Internal/App/FrontendFeatures.cs
Added new AddInstanceIdentifierToLayoutRequests feature flag constant and integrated runtime evaluation in FrontendFeatures to expose the flag's state in frontend configuration dictionary.
API Test Coverage
test/Altinn.App.Api.Tests/Controllers/ResourceController_CustomLayoutTests.cs, test/Altinn.App.Api.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt, test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveJsonSwagger.verified.json
New test suite validating custom layout endpoint behavior with and without ICustomLayoutForInstance service registered. Public API surface and OpenAPI specification updated to reflect constructor signature change and two new instance-scoped endpoints.
Core Test Coverage
test/Altinn.App.Core.Tests/Internal/App/FrontendFeaturesTest.cs, test/Altinn.App.Core.Tests/Internal/App/AppMetadataTest.GetApplicationMetadata_deserialize_serialize_unmapped_properties.verified.txt, test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
Updated feature flag tests to verify addInstanceIdentifierToLayoutRequests presence in frontend features and public API surface, reflecting new constant in FeatureFlags and new ICustomLayoutForInstance interface.
Integration Test Snapshots
test/Altinn.App.Integration.Tests/CustomScopes/_snapshots/CustomScopesTests.Metadata_*_Metadata.verified.txt, test/Altinn.App.Integration.Tests/PartyTypesAllowed/_snapshots/SubunitOnlyAppTests.ApplicationMetadata_0.verified.txt
Updated metadata snapshots for custom scopes and party types to include new instance-scoped layout and layout settings endpoints with appropriate authorization scope configuration, and reflected feature flag addition in application metadata.
Data Model Enhancement
src/Altinn.App.Core/Models/DataElementIdentifier.cs
Improved null-handling behavior in implicit conversion operators: non-nullable conversion now throws ArgumentNullException on null input, and nullable conversion explicitly returns null instead of default instance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: instance contextual layout fetching' directly summarizes the main change: introducing instance-aware layout fetching via new endpoints and the ICustomLayoutForInstance interface.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/instance-contextual-layout-fetching

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from 03c5d90 to 1f10c35 Compare October 30, 2025 06:39
@Jondyr Jondyr added feature Label Pull requests with new features. Used when generation releasenotes backport-ignore This PR is a new feature and should not be cherry-picked onto release branches squad/utforming Issues that belongs to the named squad. labels Oct 30, 2025
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch 2 times, most recently from e8df578 to e56150a Compare October 30, 2025 07:14
@Jondyr Jondyr linked an issue Oct 30, 2025 that may be closed by this pull request
4 tasks
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch 2 times, most recently from 21399d0 to 3dffd17 Compare November 6, 2025 10:24
Copy link
Copy Markdown
Member

@ivarne ivarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siden dette er en applikasjons konfigurasjon for frontend, så ville jeg droppet FeatureManager og heller bare bedt brukerene gå direkte til appsettings.json og legge til "FrontendSettings": {"AddInstanceIdentifierToLayoutRequests": true} uten at det krever noe videre konfigurasjon i backend.

@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from 3dffd17 to 271ca38 Compare November 10, 2025 08:23
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from f307242 to 301807c Compare November 10, 2025 10:17
@Jondyr Jondyr moved this to 👷 In progress in Team Altinn Studio Nov 10, 2025
@Jondyr Jondyr self-assigned this Nov 10, 2025
@Jondyr Jondyr added the squad/data Issues that belongs to the named squad. label Nov 10, 2025
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from 69d0c68 to 733ec02 Compare November 10, 2025 11:53
@Jondyr Jondyr moved this from 👷 In progress to 🔎 In review in Team Altinn Studio Nov 10, 2025
@Jondyr Jondyr removed their assignment Nov 10, 2025
@Jondyr Jondyr marked this pull request as ready for review November 10, 2025 12:36
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from 1b4246a to 9fb5195 Compare December 17, 2025 10:45
@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from 9fb5195 to 0bfe1ba Compare December 17, 2025 10:54
@JamalAlabdullah JamalAlabdullah moved this from 🔎 In review to 🧪 Test in Team Altinn Studio Dec 18, 2025
@JamalAlabdullah JamalAlabdullah self-assigned this Dec 18, 2025
Copy link
Copy Markdown

@JamalAlabdullah JamalAlabdullah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from b443d20 to 668ffdc Compare January 16, 2026 09:13
@Jondyr Jondyr enabled auto-merge (squash) January 16, 2026 09:44
@Jondyr
Copy link
Copy Markdown
Member Author

Jondyr commented Jan 28, 2026

/publish

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 28, 2026

PR release:

⚙️ Building...
✅ Done!

@Jondyr Jondyr force-pushed the feat/instance-contextual-layout-fetching branch from ca5dfe8 to 33b9d3f Compare January 29, 2026 08:32
@Jondyr
Copy link
Copy Markdown
Member Author

Jondyr commented Jan 29, 2026

/publish

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 29, 2026

PR release:

⚙️ Building...
✅ Done!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/Altinn.App.Core/Features/FeatureFlags.cs`:
- Around line 16-21: The XML summary for the public constant
AddInstanceIdentifierToLayoutRequests contains a TODO; replace it with a
concise, concrete summary describing the flag's behavior (e.g., that enabling
this feature changes the backend layout endpoint to include the instance
identifier in requests), update the <summary> tag text accordingly so generated
API docs are complete, and ensure wording is clear and present-tense without
TODO markers.
🧹 Nitpick comments (2)
src/Altinn.App.Api/Controllers/ResourceController.cs (2)

22-25: Consider injecting AppImplementationFactory directly.

Using IServiceProvider.GetRequiredService<T>() in the constructor is a service locator pattern. Prefer direct constructor injection for better testability and clearer dependencies.

♻️ Proposed refactor
-    /// <param name="serviceProvider">The service provider</param>
-    public ResourceController(IAppResources appResourcesService, IServiceProvider serviceProvider)
+    /// <param name="appImplementationFactory">The app implementation factory</param>
+    public ResourceController(IAppResources appResourcesService, AppImplementationFactory appImplementationFactory)
     {
         _appResourceService = appResourcesService;
-        _appImplementationFactory = serviceProvider.GetRequiredService<AppImplementationFactory>();
+        _appImplementationFactory = appImplementationFactory;
     }

90-90: Consider adding GUID route constraint for consistency and early validation.

The route uses {instanceId} as a string, but existing instance endpoints in this codebase use {instanceGuid:guid} with a GUID constraint. Adding the constraint would reject invalid GUIDs at the routing level (returning 404) and maintain consistency with other instance-scoped endpoints.

♻️ Proposed change
-    [Route("{org}/{app}/instances/{instanceOwnerPartyId:int}/{instanceId}/layouts/{layoutSetId}")]
+    [Route("{org}/{app}/instances/{instanceOwnerPartyId:int}/{instanceGuid:guid}/layouts/{layoutSetId}")]

Note: This would also require renaming the parameter in the method signature from instanceId to instanceGuid and updating the XML documentation accordingly.

Comment on lines +16 to +21
// TODO: write a better summary here
/// <summary>
/// Enabling this feature changes backend endpoint used for layouts to
/// add instance identifier.
/// </summary>
public const string AddInstanceIdentifierToLayoutRequests = "AddInstanceIdentifierToLayoutRequests";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Replace the TODO with a concrete summary before release.

Leaving a TODO in a public API constant’s XML doc makes the documentation incomplete and leaks into generated docs.

📝 Suggested update
-    // TODO: write a better summary here
-    /// <summary>
-    /// Enabling this feature changes backend endpoint used for layouts to
-    /// add instance identifier.
-    /// </summary>
+    /// <summary>
+    /// When enabled, layout fetches use instance-scoped endpoints so layout requests
+    /// include the instance identifier.
+    /// </summary>
     public const string AddInstanceIdentifierToLayoutRequests = "AddInstanceIdentifierToLayoutRequests";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: write a better summary here
/// <summary>
/// Enabling this feature changes backend endpoint used for layouts to
/// add instance identifier.
/// </summary>
public const string AddInstanceIdentifierToLayoutRequests = "AddInstanceIdentifierToLayoutRequests";
/// <summary>
/// When enabled, layout fetches use instance-scoped endpoints so layout requests
/// include the instance identifier.
/// </summary>
public const string AddInstanceIdentifierToLayoutRequests = "AddInstanceIdentifierToLayoutRequests";
🤖 Prompt for AI Agents
In `@src/Altinn.App.Core/Features/FeatureFlags.cs` around lines 16 - 21, The XML
summary for the public constant AddInstanceIdentifierToLayoutRequests contains a
TODO; replace it with a concise, concrete summary describing the flag's behavior
(e.g., that enabling this feature changes the backend layout endpoint to include
the instance identifier in requests), update the <summary> tag text accordingly
so generated API docs are complete, and ensure wording is clear and
present-tense without TODO markers.

Comment thread test/Altinn.App.Core.Tests/Models/DataElementIdentifierTests.cs Fixed
@bjorntore
Copy link
Copy Markdown
Contributor

/publish

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 29, 2026

PR release:

⚙️ Building...
✅ Done!

@sonarqubecloud
Copy link
Copy Markdown

@Jondyr Jondyr moved this from 🧪 Test to ⚠️ Blocked in Team Altinn Studio Feb 11, 2026
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes squad/data Issues that belongs to the named squad. squad/utforming Issues that belongs to the named squad.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Instance contextual layout fetching/resource interface

5 participants