Skip to content

Unobsolete GET instance copy endpoint, copy based on Authenticated #1228

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martinothamar
Copy link
Contributor

Description

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)

Comment on lines +259 to +261
var actual = await Assert.ThrowsAsync<PlatformHttpException>(
async () => await controller.CopyInstance("ttd", "copy-instance", instanceOwnerPartyId, instanceGuid)
);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
actual
is useless, since its value is never read.

Copilot Autofix

AI 2 months ago

To fix the problem, we need to remove the unnecessary assignment to the variable actual. The Assert.ThrowsAsync method call should be retained to ensure that the expected exception is thrown, but the result of this call does not need to be assigned to a variable.

  • Remove the assignment to the variable actual on line 259.
  • Retain the Assert.ThrowsAsync method call to ensure the test still verifies that the PlatformHttpException is thrown.
Suggested changeset 1
test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs b/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
--- a/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
+++ b/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
@@ -258,3 +258,3 @@
         var controller = fixture.ServiceProvider.GetRequiredService<InstancesController>();
-        var actual = await Assert.ThrowsAsync<PlatformHttpException>(
+        await Assert.ThrowsAsync<PlatformHttpException>(
             async () => await controller.CopyInstance("ttd", "copy-instance", instanceOwnerPartyId, instanceGuid)
EOF
@@ -258,3 +258,3 @@
var controller = fixture.ServiceProvider.GetRequiredService<InstancesController>();
var actual = await Assert.ThrowsAsync<PlatformHttpException>(
await Assert.ThrowsAsync<PlatformHttpException>(
async () => await controller.CopyInstance("ttd", "copy-instance", instanceOwnerPartyId, instanceGuid)
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link

sonarqubecloud bot commented Apr 2, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)
E Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@@ -597,7 +600,8 @@ await _processEngine.HandleEventsAndUpdateStorage(

/// <summary>
/// This method handles the copy endpoint for when a user wants to create a copy of an existing instance.
/// The endpoint will primarily be accessed directly by a user clicking the copy button for an archived instance.
/// The endpoint will primarily be accessed directly by a user clicking the copy button for an archived instance
/// from the message box in the Altinn 2 portal/Altinn 3 arbeidsflate.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// from the message box in the Altinn 2 portal/Altinn 3 arbeidsflate.
/// from the message box in the Altinn 2 portal/Altinn 3 arbeidsflate.
/// WARNING: The endpoint will be removed in an updated version of the app packages as soon as we have an
/// alternative where dialogporten/arbeidsflate where it doesn't need to rely on the user cookie propagating
/// through a GET request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's discussions going on about the future of Altinn authentication (where/how to store session info, not doing token exchange etc etc) but there is nothing concrete yet, so I don't think it's appropriate to make any assertions on what we'll do at that point. Whatever it is, it has to be planned and agreed upon with the Arbeidsflate team

Copy link
Member

Choose a reason for hiding this comment

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

The important part is that the endpoint might be removed without warning when arbeidsflate has an alternative and stops using it for apps newer than a specific version (or however we decide to do the transition)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is your point that this is only meant to be consumed by Arbeidsflate? And that we don't care about potential breakage for any other possible consumer? If so I agree that we should document that someplace, but I don't think it belongs in an XML doc comment that doesn't go anywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants