EmailDispatcher ist integriert.

This commit is contained in:
Developer 02 2024-06-12 00:40:50 +02:00
parent 0268756cf9
commit 38aa6a6217
21 changed files with 367 additions and 94 deletions

View File

@ -10,6 +10,9 @@ namespace EnvelopeGenerator.Application.Contracts
{ {
Task<DataResult<ConfigDto>> ReadFirstAsync(); Task<DataResult<ConfigDto>> ReadFirstAsync();
async Task<DataResult<ConfigDto>> ReadDefaultAsync() => await ReadFirstAsync(); Task<ConfigDto> ReadDefaultAsync();
}
Task<string> ReadDefaultSignatureHost();
}
} }

View File

@ -17,7 +17,9 @@ namespace EnvelopeGenerator.Application.Contracts
Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true); Task<DataResult<EnvelopeReceiverDto>> ReadByEnvelopeReceiverIdAsync(string envelopeReceiverId, bool withEnvelope = true, bool withReceiver = true);
Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode); Task<DataResult<string>> ReadAccessCodeByIdAsync(int envelopeId, int receiverId);
Task<DataResult<bool>> VerifyAccessCodeAsync(string uuid, string signature, string accessCode);
Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode); Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode);

View File

@ -1,38 +1,66 @@
using DigitalData.UserManager.Domain.Entities; using DigitalData.EmailProfilerDispatcher.Domain.Attributes;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory; using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs
{ {
public record EnvelopeDto( public record EnvelopeDto()
int Id, {
int UserId, public int Id { get; set; }
int Status,
string Uuid, public int UserId { get; set; }
string Message,
DateTime? ExpiresWhen, public int Status { get; set; }
DateTime? ExpiresWarningWhen,
DateTime AddedWhen, public string Uuid { get; set; }
DateTime? ChangedWhen,
string Title, [TemplatePlaceholder("[MESSAGE]")]
int? ContractType, public string Message { get; set; }
string Language, public DateTime? ExpiresWhen { get; set; }
bool? SendReminderEmails, public DateTime? ExpiresWarningWhen { get; set; }
int? FirstReminderDays, public DateTime AddedWhen { get; set; }
int? ReminderIntervalDays, public DateTime? ChangedWhen { get; set; }
int? EnvelopeTypeId,
int? CertificationType, [TemplatePlaceholder("[DOCUMENT_TITLE]")]
bool? UseAccessCode, public string Title { get; set; }
int? FinalEmailToCreator,
int? FinalEmailToReceivers, public int? ContractType { get; set; }
int? ExpiresWhenDays,
int? ExpiresWarningWhenDays, public string Language { get; set; }
bool DmzMoved,
User? User, public bool? SendReminderEmails { get; set; }
EnvelopeType? EnvelopeType,
string? EnvelopeTypeTitle, public int? FirstReminderDays { get; set; }
bool IsAlreadySent,
string? StatusTranslated, public int? ReminderIntervalDays { get; set; }
string? ContractTypeTranslated,
IEnumerable<EnvelopeDocumentDto>? Documents); public int? EnvelopeTypeId { get; set; }
public int? CertificationType { get; set; }
public bool? UseAccessCode { get; set; }
public int? FinalEmailToCreator { get; set; }
public int? FinalEmailToReceivers { get; set; }
public int? ExpiresWhenDays { get; set; }
public int? ExpiresWarningWhenDays { get; set; }
public bool DmzMoved { get; set; }
public UserReadDto? User { get; set; }
public EnvelopeType? EnvelopeType { get; set; }
public string? EnvelopeTypeTitle { get; set; }
public bool IsAlreadySent { get; set; }
public string? StatusTranslated { get; set; }
public string? ContractTypeTranslated { get; set; }
public IEnumerable<EnvelopeDocumentDto>? Documents { get; set; }
}
} }

View File

@ -1,15 +1,32 @@
namespace EnvelopeGenerator.Application.DTOs using DigitalData.EmailProfilerDispatcher.Domain.Attributes;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.DTOs
{ {
public record EnvelopeReceiverDto( public record EnvelopeReceiverDto()
int EnvelopeId, {
int ReceiverId, public int EnvelopeId { get; set; }
int Sequence,
string? Name, public int ReceiverId { get; set; }
string? JobTitle,
string? CompanyName, public int Sequence { get; set; }
string? PrivateMessage,
DateTime AddedWhen, [TemplatePlaceholder("[NAME_RECEIVER]")]
DateTime? ChangedWhen, public string? Name { get; set; }
EnvelopeDto? Envelope,
ReceiverDto? Receiver); public string? JobTitle { get; set; }
public string? CompanyName { get; set; }
public string? PrivateMessage { get; set; }
public DateTime AddedWhen { get; set; }
public DateTime? ChangedWhen { get; set; }
public EnvelopeDto? Envelope { get; set; }
public ReceiverDto? Receiver { get; set; }
}
} }

View File

@ -0,0 +1,13 @@
namespace EnvelopeGenerator.Application
{
public class DispatcherConfig
{
public int SendingProfile { get; init; } = 1;
public string AddedWho { get; init; } = "DDEnvelopGenerator";
public int ReminderTypeId { get; init; } = 202377;
public string EmailAttmt1 { get; init; } = string.Empty;
}
}

View File

@ -102,7 +102,16 @@ namespace EnvelopeGenerator.Application
/// <returns>The receiver signature.</returns> /// <returns>The receiver signature.</returns>
public static string? GetReceiverSignature(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().ReceiverSignature; public static string? GetReceiverSignature(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().ReceiverSignature;
public static void LogEnvelopeError(this ILogger logger, string envelopeReceiverId, Exception? exception = null, string? message = null, params object?[] args) public static string EncodeEnvelopeReceiverId(this (string envelopeUuid, string receiverSignature) input)
{
string combinedString = $"{input.envelopeUuid}::{input.receiverSignature}";
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
string base64String = Convert.ToBase64String(bytes);
return base64String;
}
public static void LogEnvelopeError(this ILogger logger, string envelopeReceiverId, Exception? exception = null, string? message = null, params object?[] args)
{ {
var sb = new StringBuilder().AppendLine(envelopeReceiverId.DecodeEnvelopeReceiverId().ToTitle()); var sb = new StringBuilder().AppendLine(envelopeReceiverId.DecodeEnvelopeReceiverId().ToTitle());

View File

@ -6,22 +6,57 @@ using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Application.Resources;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Infrastructure.Contracts; using EnvelopeGenerator.Infrastructure.Contracts;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
namespace EnvelopeGenerator.Application.Services namespace EnvelopeGenerator.Application.Services
{ {
public class ConfigService : BasicCRUDService<IConfigRepository, ConfigDto, Config, int>, IConfigService public class ConfigService : BasicCRUDService<IConfigRepository, ConfigDto, Config, int>, IConfigService
{ {
public ConfigService(IConfigRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper) private static readonly Guid DefaultConfigCacheId = Guid.NewGuid();
private readonly IMemoryCache _cache;
private readonly ILogger<ConfigService> _logger;
public ConfigService(IConfigRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper, IMemoryCache memoryCache, ILogger<ConfigService> logger) : base(repository, localizer, mapper)
{ {
_cache = memoryCache;
_logger = logger;
} }
public async Task<DataResult<ConfigDto>> ReadFirstAsync() public async Task<DataResult<ConfigDto>> ReadFirstAsync()
{ {
var config = await _repository.ReadFirstAsync(); var config = await _repository.ReadFirstAsync();
return config is null ? Result.Fail<ConfigDto>().Message("There is no configuration in DB.") : Result.Success(_mapper.MapOrThrow<ConfigDto>(config)); return config is null
? Result.Fail<ConfigDto>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, "There is no configuration in DB.")
: Result.Success(_mapper.MapOrThrow<ConfigDto>(config));
} }
public async Task<DataResult<ConfigDto>> ReadDefaultAsync() => await ReadFirstAsync(); /// <summary>
/// Reads the default configuration asynchronously.
/// </summary>
/// <remarks>
/// The configuration is cached in memory upon the first retrieval. If the configuration is updated,
/// the application needs to be restarted for the changes to take effect as the memory cache will not be updated automatically.
/// </remarks>
/// <returns>
/// A task that represents the asynchronous read operation. The task result contains the default configuration as a <see cref="ConfigDto"/>.
/// </returns>
/// <exception cref="InvalidOperationException">
/// Thrown when the default configuration cannot be found.
/// </exception>
public async Task<ConfigDto> ReadDefaultAsync()
{
var config = await _cache.GetOrCreateAsync(DefaultConfigCacheId, _ => ReadFirstAsync().ThenAsync(
Success: config => config,
Fail: (mssg, ntc) =>
{
_logger.LogNotice(ntc);
throw new InvalidOperationException("Default configuration cannot find.");
}));
return config!;
}
public async Task<string> ReadDefaultSignatureHost() => (await ReadDefaultAsync()).SignatureHost;
} }
} }

View File

@ -7,30 +7,93 @@ using DigitalData.UserManager.Application;
using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Common; using EnvelopeGenerator.Common;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.Services namespace EnvelopeGenerator.Application.Services
{ {
public class EnvelopeMailService : EmailOutService<Resource>, IEnvelopeMailService public class EnvelopeMailService : EmailOutService<Resource>, IEnvelopeMailService
{ {
private readonly IEmailTemplateService _tempService; private readonly IEmailTemplateService _tempService;
private readonly IMemoryCache _cache; private readonly IEnvelopeReceiverService _envRcvService;
private readonly DispatcherConfig _dConfig;
private readonly IConfigService _configService;
public EnvelopeMailService(IEmailOutRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper, IEmailTemplateService tempService, IMemoryCache cache) : base(repository, localizer, mapper) public EnvelopeMailService(IEmailOutRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions<DispatcherConfig> dispatcherConfigOptions, IConfigService configService) : base(repository, localizer, mapper)
{ {
_tempService = tempService; _tempService = tempService;
_cache = cache; _envRcvService = envelopeReceiverService;
_dConfig = dispatcherConfigOptions.Value;
_configService = configService;
} }
public Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto envelopeReceiverDto) //TODO: create ioptions and implement TemplatePlaceHolderAttribute instead of this method
{ private async Task<Dictionary<string, string>> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null)
throw new NotImplementedException(); {
} Dictionary<string, string> placeholders = new() {
{ "[NAME_PORTAL]", "signFlow" },
{ "[SIGNATURE_TYPE]" , "signieren"},
{ "[REASON]", string.Empty } };
public Task<DataResult<int>> SendAsync(EnvelopeReceiverDto envelopeReceiverDto, Constants.EmailTemplateType tempType) if (accessCode is not null)
placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode;
if(envelopeReceiverDto is not null && envelopeReceiverDto.Envelope is not null && envelopeReceiverDto.Receiver is not null)
{
var erId = (envelopeReceiverDto.Envelope.Uuid, envelopeReceiverDto.Receiver.Signature).EncodeEnvelopeReceiverId();
var sigHost = await _configService.ReadDefaultSignatureHost();
var linkToDoc = $"{sigHost}/envelope/{erId}";
placeholders["[LINK_TO_DOCUMENT]"] = linkToDoc;
placeholders["[LINK_TO_DOCUMENT_TEXT]"] = linkToDoc[..Math.Min(40, linkToDoc.Length)];
}
return placeholders;
}
public async Task<DataResult<int>> SendAccessCodeAsync(EnvelopeReceiverDto dto) => await SendAsync(dto: dto, tempType: Constants.EmailTemplateType.DocumentAccessCodeReceived);
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverDto dto, Constants.EmailTemplateType tempType)
{ {
throw new NotImplementedException(); var tempSerResult = await _tempService.ReadByNameAsync(tempType);
} if (tempSerResult.IsFailed)
} return tempSerResult.ToFail<int>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"The email cannot send because '{tempType}' template cannot found.");
var temp = tempSerResult.Data;
var mail = new EmailOutCreateDto()
{
EmailAddress = dto.Receiver!.EmailAddress,
EmailSubj = temp.Subject,
EmailBody = temp.Body,
//email_type = envelope_status,
//message = envelope_message,
ReferenceId = dto.EnvelopeId, //REFERENCE_ID = ENVELOPE_ID
ReferenceString = dto!.Envelope!.Uuid, //REFERENCE_STRING = ENVELOPE_UUID
//receiver_name = receiver.name,
//receiver_access_code = receiver.access_code,
//sender_adress = envelope.user.email,
//sender_name = envelope.user.full_name,
//envelope_title = envelope.title,
ReminderTypeId = _dConfig.ReminderTypeId,
SendingProfile = _dConfig.SendingProfile,
EntityId = null,
WfId = (int) EnvelopeStatus.MessageAccessCodeSent,
WfReference = null,
AddedWho = _dConfig.AddedWho,
EmailAttmt1 = _dConfig.EmailAttmt1
};
//get acccess code
var acResult = await _envRcvService.ReadAccessCodeByIdAsync(envelopeId: dto.EnvelopeId, receiverId: dto.ReceiverId);
if (acResult.IsFailed)
return acResult.ToFail<int>().Notice(LogLevel.Error, "Therefore, access code cannot be sent");
var accessCode = acResult.Data;
var placeholders = await CreatePlaceholders(accessCode: accessCode, envelopeReceiverDto: dto);
return await CreateWithTemplateAsync(createDto: mail,placeholders: placeholders,
dto, dto.Envelope.User!, dto.Envelope);
}
}
} }

View File

@ -104,5 +104,13 @@ namespace EnvelopeGenerator.Application.Services
int count = await _repository.CountAsync(uuid:uuid, signature:signature); int count = await _repository.CountAsync(uuid:uuid, signature:signature);
return Result.Success(count > 0); return Result.Success(count > 0);
} }
}
public async Task<DataResult<string>> ReadAccessCodeByIdAsync(int envelopeId, int receiverId)
{
var code = await _repository.ReadAccessCodeByIdAsync(envelopeId: envelopeId, receiverId: receiverId);
return code is null ?
Result.Fail<string>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"Access code is null. Envelope ID is {envelopeId} and receiver ID {receiverId}")
: Result.Success(code);
}
}
} }

View File

@ -6,6 +6,7 @@ using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Infrastructure.Contracts; using EnvelopeGenerator.Infrastructure.Contracts;
using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Application.Resources;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.Services namespace EnvelopeGenerator.Application.Services
{ {

View File

@ -14,5 +14,9 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
Task<string?> ReadAccessCodeAsync(string uuid, string signature); Task<string?> ReadAccessCodeAsync(string uuid, string signature);
Task<int> CountAsync(string uuid, string signature); Task<int> CountAsync(string uuid, string signature);
Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId);
Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId);
} }
} }

View File

@ -1,4 +1,5 @@
using EnvelopeGenerator.Domain.Entities; using DigitalData.EmailProfilerDispatcher.Domain.Entities;
using EnvelopeGenerator.Domain.Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories namespace DigitalData.UserManager.Infrastructure.Repositories
@ -26,6 +27,7 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
modelBuilder.Entity<EnvelopeType>(); modelBuilder.Entity<EnvelopeType>();
modelBuilder.Entity<Receiver>(); modelBuilder.Entity<Receiver>();
modelBuilder.Entity<UserReceiver>(); modelBuilder.Entity<UserReceiver>();
modelBuilder.Entity<EmailOut>();
// Configure the one-to-many relationship of Envelope // Configure the one-to-many relationship of Envelope
modelBuilder.Entity<Envelope>() modelBuilder.Entity<Envelope>()

View File

@ -26,6 +26,9 @@
<Reference Include="DigitalData.Core.Infrastructure"> <Reference Include="DigitalData.Core.Infrastructure">
<HintPath>..\..\WebCoreModules\DigitalData.Core.Infrastructure\bin\Debug\net7.0\DigitalData.Core.Infrastructure.dll</HintPath> <HintPath>..\..\WebCoreModules\DigitalData.Core.Infrastructure\bin\Debug\net7.0\DigitalData.Core.Infrastructure.dll</HintPath>
</Reference> </Reference>
<Reference Include="DigitalData.EmailProfilerDispatcher.Domain">
<HintPath>..\..\EmailProfilerDispatcher\DigitalData.EmailProfilerDispatcher.Application\bin\Debug\net7.0\DigitalData.EmailProfilerDispatcher.Domain.dll</HintPath>
</Reference>
<Reference Include="DigitalData.UserManager.Domain"> <Reference Include="DigitalData.UserManager.Domain">
<HintPath>..\..\WebUserManager\DigitalData.UserManager.Domain\bin\Debug\net7.0\DigitalData.UserManager.Domain.dll</HintPath> <HintPath>..\..\WebUserManager\DigitalData.UserManager.Domain\bin\Debug\net7.0\DigitalData.UserManager.Domain.dll</HintPath>
</Reference> </Reference>

View File

@ -49,5 +49,17 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync(); public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
}
public IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId) => _dbSet
.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
.FirstOrDefaultAsync();
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
.Select(er => er.AccessCode)
.FirstOrDefaultAsync();
}
} }

View File

@ -42,11 +42,18 @@ namespace EnvelopeGenerator.Web.Controllers
Body = "Wenn Sie diese URL in Ihrer E-Mail erhalten haben, wenden Sie sich bitte an das IT-Team." Body = "Wenn Sie diese URL in Ihrer E-Mail erhalten haben, wenden Sie sich bitte an das IT-Team."
}); });
public static ViewResult ViewInnerServiceError(this Controller controller) => controller.ViewError(new() public static ViewResult ViewAccessCodeNotSent(this Controller controller) => controller.ViewError(new()
{
Title = "500",
Subtitle = "Der Zugangscode konnte nicht gesendet werden",
Body = "Bitte kontaktieren Sie das IT-Team."
});
public static ViewResult ViewInnerServiceError(this Controller controller) => controller.ViewError(new()
{ {
Title = "500", Title = "500",
Subtitle = "Ein unerwarteter Fehler ist aufgetreten", Subtitle = "Ein unerwarteter Fehler ist aufgetreten",
Body = "Bitte kontaktieren Sie das IT-Team." Body = "Bitte kontaktieren Sie das IT-Team."
}); });
} }
} }

View File

@ -27,8 +27,8 @@ namespace EnvelopeGenerator.Web.Controllers
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly UrlEncoder _urlEncoder; private readonly UrlEncoder _urlEncoder;
private readonly Cultures _cultures; private readonly Cultures _cultures;
private readonly IEnvelopeMailService _mailService;
public HomeController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, UrlEncoder urlEncoder, Cultures cultures) : base(databaseService, logger) public HomeController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, UrlEncoder urlEncoder, Cultures cultures, IEnvelopeMailService envelopeMailService) : base(databaseService, logger)
{ {
this.envelopeOldService = envelopeOldService; this.envelopeOldService = envelopeOldService;
_envRcvService = envelopeReceiverService; _envRcvService = envelopeReceiverService;
@ -37,7 +37,9 @@ namespace EnvelopeGenerator.Web.Controllers
_configuration = configuration; _configuration = configuration;
_urlEncoder = urlEncoder; _urlEncoder = urlEncoder;
_cultures = cultures; _cultures = cultures;
} _mailService = envelopeMailService;
}
[HttpGet("EnvelopeKey/{envelopeReceiverId}")] [HttpGet("EnvelopeKey/{envelopeReceiverId}")]
public async Task<IActionResult> SendAccessCode([FromRoute] string envelopeReceiverId) public async Task<IActionResult> SendAccessCode([FromRoute] string envelopeReceiverId)
@ -57,7 +59,12 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
await _historyService.RecordAsync(er.EnvelopeId, er.Receiver.EmailAddress, Constants.EnvelopeStatus.AccessCodeRequested); await _historyService.RecordAsync(er.EnvelopeId, er.Receiver.EmailAddress, Constants.EnvelopeStatus.AccessCodeRequested);
bool result = database.Services.emailService.SendDocumentAccessCodeReceivedEmail(response.Envelope, response.Receiver); var mailRes = await _mailService.SendAccessCodeAsync(envelopeReceiverDto: er);
if (mailRes.IsFailed)
{
_logger.LogNotice(mailRes);
return this.ViewAccessCodeNotSent();
}
} }
return Redirect($"{envelopeReceiverId}/Locked"); return Redirect($"{envelopeReceiverId}/Locked");

View File

@ -42,5 +42,16 @@ namespace EnvelopeGenerator.Web.Controllers.Test
} }
return NotFound(result); return NotFound(result);
} }
}
[HttpGet("decode")]
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId, int type = 0)
{
return type switch
{
1 => Ok(envelopeReceiverId.GetEnvelopeUuid()),
2 => Ok(envelopeReceiverId.GetReceiverSignature()),
_ => Ok(envelopeReceiverId.DecodeEnvelopeReceiverId()),
};
}
}
} }

View File

@ -0,0 +1,48 @@
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs;
using Microsoft.AspNetCore.Mvc;
using System.Net;
namespace EnvelopeGenerator.Web.Controllers.Test
{
[ApiController]
[Route("api/test/[controller]")]
public class TestEnvelopeMailController : ControllerBase
{
private readonly ILogger<TestEnvelopeMailController> _logger;
private readonly IEnvelopeMailService _mailService;
private readonly IEnvelopeReceiverService _envRcvService;
public TestEnvelopeMailController(ILogger<TestEnvelopeMailController> logger, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverService envelopeReceiverService)
{
_logger = logger;
_mailService = envelopeMailService;
_envRcvService = envelopeReceiverService;
}
[HttpGet]
public async Task<IActionResult> SendAccessCode([FromQuery] string envelopeReceiverId = "ZDlmYjZmYjctNTBhNS00NTcyLWI5NTQtYzJjYmY4N2UwZmZhOjowRDI3MkEwNTdGMjRBMkY3MEZDMzM3QkRBQzA1MjYxRjU3NTI2QzgxQ0IyMUE5NzE1RjA1NTJFQzdFNjIwNjY1")
{
return await _envRcvService.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId: envelopeReceiverId).ThenAsync<EnvelopeReceiverDto, IActionResult>(
SuccessAsync: async er =>
{
var mailRes = await _mailService.SendAccessCodeAsync(envelopeReceiverDto: er);
if (mailRes.IsFailed)
{
_logger.LogNotice(mailRes);
return StatusCode(500, mailRes.Notices);
}
return Ok();
},
Fail: (messages, notices) =>
{
_logger.LogNotice(notices);
return StatusCode(500, notices);
});
}
}
}

View File

@ -178,6 +178,8 @@ try
builder.Services.AddMemoryCache(); builder.Services.AddMemoryCache();
builder.ConfigureBySection<DispatcherConfig>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

View File

@ -60,7 +60,7 @@ namespace EnvelopeGenerator.Web.Services
_logger.LogInformation("Resolved receiver signature to receiverId [{0}]", receiverId); _logger.LogInformation("Resolved receiver signature to receiverId [{0}]", receiverId);
_logger.LogInformation("Loading envelope.."); _logger.LogInformation("Loading envelope..");
Envelope? envelope = envelopeModel.GetByUuid(envelopeUuid); Envelope? envelope = envelopeModel.GetByUuid(envelopeUuid);
if (envelope == null) if (envelope == null)
{ {
@ -96,22 +96,14 @@ namespace EnvelopeGenerator.Web.Services
}).ToList(); }).ToList();
//if documenet_path_dmz is existing in config, replace the path with it //if documenet_path_dmz is existing in config, replace the path with it
var configResult = await _configService.ReadDefaultAsync(); var config = await _configService.ReadDefaultAsync();
if (configResult.IsSuccess && configResult.Data is not null)
{ if (config.DocumentPathDmz is not null && config.DocumentPathDmz != string.Empty)
var config = configResult.Data; foreach (var doc in envelope.Documents)
{
doc.Filepath = doc.Filepath.Replace(config.DocumentPath, config.DocumentPathDmz);
}
if(config.DocumentPathDmz is not null && config.DocumentPathDmz != string.Empty)
foreach(var doc in envelope.Documents)
{
doc.Filepath = doc.Filepath.Replace(config.DocumentPath , config.DocumentPathDmz);
}
}
else
{
_logger.LogError(string.Join(". ", configResult.Messages));
throw new InvalidOperationException(String.Join(". ", configResult.Messages));
}
return new() return new()
{ {

View File

@ -113,5 +113,11 @@
"FIClass": "fi-us" "FIClass": "fi-us"
} }
], ],
"DisableMultiLanguage": false "DisableMultiLanguage": false,
"DispatcherConfig": {
"SendingProfile": 1,
"AddedWho": "DDEnvelopGenerator",
"ReminderTypeId": 202377,
"EmailAttmt1" : ""
}
} }