Skip to content

Refactor merchant validation flow to reduce security-check complexity#1688

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-security-checks-complexity
Mar 18, 2026
Merged

Refactor merchant validation flow to reduce security-check complexity#1688
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-security-checks-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

The merchant security-check path carried the same estate/merchant retrieval and validation branches across multiple operations, leaving the current implementation with the same maintainability problem as the original PerformSecurityChecks warning. This change consolidates that logic into a single helper and updates merchant operations to use it consistently.

  • What changed

    • Introduced GetValidatedMerchantContext(...) in MerchantDomainService to:
      • load the estate aggregate
      • load the merchant aggregate
      • run the existing ValidateEstateAndMerchant(...) checks
      • return both validated aggregates as a single context
    • Replaced repeated inline validation blocks in merchant command handlers with the shared helper.
  • Where the refactor applies

    • Merchant operations that previously duplicated the same security-check flow now delegate to the shared context loader, including:
      • device add/swap
      • operator assignment/removal
      • merchant user creation
      • deposit/withdrawal prerequisites
      • contract add/remove
      • merchant/address/contact updates
      • schedule/opening-hours updates
  • Behavior preserved

    • No validation rules were changed.
    • Existing error paths and messages still come from the same validation methods; only the orchestration was centralized.
  • Illustrative example

    Result<ValidatedMerchantContext> contextResult =
        await this.GetValidatedMerchantContext(command.EstateId, command.MerchantId, cancellationToken);
    
    if (contextResult.IsFailed)
        return ResultHelpers.CreateFailure(contextResult);
    
    MerchantAggregate merchantAggregate = contextResult.Data.MerchantAggregate;

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 test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj --filter VerifyBootstrapperIsValid --no-restore -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter MerchantDomainService_ --no-restore -nologo (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>[Complexity] Method MerchantController::PerformSecurityChecks has a cyclomatic complexity of 11 (limit is 8)</issue_title>
<issue_description>Codacy ID: 6c566c35dda4ec463e3c4620e4f62a4

File: TransactionProcessor/Controllers/MerchantController.cs
Line: 61
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method MerchantController::PerformSecurityChecks has a cyclomatic complexity of 11 (limit is 8)

**Code Snippet:**
```csharp
    private Result PerformSecurityChecks(Guid estateId,Guid merchantId) { 
```

</issue_description>

<agent_instructions>add the maintenance label to the pull request</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce cyclomatic complexity in PerformSecurityChecks method Refactor merchant validation flow to reduce security-check complexity Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 16:06
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 16:06
@StuartFerguson StuartFerguson merged commit 8266542 into master Mar 18, 2026
7 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.

[Complexity] Method MerchantController::PerformSecurityChecks has a cyclomatic complexity of 11 (limit is 8)

2 participants