Skip to content

Refactor Diagnostics Index to use MediatR query pattern#1388

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/refactor-diagnostics-index
Apr 12, 2026
Merged

Refactor Diagnostics Index to use MediatR query pattern#1388
StuartFerguson merged 2 commits intomasterfrom
copilot/refactor-diagnostics-index

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

The Diagnostics/Index page model contained inline business logic (IP loopback check, authentication, claims extraction) rather than delegating through MediatR as every other page in the service does.

Changes

  • OidcCommands — added DiagnosticsQuery(HttpContext)
  • OidcResults — added DiagnosticsQueryResult discriminated union (DiagnosticsPageResult, DiagnosticsNotFoundResult, DiagnosticsChallengeResult) and moved DiagnosticItem here from the page model
  • DiagnosticsRequestHandler (new) — handles DiagnosticsQuery; owns all logic previously inlined in the page: loopback guard, AuthenticateAsync, claims/properties projection
  • Pages/Diagnostics/Index.cshtml.cs — now injects only IMediator, sends the query, and pattern-matches the result to an IActionResult
// Before: logic sprawled directly in OnGetAsync
var result = await this.HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme);
this.Claims = result.Principal.Claims.Select(...).ToArray();

// After: page model is a thin dispatcher
var result = await this._mediator.Send(new OidcCommands.DiagnosticsQuery(this.HttpContext), cancellationToken);
return result.Data switch
{
    DiagnosticsNotFoundResult       => this.NotFound(),
    DiagnosticsChallengeResult c    => this.Challenge(c.AuthenticationScheme),
    DiagnosticsPageResult page      => this.ApplyPageResult(page),
    _                               => this.Page()
};

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.slnx --configuration Release -main/dist/indexcredential.helper (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/SecurityService/SecurityService/SecurityService.slnx --packages /tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 12, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 3 complexity · 0 duplication

Metric Results
Complexity 3
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copilot AI changed the title [WIP] Refactor diagnostics index to use commands and queries Refactor Diagnostics Index to use MediatR query pattern Apr 12, 2026
Copilot AI requested a review from StuartFerguson April 12, 2026 18:05
@StuartFerguson StuartFerguson marked this pull request as ready for review April 12, 2026 18:06
@StuartFerguson StuartFerguson merged commit 6050213 into master Apr 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics Index Refactor

2 participants