Introduced a new feature for submitting signatures, including backend and frontend changes. Added `SignatureSubmitDto` and `SubmitAsync` in `SignatureService` to handle signature data submission. Implemented a new `Submit` endpoint in `SignatureController` to validate and process signature payloads. Updated pipeline behaviors to include `SaveSignatureBehavior` and adjusted the execution order. Enhanced query logic in `EnvelopeReceiverResolutionBehavior` and `SaveSignatureBehavior` to align with the updated data model. Refactored `EGDbContext` to improve trigger handling and logging. Updated `ReceiverSignedPage.razor` to integrate `SignatureService` and handle submission errors gracefully. Adjusted application URLs in `launchSettings.json` and added new database triggers in `appsettings.json`.
105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using EnvelopeGenerator.Server.Extensions;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
|
using EnvelopeGenerator.Application.Documents.Queries;
|
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
|
using EnvelopeGenerator.Application.Histories.Queries;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EnvelopeGenerator.Server.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class SignatureController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
private readonly ILogger<SignatureController> _logger;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="SignatureController"/>.
|
|
/// </summary>
|
|
public SignatureController(IMediator mediator, ILogger<SignatureController> logger)
|
|
{
|
|
_mediator = mediator;
|
|
_logger = logger;
|
|
}
|
|
|
|
//TODO: update to use signature query
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeKey"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[HttpGet("{envelopeKey}")]
|
|
public async Task<IActionResult> Get(string envelopeKey, CancellationToken cancel)
|
|
{
|
|
int envelopeId = User.EnvelopeId();
|
|
|
|
int receiverId = User.ReceiverId();
|
|
|
|
var doc = await _mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
|
|
|
if (doc.Elements is not IEnumerable<DocReceiverElementDto> docSignatures)
|
|
return NotFound("Document is empty.");
|
|
|
|
var rcvSignatures = docSignatures.Where(s => s.ReceiverId == receiverId).ToList();
|
|
|
|
if (rcvSignatures is null)
|
|
return NotFound("No signatures found for the current receiver.");
|
|
else
|
|
return Ok(rcvSignatures);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finalizes the receiver signing flow and persists signature data to TBSIG_DOCUMENT_RECEIVER_ELEMENT.
|
|
/// Also triggers status/history/mail side effects through SigningCommand pipeline.
|
|
/// </summary>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[HttpPost("submit/{envelopeKey}")]
|
|
public async Task<IActionResult> Submit(
|
|
[FromRoute] string envelopeKey,
|
|
[FromBody] IEnumerable<Signature>? signatures,
|
|
CancellationToken cancel)
|
|
{
|
|
if (signatures is null)
|
|
return BadRequest("Signature payload is required.");
|
|
|
|
var uuid = User.EnvelopeUuid();
|
|
var receiverSignature = User.ReceiverSignature();
|
|
|
|
if (await _mediator.IsSignedAsync(uuid, receiverSignature, cancel))
|
|
return Problem(statusCode: StatusCodes.Status409Conflict);
|
|
|
|
if (await _mediator.AnyHistoryAsync(uuid, new[] { EnvelopeStatus.EnvelopeRejected, EnvelopeStatus.DocumentRejected }, cancel))
|
|
return Problem(statusCode: StatusCodes.Status423Locked);
|
|
|
|
try
|
|
{
|
|
await _mediator.Send(new SigningCommand
|
|
{
|
|
Envelope = new() { Uuid = uuid },
|
|
Receiver = new() { Signature = receiverSignature },
|
|
ReceiverAppType = ReceiverAppType.ReceiverUI,
|
|
Signatures = signatures.ToList()
|
|
}, cancel);
|
|
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to submit signatures for envelope {EnvelopeKey}", envelopeKey);
|
|
throw;
|
|
}
|
|
}
|
|
}
|