Skip to content

add hideAppNameInPdf functionality to footer in the pdf#1753

Open
walldenfilippa wants to merge 8 commits into
mainfrom
feat/18402-hide-app-name-footer-pdf
Open

add hideAppNameInPdf functionality to footer in the pdf#1753
walldenfilippa wants to merge 8 commits into
mainfrom
feat/18402-hide-app-name-footer-pdf

Conversation

@walldenfilippa
Copy link
Copy Markdown

@walldenfilippa walldenfilippa commented May 15, 2026

Description

The hideAppNameInPdf property determines whether the app name is displayed in the PDF footer.
Frontend implementation: Altinn/app-frontend-react#4173

Needs to be checked for consistency and alignment with next.

Related Issue(s)

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

    • PDF footer now adapts to UI settings and can optionally hide the app name.
  • Public API

    • Public constructor/API updated to accept additional dependencies to support layout-based PDF footer behavior.
  • Tests

    • Expanded tests to verify footer rendering and hide-app-name behavior across scenarios, including expressions, missing or malformed settings.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@walldenfilippa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 47 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a98afbcd-8a60-4083-8be7-68d5349da69c

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfeedc and 31202dd.

📒 Files selected for processing (2)
  • src/Altinn.App.Core/Internal/Pdf/PdfService.cs
  • test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs
📝 Walkthrough

Walkthrough

PdfService now supports customizable PDF footer content with optional app name hiding. The service accepts new IAppResources and ILayoutEvaluatorStateInitializer dependencies, reads hideAppNameInPdf from layout UI settings, and evaluates it as either a static boolean or dynamic expression. A new UiSettings model is introduced to the public API. All test fixtures are updated to wire the new dependencies.

Changes

PDF Footer Customization with App Name Hiding

Layer / File(s) Summary
PdfService dependencies and JSON configuration
src/Altinn.App.Core/Internal/Pdf/PdfService.cs
PdfService constructor is updated to accept and store IAppResources and ILayoutEvaluatorStateInitializer. A static JsonSerializerOptions is configured for camelCase deserialization with comment and trailing comma tolerance, enabling expression evaluation support.
Footer customization implementation
src/Altinn.App.Core/Internal/Pdf/PdfService.cs
GetFooterContent method now accepts instance and taskId. Footer title construction conditionally includes or hides the app name. New GetHideAppNameInPdf helper reads uiSettings.hideAppNameInPdf from layout sets and returns a literal boolean or deserializes and evaluates an Expression using layout evaluation state initialization.
Test and controller wiring updates
test/Altinn.App.Api.Tests/Controllers/PdfControllerTests.cs, test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs
PdfControllerTests and PdfServiceTests add an ILayoutEvaluatorStateInitializer mock and pass it into PdfService. New tests validate footer app-name inclusion/exclusion for expression-based, explicit true/false, missing UI settings, and malformed JSON cases.
Public API snapshot
test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
Public API verification updated to include added IAppResources resources and ILayoutEvaluatorStateInitializer layoutStateInit parameters on the PdfService constructor.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% 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 title accurately describes the main change: adding hideAppNameInPdf functionality to the PDF footer, which is the primary purpose of this PR.
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/18402-hide-app-name-footer-pdf

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 and usage tips.

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

🧹 Nitpick comments (1)
test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs (1)

37-37: ⚡ Quick win

Add focused tests for the new footer branches.

The fixture now wires ILayoutEvaluatorStateInitializer, but there are still no assertions around uiSettings.hideAppNameInPdf as a literal boolean, as an expression, or when the config is malformed. Those are the new branches most likely to regress here.

Also applies to: 538-539

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Altinn.App.Core/Internal/Pdf/PdfService.cs`:
- Around line 409-447: Wrap the whole hideAppNameInPdf evaluation in a try/catch
that returns false on any exception so PDF generation fails closed; when parsing
layoutSetsString call JsonDocument.Parse with an explicit JsonDocumentOptions
(set AllowTrailingCommas = true and CommentHandling = JsonCommentHandling.Skip)
instead of relying on _jsonSerializerOptions; after obtaining hideAppNameElement
ensure ValueKind is True/False or safely call
hideAppNameElement.Deserialize<Expression>(_jsonSerializerOptions) and if that
returns null return false; guard against null instance.Data before using
instance.Data.Find; and catch exceptions from
_instanceDataUnitOfWorkInitializer.Init, _layoutStateInit.Init and
ExpressionEvaluator.EvaluateExpression and return false on error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ddfdd5b6-cadf-40d7-9e23-9d1f72286dec

📥 Commits

Reviewing files that changed from the base of the PR and between 829f12b and 72328cc.

📒 Files selected for processing (4)
  • src/Altinn.App.Core/Internal/Pdf/PdfService.cs
  • test/Altinn.App.Api.Tests/Controllers/PdfControllerTests.cs
  • test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

Comment thread src/Altinn.App.Core/Internal/Pdf/PdfService.cs Outdated
Comment thread src/Altinn.App.Core/Internal/Pdf/PdfService.cs Fixed
@walldenfilippa walldenfilippa 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 labels May 15, 2026
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

🧹 Nitpick comments (1)
test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs (1)

37-37: ⚡ Quick win

Consider adding setup for the layout state initializer mock or verifying it's not needed.

The _layoutStateInit mock is instantiated but never configured with any behavior. While Moq allows this, it's worth confirming whether:

  1. The mock should be set up to support expression-based hideAppNameInPdf tests (see comment on lines 480-629), or
  2. The current test scenarios don't require the initializer to be invoked
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs` at line 37, The
_layoutStateInit mock (Mock<ILayoutEvaluatorStateInitializer>) is created but
never configured; either add explicit setups for the calls used in
PdfServiceTests — e.g., configure _layoutStateInit.Setup(s =>
s.InitializeState(It.IsAny<...>())).Returns(...) or Setup for any
expression-based behavior used by the hideAppNameInPdf-related tests — or add
assertions that the initializer is never invoked; update tests referencing
hideAppNameInPdf to call the initializer mock or remove the unused field if it
is truly unnecessary so the test intent is explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs`:
- Around line 480-629: Add a unit test that covers expression-based
hideAppNameInPdf by supplying layoutSets JSON with an expression (e.g.
{"sets":[],"uiSettings":{"hideAppNameInPdf":["equals",["dataModel","someField"],"someValue"]}})
when constructing the PdfService via SetupPdfService, and mock the
ILayoutEvaluatorStateInitializer / its evaluator to evaluate that expression to
true and false respectively so you can Verify GeneratePdf called with footer
that omits the app name when the expression evaluates true and includes it when
false; target the GenerateAndStorePdf method and reuse the existing Instance
setup and _pdfGeneratorClient.Verify pattern to assert behavior.

---

Nitpick comments:
In `@test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs`:
- Line 37: The _layoutStateInit mock (Mock<ILayoutEvaluatorStateInitializer>) is
created but never configured; either add explicit setups for the calls used in
PdfServiceTests — e.g., configure _layoutStateInit.Setup(s =>
s.InitializeState(It.IsAny<...>())).Returns(...) or Setup for any
expression-based behavior used by the hideAppNameInPdf-related tests — or add
assertions that the initializer is never invoked; update tests referencing
hideAppNameInPdf to call the initializer mock or remove the unused field if it
is truly unnecessary so the test intent is explicit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c681f9d8-14df-4a3f-ab85-bfe2243b5910

📥 Commits

Reviewing files that changed from the base of the PR and between 72328cc and 8b7ee7d.

📒 Files selected for processing (2)
  • src/Altinn.App.Core/Internal/Pdf/PdfService.cs
  • test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Altinn.App.Core/Internal/Pdf/PdfService.cs

Comment thread test/Altinn.App.Core.Tests/Internal/Pdf/PdfServiceTests.cs
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
62.5% Condition Coverage on New Code (required ≥ 65%)

See analysis details on SonarQube Cloud

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skjule appName på underskjemaene i pdf-visning

2 participants