< Summary

Information
Class: Services.AiAssistant.AiOrderScopeApplier
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/AiAssistant/AiOrderScopeApplier.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ApplyAsync()100%88100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/AiAssistant/AiOrderScopeApplier.cs

#LineLine coverage
 1using OzonDomains.Models;
 2using Services.Authorization.Services;
 3
 4namespace Services.AiAssistant;
 5
 6/// <summary>
 7/// Применяет DataScope и ограничения по складам к запросам заказов для AI-ассистента.
 8/// </summary>
 9public sealed class AiOrderScopeApplier
 10{
 11    private readonly IDataScopeService _dataScopeService;
 12    private readonly IScopeFilterValuesService _scopeFilterValuesService;
 13
 1214    public AiOrderScopeApplier(
 1215        IDataScopeService dataScopeService,
 1216        IScopeFilterValuesService scopeFilterValuesService)
 17    {
 1218        _dataScopeService          = dataScopeService;
 1219        _scopeFilterValuesService  = scopeFilterValuesService;
 1220    }
 21
 22    public async Task<IQueryable<Order>> ApplyAsync(
 23        IQueryable<Order> query,
 24        string? userId,
 25        CancellationToken ct = default)
 26    {
 1227        if (string.IsNullOrWhiteSpace(userId))
 428            return query;
 29
 830        var scoped = await _dataScopeService.ApplyDataScopeAsync(
 831            query, userId, entityName: "Order", extraParameters: null, ct);
 32
 833        var allowed = await _scopeFilterValuesService.GetAllowedValuesAsync(userId, "Order", ct);
 834        if (allowed.TryGetValue("ShipmentWarehouseId", out var allowedWarehouseIdsRaw) &&
 835            allowedWarehouseIdsRaw.Count > 0)
 36        {
 537            var allowedWarehouseIds = allowedWarehouseIdsRaw
 1438                .Select(x => int.TryParse(x, out var id) ? id : (int?)null)
 1439                .Where(x => x.HasValue)
 840                .Select(x => x!.Value)
 541                .Distinct()
 542                .ToArray();
 43
 544            if (allowedWarehouseIds.Length > 0)
 45            {
 446                scoped = scoped.Where(o =>
 447                    o.ShipmentWarehouseId.HasValue &&
 448                    allowedWarehouseIds.Contains(o.ShipmentWarehouseId.Value));
 49            }
 50        }
 51
 852        return scoped;
 1253    }
 54}