Skip to content

fix: only use id directly if scheme is null#93

Open
SondreJDigdir wants to merge 5 commits into
mainfrom
fix/subject-scheme-check
Open

fix: only use id directly if scheme is null#93
SondreJDigdir wants to merge 5 commits into
mainfrom
fix/subject-scheme-check

Conversation

@SondreJDigdir

@SondreJDigdir SondreJDigdir commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

If scheme is not null, subjectparty id is prepended with scheme id. Only use id directly if scheme is null

Documentation

  • Doc updated

Summary by CodeRabbit

  • New Features

    • Added a new test-only Tilda data source with fixed organization details and predefined alert endpoints for testing.
  • Bug Fixes

    • Improved subject identifier handling when fetching audit coordination and audit reports, ensuring the correct report/evidence sources are queried.
    • When no coordination/report results are found, the system now returns a consistent empty evidence payload and skips unnecessary follow-up steps.
  • Chores

    • Simplified the Digitaliseringsdirektoratet Tilda data source implementation.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Audit evidence and shared Tilda URI construction now select subject from SubjectParty conditionally on Scheme. Source initialization also changed, and a new TestTilsyn data source was added with MTAM alert URI generation.

Changes

Tilda subject handling and source updates

Layer / File(s) Summary
Shared subject lookup
src/Dan.Plugin.Tilda/Extensions/EvidenceHarvesterRequestExtension.cs, src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs
GetTildaSubject now selects subject data from SubjectParty based on Scheme, and the shared audit URI builders use it when calling GetUri(...).
Evidence builders and empty responses
src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs, src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs
Both evidence builders now use GetTildaSubject(), add empty-response early returns when npdid is true and no results are collected, and reuse the earlier EvidenceBuilder instance.
Source constructors and test source
src/Dan.Plugin.Tilda/TildaSources/Digitaliseringsdirektoratet.cs, src/Dan.Plugin.Tilda/TildaSources/TestTilsyn.cs
Digitaliseringsdirektoratet trims interfaces and code initialization, adds a parameterless constructor, and TestTilsyn adds a new data source with hardcoded metadata, constructors, and MTAM alert URI methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • data-altinn-no/plugin-tilda#57: This PR also split out and changed the audit evidence-generation classes where these flows now live.
  • data-altinn-no/plugin-tilda#77: Both PRs adjust the AuditReportFunctions and AuditCoordinationFunctions evidence flow with early-return handling and EvidenceBuilder reuse.
  • data-altinn-no/plugin-tilda#87: Both PRs modify the same audit evidence path where subject and npdid influence report and coordination retrieval.

Suggested reviewers

  • erlendoksvoll
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the core change to subject handling: use the raw ID only when the scheme is null.
Docstring Coverage ✅ Passed Docstring coverage is 7.14% which is sufficient. The required threshold is 0.00%.
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 fix/subject-scheme-check

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 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/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs`:
- Line 57: The subject derivation in AuditCoordinationFunctions is using the
wrong fallback when SubjectParty.Scheme is present. Update the subject-building
logic in the method that assigns subject so it uses the scheme-prefixed
identifier (Scheme + Id) whenever Scheme is set, and only uses the plain Id when
Scheme is null. Keep the change localized to the existing req.SubjectParty
handling so npdid stays classified correctly and the query path is selected from
the intended identifier.

In `@src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs`:
- Line 57: The subject derivation in AuditReportFunctions should follow the PR
contract: use SubjectParty.Id when SubjectParty.Scheme is null, and when Scheme
is present build the subject from Scheme plus Id instead of switching to
NorwegianOrganizationNumber. Update the logic around the subject variable so the
later npdid/lookup branching in this function continues to receive the expected
identifier format.
🪄 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: 60c6fb61-7cce-4174-81f2-8fda34dd53f8

📥 Commits

Reviewing files that changed from the base of the PR and between 03793a8 and b4d618b.

📒 Files selected for processing (2)
  • src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs
  • src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs

Comment thread src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs Outdated
Comment thread src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 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/Dan.Plugin.Tilda/TildaSources/TestTilsyn.cs`:
- Around line 41-50: The parameterless TestTilsyn constructor leaves the _code
field unset, but GetAlertUri, GetSingleAlertUri, and PostAlertUri all embed it
in the generated query string. Update TestTilsyn so _code is always initialized
before any URI methods can run, either by removing or redirecting the
parameterless constructor to the DI-backed constructor, or by giving it a safe
default/fallback value consistent with the existing constructor behavior.

In `@src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs`:
- Around line 86-87: The subject value in TildaDataSource needs to be
scheme-aware: the current logic in TildaDataSource.GetAuditReportUri-style URI
construction branches on req.SubjectParty.Scheme but still emits only the raw Id
or NorwegianOrganizationNumber, which omits the required scheme:id format.
Update the subject construction used for all three GetUri call sites so that
when SubjectParty.Scheme is present it prefixes the identifier with that scheme,
and otherwise falls back to the existing identifier-only value. Keep the change
localized to the shared subject-building logic in TildaDataSource so the audit
report, transfer, and other URI paths all receive the same correctly formatted
subject.
🪄 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: 06085af8-bcb9-4126-ba84-9ed3547a5729

📥 Commits

Reviewing files that changed from the base of the PR and between b4d618b and 9913626.

📒 Files selected for processing (3)
  • src/Dan.Plugin.Tilda/TildaSources/Digitaliseringsdirektoratet.cs
  • src/Dan.Plugin.Tilda/TildaSources/TestTilsyn.cs
  • src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs
💤 Files with no reviewable changes (1)
  • src/Dan.Plugin.Tilda/TildaSources/Digitaliseringsdirektoratet.cs

Comment thread src/Dan.Plugin.Tilda/TildaSources/TestTilsyn.cs
Comment thread src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs Outdated

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs (1)

58-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Centralize the Tilda subject-resolution rule.

This Scheme/Id/NorwegianOrganizationNumber branch now exists here and in src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs:84-91. Pulling it into one shared helper would reduce the chance that npdid classification and URI construction drift apart again.

Based on learnings and the matching upstream contract in src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs:84-91, this subject-selection rule is repository-wide.

🤖 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 `@src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs` around lines 58
- 59, The subject-resolution logic is duplicated and can drift between
AuditCoordinationFunctions and TildaDataSource. Extract the shared
Scheme/Id/NorwegianOrganizationNumber selection into one helper used by both the
npdid classification in AuditCoordinationFunctions and the URI construction in
TildaDataSource, so both paths always derive the subject the same way.

Source: Learnings

🤖 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.

Nitpick comments:
In `@src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs`:
- Around line 58-59: The subject-resolution logic is duplicated and can drift
between AuditCoordinationFunctions and TildaDataSource. Extract the shared
Scheme/Id/NorwegianOrganizationNumber selection into one helper used by both the
npdid classification in AuditCoordinationFunctions and the URI construction in
TildaDataSource, so both paths always derive the subject the same way.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e65c173-7889-4c3f-8fc2-bb77c759da34

📥 Commits

Reviewing files that changed from the base of the PR and between 9913626 and 1bc3fc8.

📒 Files selected for processing (3)
  • src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs
  • src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs
  • src/Dan.Plugin.Tilda/TildaSources/Digitaliseringsdirektoratet.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs

@SondreJDigdir

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 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/Dan.Plugin.Tilda/Extensions/EvidenceHarvesterRequestExtension.cs`:
- Around line 47-50: GetTildaSubject can return null when Scheme is present but
NorwegianOrganizationNumber is missing, which later breaks callers that assume a
non-null string. Update the return logic in
EvidenceHarvesterRequestExtension.GetTildaSubject to fall back to
req.SubjectParty.Id whenever NorwegianOrganizationNumber is null, ensuring the
method always returns a non-null value for AuditReportFunctions and
AuditCoordinationFunctions.
🪄 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: 8bed358f-a789-4bcb-8cfb-36946f9e5588

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc3fc8 and b9bbb4e.

📒 Files selected for processing (4)
  • src/Dan.Plugin.Tilda/Extensions/EvidenceHarvesterRequestExtension.cs
  • src/Dan.Plugin.Tilda/Functions/AuditCoordinationFunctions.cs
  • src/Dan.Plugin.Tilda/Functions/AuditReportFunctions.cs
  • src/Dan.Plugin.Tilda/TildaSources/TildaDataSource.cs

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.

1 participant