Skip to content

Add ASD search in KRR by phone number - #1005

Open
SandGrainOne wants to merge 5 commits into
mainfrom
feature/696-give-asd-access-to-krr-search-by-phone-number
Open

Add ASD search in KRR by phone number#1005
SandGrainOne wants to merge 5 commits into
mainfrom
feature/696-give-asd-access-to-krr-search-by-phone-number

Conversation

@SandGrainOne

@SandGrainOne SandGrainOne commented Jul 24, 2026

Copy link
Copy Markdown
Member

Description

Adding an endpoint to the Dashboard spesific API. The new endpoint will enable phone number based search in KRR.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green
  • Manual testing done (required)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features
    • Added dashboard lookup of user contact information by phone number, returning email/phone values plus reservation and verification/timestamp details.
    • Supports multiple matches for the same phone number.
  • Bug Fixes
    • Updated dashboard contact information by email test to send the configured email value and corrected request/header casing.
  • Tests
    • Expanded integration and repository tests for phone-number lookups (valid, missing/empty input returning bad request, unauthorized returning forbidden, multiple matches, and no results).
    • Added new API test coverage for the phone-number endpoint.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d64c1118-9a60-4b77-a549-4e2d935a7578

📥 Commits

Reviewing files that changed from the base of the PR and between f15c1d0 and 254df5e.

📒 Files selected for processing (5)
  • src/Altinn.Profile.Core/Integrations/IPersonService.cs
  • test/Altinn.Profile.Tests/IntegrationTests/Mocks/PepWithPDPAuthorizationMockSI.cs
  • test/Altinn.Profile.Tests/Profile.Integrations/Person/PersonRepositoryTests.cs
  • test/Bruno/Profile/Dashboard/User Contact Information By Email.bru
  • test/Bruno/Profile/Dashboard/User Contact Information By PhoneNumber.bru
💤 Files with no reviewable changes (2)
  • test/Bruno/Profile/Dashboard/User Contact Information By Email.bru
  • src/Altinn.Profile.Core/Integrations/IPersonService.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/Bruno/Profile/Dashboard/User Contact Information By PhoneNumber.bru
  • test/Altinn.Profile.Tests/Profile.Integrations/Person/PersonRepositoryTests.cs

📝 Walkthrough

Walkthrough

Adds phone-number contact preference retrieval, dashboard contact-point mapping, dashboard authorization attributes, and automated API, repository, and Bruno test coverage.

Changes

Phone contact lookup

Layer / File(s) Summary
Lookup contract and repository integration
src/Altinn.Profile.Core/Integrations/IPersonService.cs, src/Altinn.Profile.Core/User.ContactPoints/IUserContactPointsService.cs, src/Altinn.Profile.Integrations/Repositories/PersonRepository.cs, test/Altinn.Profile.Tests/Profile.Integrations/Person/PersonRepositoryTests.cs
Adds the phone-number lookup contract, updates interface and repository documentation, and tests matching, duplicate, and empty-result behavior.
Dashboard contact-point mapping
src/Altinn.Profile.Core/User.ContactPoints/UserContactPointService.cs
Adds phone-based dashboard contact retrieval and maps preferences to DashboardUserContactPoint values.
Dashboard authorization and endpoint validation
src/Altinn.Profile/Controllers/DashboardController.cs, test/Altinn.Profile.Tests/IntegrationTests/API/Controllers/DashboardUserPrivateContactInformationControllerTests.cs, test/Bruno/Profile/Dashboard/*, test/Altinn.Profile.Tests/IntegrationTests/Mocks/PepWithPDPAuthorizationMockSI.cs
Adds general authorization attributes, validates phone lookup responses and access cases, updates Bruno request definitions, and switches mock role deserialization to System.Text.Json.

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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: adding phone-number search support for KRR/Dashboard.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/696-give-asd-access-to-krr-search-by-phone-number

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: 4

🤖 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.Profile.Core/Integrations/IPersonService.cs`:
- Around line 41-42: Align GetContactPreferencesByPhoneNumberAsync’s null-input
behavior across the contract and implementation: either revise the
ArgumentNullException documentation to match the repository’s empty-list
behavior, or update PersonRepository to throw ArgumentNullException for null
phoneNumber while preserving the interface contract; apply the chosen behavior
consistently in both affected files.

In `@src/Altinn.Profile.Core/User.ContactPoints/IUserContactPointsService.cs`:
- Around line 6-8: Restore the opening XML <summary> tag immediately before the
existing interface description for IUserContactPointsService, ensuring it
correctly pairs with the closing </summary> and documents the public interface.

In `@test/Bruno/Profile/Dashboard/User` Contact Information By PhoneNumber.bru:
- Around line 67-120: Update the documentation in the phone contact information
request to describe KRR-only searches and a list response that always uses 200
OK. Remove the SI-user claims and example, change the 400 description to invalid
PhoneNumber header values, and remove the unrelated 404 status entry.
- Around line 53-58: Remove the conditional verification-timestamp assertions
from both contact tests: test/Bruno/Profile/Dashboard/User Contact Information
By PhoneNumber.bru lines 53-58 and test/Bruno/Profile/Dashboard/User Contact
Information By Email.bru lines 53-58. Keep the contact value checks unchanged
and allow emailAddress or phoneNumber to have independently nullable
corresponding timestamps.
🪄 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 Plus

Run ID: 0097feab-a029-42ed-940c-f6c26f30e235

📥 Commits

Reviewing files that changed from the base of the PR and between d7e463a and f15c1d0.

📒 Files selected for processing (9)
  • src/Altinn.Profile.Core/Integrations/IPersonService.cs
  • src/Altinn.Profile.Core/User.ContactPoints/IUserContactPointsService.cs
  • src/Altinn.Profile.Core/User.ContactPoints/UserContactPointService.cs
  • src/Altinn.Profile.Integrations/Repositories/PersonRepository.cs
  • src/Altinn.Profile/Controllers/DashboardController.cs
  • test/Altinn.Profile.Tests/IntegrationTests/API/Controllers/DashboardUserPrivateContactInformationControllerTests.cs
  • test/Altinn.Profile.Tests/Profile.Integrations/Person/PersonRepositoryTests.cs
  • test/Bruno/Profile/Dashboard/User Contact Information By Email.bru
  • test/Bruno/Profile/Dashboard/User Contact Information By PhoneNumber.bru

Comment thread src/Altinn.Profile.Core/Integrations/IPersonService.cs Outdated
Comment on lines +53 to +58
if (contact.emailAddress !== null) {
expect(contact.emailLastUpdatedOrVerified).to.be.a('string');
}
if (contact.phoneNumber !== null) {
expect(contact.phoneNumberLastUpdatedOrVerified).to.be.a('string');
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Allow nullable verification timestamps independently of contact values. The response model and controller mapping permit a populated email/phone value with a null corresponding timestamp, so these assertions can reject valid responses.

  • test/Bruno/Profile/Dashboard/User Contact Information By PhoneNumber.bru#L53-L58: remove the assertions requiring timestamps when the contact value is non-null.
  • test/Bruno/Profile/Dashboard/User Contact Information By Email.bru#L53-L58: remove the same requirement to keep both request tests aligned with the nullable response contract.
📍 Affects 2 files
  • test/Bruno/Profile/Dashboard/User Contact Information By PhoneNumber.bru#L53-L58 (this comment)
  • test/Bruno/Profile/Dashboard/User Contact Information By Email.bru#L53-L58
🤖 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/Bruno/Profile/Dashboard/User` Contact Information By PhoneNumber.bru
around lines 53 - 58, Remove the conditional verification-timestamp assertions
from both contact tests: test/Bruno/Profile/Dashboard/User Contact Information
By PhoneNumber.bru lines 53-58 and test/Bruno/Profile/Dashboard/User Contact
Information By Email.bru lines 53-58. Keep the contact value checks unchanged
and allow emailAddress or phoneNumber to have independently nullable
corresponding timestamps.

Comment on lines +67 to +120
# Get Contact Information by Phone number

Retrieves personal contact information that the user has registered in the national registry (KRR) and from SI users private contact information

## Authentication

Requires Dashboard Maskinporten scope: `altinn:profile.support.admin`

## Parameters

- `PhoneNumber` (header): Phone number to search for

## Response Examples

```json
{
"nationalIdentityNumber": "01010112345",
"isReserved": true,
"emailAddress": null,
"emailLastUpdatedOrVerified": "2025-01-10T11:30:00Z",
"phoneNumber": "+4798765432",
"phoneNumberLastUpdatedOrVerified": "2025-01-15T14:20:00Z",
"username": null
}
```

```json
{
"nationalIdentityNumber": null,
"isReserved": false,
"emailAddress": "jane.smith@example.com",
"emailLastUpdatedOrVerified": "2025-01-10T11:30:00Z",
"phoneNumber": null,
"phoneNumberLastUpdatedOrVerified": null,
"username": "epost:jane.smith@example.com"
}
```

## Features

- Returns the contact information that the given user (identified by NIN) has registered in the national common contact register (KRR)
- `phoneNumberLastUpdatedOrVerified` reflects the last time that the user updated or verified their phone number (whichever operation was performed most recently).
- equivalent for email
- holds `null` if the user has not yet registered a value for that address type
- may have a value for cases where the user has added and then removed the address
- `emailLastUpdatedOrVerified` may have a value even though `emailAddress` is null, if the user has intentionally removed a previous email address from their contact information settings
- Does not apply for `phoneNumber`, as that field cannot be removed once set (only updated to a different valid number)

## Status Codes

- **200 OK**: Successfully retrieved user contact information
- **400 Bad Request**: Invalid request parameters (invalid Email header value)
- **403 Forbidden**: Missing required scope
- **404 Not Found**: User with the provided National Identity Number does not exist

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Correct the phone endpoint documentation.

This endpoint searches KRR only, not SI users, and valid requests always return 200 OK with a list. Remove the SI example/claims and the unrelated 404 status; describe an invalid PhoneNumber header for 400.

🤖 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/Bruno/Profile/Dashboard/User` Contact Information By PhoneNumber.bru
around lines 67 - 120, Update the documentation in the phone contact information
request to describe KRR-only searches and a list response that always uses 200
OK. Remove the SI-user claims and example, change the 400 description to invalid
PhoneNumber header values, and remove the unrelated 404 status entry.

@sonarqubecloud

Copy link
Copy Markdown

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