Renamed namespaces and related identifiers from EnvelopeGenerator.WebUI to EnvelopeGenerator.Server across the project. This change affects data models, services, controllers, and configuration files to ensure consistency with the new architecture. Updated @using directives in Razor components and other files to reflect the new namespace structure. Adjusted project references in EnvelopeGenerator.Server.csproj to point to the new EnvelopeGenerator.Server.Client project. Modified middleware and logging configurations to use the new EnvelopeGenerator.Server namespace, including changes in Program.cs and appsettings.json. Updated resource and file references to use the new EnvelopeGenerator.Server path, ensuring correct resource loading. Adjusted configuration options in Program.cs to use the new namespace for options classes, such as ApiOptions and PdfViewerOptions. Updated authentication scheme names and related constants to align with the new namespace structure. Revised comments and documentation to reflect the new namespace, ensuring clarity and consistency in the codebase.
133 lines
5.2 KiB
C#
133 lines
5.2 KiB
C#
using DigitalData.Core.Abstraction.Application.DTO;
|
|
using DigitalData.Core.Exceptions;
|
|
using EnvelopeGenerator.Server.Extensions;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
|
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
|
|
using EnvelopeGenerator.Application.Common.Notifications.RemoveSignature;
|
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
|
using EnvelopeGenerator.Application.Histories.Queries;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EnvelopeGenerator.Server.Controllers;
|
|
|
|
/// <summary>
|
|
/// Manages annotations and signature lifecycle for envelopes.
|
|
/// </summary>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class AnnotationController : ControllerBase
|
|
{
|
|
[Obsolete("Use MediatR")]
|
|
private readonly IEnvelopeHistoryService _historyService;
|
|
|
|
[Obsolete("Use MediatR")]
|
|
private readonly IEnvelopeReceiverService _envelopeReceiverService;
|
|
|
|
private readonly IMediator _mediator;
|
|
|
|
private readonly ILogger<AnnotationController> _logger;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="AnnotationController"/>.
|
|
/// </summary>
|
|
[Obsolete("Use MediatR")]
|
|
public AnnotationController(
|
|
ILogger<AnnotationController> logger,
|
|
IEnvelopeHistoryService envelopeHistoryService,
|
|
IEnvelopeReceiverService envelopeReceiverService,
|
|
IMediator mediator)
|
|
{
|
|
_historyService = envelopeHistoryService;
|
|
_envelopeReceiverService = envelopeReceiverService;
|
|
_mediator = mediator;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates or updates annotations for the authenticated envelope receiver.
|
|
/// </summary>
|
|
/// <param name="psPdfKitAnnotation">Annotation payload.</param>
|
|
/// <param name="cancel">Cancellation token.</param>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[HttpPost]
|
|
[Obsolete("PSPDF Kit will no longer be used.")]
|
|
public async Task<IActionResult> CreateOrUpdate([FromBody] PsPdfKitAnnotation? psPdfKitAnnotation = null, CancellationToken cancel = default)
|
|
{
|
|
var signature = User.ReceiverSignature();
|
|
var uuid = User.EnvelopeUuid();
|
|
|
|
var envelopeReceiver = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel).ThrowIfNull(Exceptions.NotFound);
|
|
|
|
if (!envelopeReceiver.Envelope!.ReadOnly && psPdfKitAnnotation is null)
|
|
return BadRequest();
|
|
|
|
if (await _mediator.IsSignedAsync(uuid, signature, cancel))
|
|
return Problem(statusCode: StatusCodes.Status409Conflict);
|
|
else if (await _mediator.AnyHistoryAsync(uuid, new[] { EnvelopeStatus.EnvelopeRejected, EnvelopeStatus.DocumentRejected }, cancel))
|
|
return Problem(statusCode: StatusCodes.Status423Locked);
|
|
|
|
var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
|
|
var docSignedNotification = envelopeReceiverDto is not null
|
|
? new DocSignedNotification { EnvelopeReceiver = envelopeReceiverDto, PsPdfKitAnnotation = psPdfKitAnnotation }
|
|
: throw new NotFoundException("Envelope receiver is not found.");
|
|
|
|
try
|
|
{
|
|
await _mediator.Publish(docSignedNotification, cancel);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await _mediator.Publish(new RemoveSignatureNotification()
|
|
{
|
|
EnvelopeId = docSignedNotification.EnvelopeReceiver.EnvelopeId,
|
|
ReceiverId = docSignedNotification.EnvelopeReceiver.ReceiverId
|
|
}, cancel);
|
|
throw;
|
|
}
|
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rejects the document for the current receiver.
|
|
/// </summary>
|
|
/// <param name="reason">Optional rejection reason.</param>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[HttpPost("reject")]
|
|
[Obsolete("Use MediatR")]
|
|
public async Task<IActionResult> Reject([FromBody] string? reason = null)
|
|
{
|
|
var signature = User.ReceiverSignature();
|
|
var uuid = User.EnvelopeUuid();
|
|
var mail = User.ReceiverMail();
|
|
|
|
var envRcvRes = await _envelopeReceiverService.ReadByUuidSignatureAsync(uuid: uuid, signature: signature);
|
|
|
|
if (envRcvRes.IsFailed)
|
|
{
|
|
_logger.LogNotice(envRcvRes.Notices);
|
|
return Unauthorized("you are not authorized");
|
|
}
|
|
|
|
var histRes = await _historyService.RecordAsync(envRcvRes.Data.EnvelopeId, userReference: mail, EnvelopeStatus.DocumentRejected, comment: reason);
|
|
if (histRes.IsSuccess)
|
|
{
|
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
return NoContent();
|
|
}
|
|
|
|
_logger.LogEnvelopeError(uuid: uuid, signature: signature, message: "Unexpected error happened in api/envelope/reject");
|
|
_logger.LogNotice(histRes.Notices);
|
|
return StatusCode(500, histRes.Messages);
|
|
}
|
|
}
|