< Summary

Information
Class: Elsa.Identity.Services.RoleSecurityNotifier
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/RoleSecurityNotifier.cs
Line coverage
62%
Covered lines: 5
Uncovered lines: 3
Coverable lines: 8
Total lines: 33
Line coverage: 62.5%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
RoleChangedAsync(...)100%11100%
UserRolesChangedAsync(...)100%210%
Context(...)50%44100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/RoleSecurityNotifier.cs

#LineLine coverage
 1using System.Security.Claims;
 2using Elsa.Common;
 3using Elsa.Common.Multitenancy;
 4using Elsa.Identity.Notifications;
 5using Elsa.Mediator.Contracts;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Identity.Services;
 9
 10/// <summary>Publishes role and assignment changes for audit subscribers.</summary>
 11/// <remarks>
 12/// Follows ADR 0007: typed, redacted notifications over the mediator, with no audit persistence owned
 13/// here. A future audit module subscribes, stores, and sets its own retention policy without coupling
 14/// identity administration to an audit database.
 15/// </remarks>
 16[UsedImplicitly]
 2217public class RoleSecurityNotifier(INotificationSender notificationSender, ITenantAccessor tenantAccessor, ISystemClock c
 18{
 19    /// <summary>Publishes a role creation, update, or deletion.</summary>
 20    public Task RoleChangedAsync(ClaimsPrincipal? actor, string operation, string roleId, string roleName, IReadOnlyColl
 421        notificationSender.SendAsync(
 422            new RoleChanged(Context(actor, $"Role '{roleName}' {operation}."), operation, roleId, roleName, permissions)
 423            cancellationToken);
 24
 25    /// <summary>Publishes a change to the roles a user holds.</summary>
 26    public Task UserRolesChangedAsync(ClaimsPrincipal? actor, string userId, IReadOnlyCollection<string> assigned, IRead
 027        notificationSender.SendAsync(
 028            new UserRoleAssignmentChanged(Context(actor, $"Roles changed for user '{userId}': {assigned.Count} assigned,
 029            cancellationToken);
 30
 31    private RoleSecurityEventContext Context(ClaimsPrincipal? actor, string summary) =>
 432        new(actor?.Identity?.Name, tenantAccessor.TenantId, clock.UtcNow, summary);
 33}