Skip to content

extend delegation problem with reasoncodes for systemuser delegation - #2387

Merged
acn-dgopa merged 13 commits into
mainfrom
feature/map-delegationerror-reasons-systemuser
Jul 30, 2026
Merged

extend delegation problem with reasoncodes for systemuser delegation#2387
acn-dgopa merged 13 commits into
mainfrom
feature/map-delegationerror-reasons-systemuser

Conversation

@acn-dgopa

@acn-dgopa acn-dgopa commented Jul 17, 2026

Copy link
Copy Markdown
Member

extend delegation problem with reasoncodes and actual failing delegation package and resource name

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)

Summary by CodeRabbit

  • New Features
    • Delegation errors can now show backend-provided delegation reasons inside the existing alert, with preserved line breaks.
    • Added new localized delegation-related error messages for codes 69–71.
  • Bug Fixes
    • Improved delegation error handling so delegation reason details are forwarded when available and omitted safely when missing or invalid.
  • Tests
    • Updated and extended automated tests to verify delegation reason forwarding and the new error-code mappings.

@acn-dgopa
acn-dgopa requested review from Copilot and mgunnerud July 17, 2026 08:38
@github-actions github-actions Bot added the kind/feature-request Used when issue is a new feature or request label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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
📝 Walkthrough

Walkthrough

ProblemMapper now returns ProblemInstance values and forwards delegation reasons. The frontend accepts, resolves, and displays those reasons using access package/resource context, new error mappings, localized text, and updated call-site wiring.

Changes

Delegation reason forwarding

Layer / File(s) Summary
Map and forward delegation extensions
backend/src/.../Constants/Problem.cs, backend/src/.../Helpers/ProblemMapper.cs, backend/src/.../Tests/Helpers/ProblemMapperTest.cs
ProblemMapper creates ProblemInstance results, forwards selected non-empty extensions, adds delegation descriptors for codes 69–71, and tests extension preservation.
Render and resolve delegation reasons
src/features/amUI/systemUser/types.ts, src/features/amUI/systemUser/components/DelegationCheckError/*, src/features/amUI/systemUser/errorHandling.ts, src/localizations/*
DelegationCheckError parses delegation reasons, resolves packages/resources, maps reason codes, and renders localized messages with preserved line breaks.
Wire context into error views
src/features/amUI/systemUser/...
System user pages pass access package and resource data to DelegationCheckError.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Auth as Upstream AUTH
  participant Mapper as ProblemMapper
  participant ErrorView as DelegationCheckError
  participant Catalog as Access package and resource data
  Auth->>Mapper: Return problem with delegationReasons
  Mapper->>Mapper: Extract configured extension
  Mapper->>ErrorView: Provide ProblemDetail with delegationReasons
  ErrorView->>Catalog: Resolve package or resource identifiers
  ErrorView->>ErrorView: Map reason codes and render details
Loading

Possibly related PRs

Suggested labels: Test, Text

Suggested reviewers: mgunnerud

Poem

Reasons cross the backend stream,
From mapped errors to the screen.
Packages, rights, and messages align,
While alerts preserve each line.
Error details now plainly gleam.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% 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 matches the main change: extending system user delegation problem reporting with reason codes.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/map-delegationerror-reasons-systemuser

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.

@acn-dgopa acn-dgopa changed the title extend delegation problem with reasoncodes and actual failing delegat… extend delegation problem with reasoncodes for systemuser delegation Jul 17, 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.

Pull request overview

This PR extends the delegation error surface from the backend to the frontend by forwarding and rendering an upstream problem “extension” field (delegationReasons) so delegation/approval failures can show the concrete failing package/right and reason.

Changes:

  • Added delegationReasons?: string to the frontend ProblemDetail model and rendered it in DelegationCheckError.
  • Added styling for multi-line reason text in the error alert (white-space: pre-line).
  • Updated backend ProblemMapper.MapToAuthUiError to forward selected upstream problem extension members (currently delegationReasons), and adjusted tests to use the new return type.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/features/amUI/systemUser/types.ts Adds delegationReasons to the problem type used by system user UI.
src/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.tsx Displays forwarded delegation reasons in the error alert.
src/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.module.css Styles the delegated reason details for readability (multi-line).
backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Tests/Helpers/ProblemMapperTest.cs Updates tests to use ProblemInstance return type.
backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Helpers/ProblemMapper.cs Forwards selected upstream problem extensions (e.g. delegationReasons) when mapping AUTH problems.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.tsx`:
- Around line 101-115: Harden the reasons.map rendering in DelegationCheckError
against malformed entries by validating that each reason is an object with a
usable codes array before iterating, and provide a safe fallback for invalid
entries. Update package handling to fall back to reason.id when the package is
missing, and resolve unknown ReasonErrorMap codes without throwing while
preserving the existing translated-message format; also include package codes if
the payload provides them.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b9ea282a-28cd-49ea-bfb4-4f6099c0deeb

📥 Commits

Reviewing files that changed from the base of the PR and between f4e8ed8 and f89d1cf.

📒 Files selected for processing (12)
  • backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Constants/Problem.cs
  • backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Helpers/ProblemMapper.cs
  • src/features/amUI/systemUser/CreateSystemUserPage/RightsIncluded.tsx
  • src/features/amUI/systemUser/SystemUserAgentDelegationPage/SystemUserAgentDelegationPageContent.tsx
  • src/features/amUI/systemUser/SystemUserAgentRequestPage.tsx
  • src/features/amUI/systemUser/SystemUserChangeRequestPage.tsx
  • src/features/amUI/systemUser/SystemUserRequestPage.tsx
  • src/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.tsx
  • src/features/amUI/systemUser/errorHandling.ts
  • src/localizations/en.json
  • src/localizations/no_nb.json
  • src/localizations/no_nn.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Helpers/ProblemMapper.cs

@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/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.tsx`:
- Around line 151-153: Update the single-code branch in DelegationCheckError to
pass the result of mapErrorCodeToErrorMessage through the existing translation
function t(), matching the multi-code branch, so single-reason errors render
localized text rather than the raw translation key.
- Around line 143-149: Add a stable key prop to each DsListItem returned by the
codes.map callback in DelegationCheckError, using the mapped code value or
another unique identifier already available in that iteration.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d275497a-b39d-40ac-9077-e3a39532ef85

📥 Commits

Reviewing files that changed from the base of the PR and between f89d1cf and 54d8da9.

📒 Files selected for processing (6)
  • src/features/amUI/systemUser/SystemUserAgentDelegationPage/SystemUserAgentDelegationPageContent.tsx
  • src/features/amUI/systemUser/SystemUserAgentRequestPage.tsx
  • src/features/amUI/systemUser/components/DelegationCheckError/DelegationCheckError.tsx
  • src/localizations/en.json
  • src/localizations/no_nb.json
  • src/localizations/no_nn.json
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/features/amUI/systemUser/SystemUserAgentRequestPage.tsx
  • src/localizations/no_nn.json
  • src/features/amUI/systemUser/SystemUserAgentDelegationPage/SystemUserAgentDelegationPageContent.tsx
  • src/localizations/en.json
  • src/localizations/no_nb.json

@sonarqubecloud

Copy link
Copy Markdown

@Nyeng
Nyeng self-requested a review July 29, 2026 12:58
@acn-dgopa
acn-dgopa merged commit fdb4d0a into main Jul 30, 2026
10 checks passed
@acn-dgopa
acn-dgopa deleted the feature/map-delegationerror-reasons-systemuser branch July 30, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature-request Used when issue is a new feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants