Sitelet https://github.com/Altinn/app-lib-dotnet/pull/1872
Skip to content

feat: copy data values, presentation texts and due date when copying an instance - #1872

Open
ivarne wants to merge 5 commits into
Altinn:mainfrom
ivarne-agent:feat/copy-instance-values
Open

ivarne wants to merge 5 commits into
Altinn:mainfrom
ivarne-agent:feat/copy-instance-values

Conversation

@ivarne

@ivarne ivarne commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

When an instance is copied today, dataValues, presentationTexts and dueBefore are not carried over from the source instance. Apps that set data values from code (for example an appVersion value that an ICopyInstanceValidator checks) lose those values on the first copy, so a copy of a copy can no longer be validated.

This PR adds three settings to copyInstanceSettings in applicationmetadata.json:

Setting Type Behaviour
includeDueBefore bool Copies dueBefore from the source instance. Defaults to false. On the simplified instantiation endpoint, a dueBefore given in the request takes precedence.
includedDataValues string[] Keys in dataValues to copy from the source instance.
includedPresentationTexts string[] Keys in presentationTexts to copy from the source instance.

Keys that do not exist on the source are ignored. If a key is also derived from dataFields/presentationFields, the value recalculated from the copied form data is used.

"copyInstanceSettings": {
    "enabled": true,
    "includeDueBefore": true,
    "includedDataValues": ["appVersion", "customerId"],
    "includedPresentationTexts": ["name"]
}

Implementation notes

  • The settings were added to CopyInstanceSettings in feat: add settings for copying due date, data values and presentationtexts altinn-storage#1121 (backported to the v4 interface line). This PR updates Altinn.Platform.Storage.Interface from 4.7.1 to 4.7.2, which contains them, so no app specific model is needed.
  • Both the legacy /legacy/instances/{partyId}/{guid}/copy endpoint and the simplified instances/create endpoint with sourceInstanceId honour the settings. In the simplified endpoint the source instance is now fetched before the instance template is built so dueBefore can be set on creation (Storage has no endpoint for updating it afterwards). The archived check therefore runs before the instantiation validator instead of after it.
  • The selected data values and presentation texts are sent in the instance template to Storage when the instance is created, so no extra Storage calls are made. Storage accepts presentationTexts on creation since feat: accept presentationTexts when creating an instance altinn-storage#1129. Against a Storage without that change, the presentation texts are silently dropped while data values and due date still work. Localtest gets the same change in Altinn/altinn-studio (feat(localtest): accept presentationTexts when creating an instance) and Altinn/app-localtest.
  • The OpenAPI snapshots gained the three new properties on the CopyInstanceSettings schema, coming from the package update. The public API of the app libraries is unchanged.

Follow-ups

  • Docs: Altinn/altinn-studio-docs PR (linked below) documents the new settings for v8 and v9 and in the app metadata model reference.
  • Altinn Studio: application-metadata.schema.v1.json in the monorepo should get the three new properties so Studio validates them. Left out of this PR since this repository is subtree-merged into the monorepo later.

Verification

  • New unit tests in InstancesController_CopyInstanceTests cover the legacy copy endpoint: the instance template sent to Storage has the listed values and dueBefore, unlisted and missing keys are left out, nothing is copied when the settings are absent, and no separate UpdateDataValues/UpdatePresentationTexts calls are made.
  • New end-to-end test CopyInstance_SimplifiedEndpoint_CopiesConfiguredValuesFromSource in InstancesController_PostNewInstanceTests creates a source instance with a due date and custom data values/presentation texts, archives it, copies it through instances/create and asserts the copied instance's dueBefore, dataValues and presentationTexts.
  • New AppMetadataTest verifies that applicationmetadata.json with the new settings deserializes as expected.
  • Altinn.App.Core.Tests and Altinn.App.Api.Tests run on net10.0 (only runtime available locally): all tests pass except two pre-existing file-watcher tests (*ReloadsWhenKubernetesDataSymlinkChanges) that time out in this sandbox and are unrelated to this change. net8.0 was not run locally.
  • dotnet csharpier check passes.

🤖 Generated with Claude Code

…an instance

Honours the includeDueBefore, includedDataValues and includedPresentationTexts
settings in copyInstanceSettings in applicationmetadata.json. The settings
were added to CopyInstanceSettings in Altinn.Platform.Storage.Interface
4.7.2, which this change updates to.

Both the legacy copy endpoint and the simplified instantiation endpoint
with sourceInstanceId honour the settings. Listed data values and
presentation texts are copied from the source instance after the form data
has been copied, so they take precedence over values derived from
dataFields and presentationFields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 10:14
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 53459433-6a32-4bbd-9e79-cb7809824b4f

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

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

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The implementation consistently covers both copy paths and includes appropriate automated verification.

Review effort: Balanced
Findings: None

What changed in this PR

Adds configurable copying of due dates, selected data values, and presentation texts for both instance-copy endpoints.

Changes:

  • Adds copy settings via Storage Interface 4.7.2.
  • Copies configured metadata with request due dates taking precedence.
  • Adds unit, integration, deserialization, and OpenAPI coverage.
File Description
Directory.Packages.props Updates the Storage Interface dependency.
src/​Altinn.App.Api/​Controllers/​InstancesController.cs Implements configured metadata copying.
test/​Altinn.App.Api.Tests/​Controllers/​InstancesController_CopyInstanceTests.cs Tests legacy copy behavior.
test/​Altinn.App.Api.Tests/​Controllers/​InstancesController_PostNewInstanceTests.cs Tests simplified endpoint copying end-to-end.
test/​Altinn.App.Core.Tests/​Internal/​App/​AppMetadataTest.cs Tests settings deserialization.
test/​Altinn.App.Core.Tests/​Internal/​App/​TestData/​AppMetadata/​copy-instance-settings.applicationmetadata.json Provides metadata test data.
test/​Altinn.App.Api.Tests/​OpenApi/​OpenApiSpecChangeDetection.SaveJsonSwagger.verified.json Updates the JSON OpenAPI snapshot.
test/​Altinn.App.Api.Tests/​OpenApi/​OpenApiSpecChangeDetection.SaveCustomOpenApiSpec.verified.json Updates the custom OpenAPI snapshot.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Altinn.App.Api/Controllers/InstancesController.cs Dismissed
…e instance

Storage accepts presentationTexts on instance creation since
Altinn/altinn-storage#1129, and has always accepted dataValues. Setting
the included values on the instance template removes the separate
UpdateDataValues and UpdatePresentationTexts calls after the copy.

Values derived from dataFields and presentationFields are calculated
after the form data is copied, so they now win over the copied values
for overlapping keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ivarne ivarne added the feature Label Pull requests with new features. Used when generation releasenotes label Oct 2, 2026

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Documented precedence and derived-field override behavior still lack regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

Comment thread src/Altinn.App.Api/Controllers/InstancesController.cs
…opying

The simplified instantiation test now runs with and without dueBefore in
the copy request, and asserts that the request value wins over the source
instance. It also lists a presentation text derived from presentationFields
in includedPresentationTexts, with a stale value on the source, and asserts
that the copy gets the value recalculated from the copied form data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ivarne

ivarne commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

/publish

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

PR release:

⚙️ Building...
✅ Done!

This branch has not been deployed

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

Labels

feature Label Pull requests with new features. Used when generation releasenotes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICopyInstanceValidator: behov for å få kopiert over datavalues fra orginal til kopi instans

4 participants