< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Shared.Services.OwnedScopeVisibility
Assembly: ArturRios.Heimdall.Shared
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Shared/Services/OwnedScopeVisibility.cs
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ScopesVisibleToAsync()100%22100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Shared/Services/OwnedScopeVisibility.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.Interfaces;
 2using ArturRios.Heimdall.Domain.Entities;
 3using ArturRios.Heimdall.Domain.Enums;
 4using Microsoft.EntityFrameworkCore;
 5
 6namespace ArturRios.Heimdall.Shared.Services;
 7
 8/// <summary>
 9///     FR-PE-19: which of another person's scope ownerships a reader may see. A System Admin sees
 10///     every one; anyone else sees only the ownerships of scopes they own themselves.
 11/// </summary>
 12/// <remarks>
 13///     <para>
 14///         A Scope Admin can read a co-owner, and the owners of their scopes, because they share a
 15///         scope with them. That shared scope is what they are entitled to know about. The other
 16///         scopes the person owns belong to other tenants, so a projection a Scope Admin reads about
 17///         somebody else reports only the ownerships the two have in common.
 18///     </para>
 19///     <para>
 20///         A person reading their own record sees every scope they own either way, since every
 21///         scope they own is one of theirs. The callers that short-circuit a self read do so only to
 22///         save the query.
 23///     </para>
 24/// </remarks>
 25public static class OwnedScopeVisibility
 26{
 27    /// <summary>
 28    ///     The internal ids of the scopes whose ownerships <paramref name="actingPersonId" /> may see
 29    ///     on another person, or <c>null</c> when they may see all of them (a System Admin).
 30    /// </summary>
 31    /// <remarks>
 32    ///     A logically deleted actor owns nothing, as <see cref="ScopeOwnershipChecker" /> holds: they
 33    ///     can no longer authenticate, so a token issued before the deletion reveals nothing.
 34    /// </remarks>
 35    public static async Task<IReadOnlyCollection<long>?> ScopesVisibleToAsync(
 36        IAsyncReadOnlyRepository<Person, long> personReader, int actingRole, Guid actingPersonId)
 37    {
 9738        if (actingRole == (int)Roles.SystemAdmin)
 39        {
 7640            return null;
 41        }
 42
 2143        return await personReader.Query()
 2144            .Where(x => x.PublicId == actingPersonId && !x.IsDeleted)
 2145            .SelectMany(x => x.ScopeOwnerships.Select(ownership => ownership.ScopeId))
 2146            .ToListAsync();
 9747    }
 48}

Methods/Properties

ScopesVisibleToAsync()