< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.MailgunRestrictionLiftNotifier
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Email/MailgunRestrictionLiftNotifier.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
NotifyAsync()100%22100%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Email/MailgunRestrictionLiftNotifier.cs

#LineLine coverage
 1using ArturRios.Heimdall.Command.Services;
 2using ArturRios.Heimdall.Shared.Security;
 3using ArturRios.Messaging.Email;
 4
 5namespace ArturRios.Heimdall.WebApi.Email;
 6
 7/// <summary>
 8///     Sends GDPR Art. 18(3)'s notification through Mailgun, and reports whether it was accepted.
 9/// </summary>
 10/// <remarks>
 11///     Deliberately does not extend <see cref="MailgunSender" />. That base class swallows delivery
 12///     failures on purpose, which is right for every other email this API sends and wrong for this
 13///     one — see <see cref="IRestrictionLiftNotifier" />.
 14/// </remarks>
 315public class MailgunRestrictionLiftNotifier(
 316    IEmailService emailService,
 317    ILogger<MailgunRestrictionLiftNotifier> logger) : IRestrictionLiftNotifier
 18{
 19    private const string Subject = "The restriction on your account is being lifted";
 20
 21    public async Task<bool> NotifyAsync(string email)
 22    {
 23        const string body = """
 24                            You asked us to restrict processing of your data, and that restriction is
 25                            being lifted.
 26
 27                            Your account will work normally again. If you did not expect this, or you
 28                            believe the matter that led to the restriction is unresolved, reply to
 29                            this message.
 30                            """;
 31
 32        try
 33        {
 334            var result = await emailService.SendEmailAsync(email, Subject, body);
 35
 236            if (!result.Success)
 37            {
 138                logger.LogError(
 139                    "Mailgun refused the restriction lift notification for {EmailRef}: {Errors}",
 140                    LogSafeEmail.Reference(email), string.Join(" | ", result.Errors));
 41            }
 42
 243            return result.Success;
 44        }
 145        catch (Exception exception)
 46        {
 147            logger.LogError(
 148                exception, "Could not deliver the restriction lift notification to {EmailRef}",
 149                LogSafeEmail.Reference(email));
 50
 151            return false;
 52        }
 353    }
 54}