Endpunkt für die Ablehnung von Umschlägen hinzugefügt.

This commit is contained in:
Developer 02
2024-06-04 16:11:30 +02:00
parent 34b3c46720
commit 7697939d7e
5 changed files with 75 additions and 52 deletions

View File

@@ -1,24 +1,43 @@
using EnvelopeGenerator.Application;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application;
using EnvelopeGenerator.Application.Contracts;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Web.Controllers
{
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class EnvelopeController : BaseController
{
private readonly EnvelopeOldService envelopeService;
private readonly ActionService? actionService;
private readonly UrlEncoder _urlEncoder;
private readonly IEnvelopeHistoryService _histService;
private readonly IReceiverService _receiverService;
private readonly IEnvelopeReceiverService _envRcvService;
public EnvelopeController(DatabaseService database, EnvelopeOldService envelope, ILogger<EnvelopeController> logger, UrlEncoder urlEncoder) : base(database, logger)
public EnvelopeController(DatabaseService database,
EnvelopeOldService envelope,
ILogger<EnvelopeController> logger, UrlEncoder urlEncoder,
IEnvelopeHistoryService envelopeHistoryService,
IReceiverService receiverService,
IEnvelopeReceiverService envelopeReceiverService) : base(database, logger)
{
envelopeService = envelope;
actionService = database?.Services?.actionService;
_urlEncoder = urlEncoder;
_histService = envelopeHistoryService;
_receiverService = receiverService;
_envRcvService = envelopeReceiverService;
}
[NonAction]
@@ -49,17 +68,17 @@ namespace EnvelopeGenerator.Web.Controllers
}
[Authorize]
[HttpPost("api/envelope/{envelopeKey}")]
[HttpPost("{envelopeKey}")]
public async Task<IActionResult> Update(string envelopeKey, int index)
{
try
{
envelopeKey = _urlEncoder.Encode(envelopeKey);
var authSignature = this.GetAuthenticatedReceiverSignature();
var authSignature = this.GetAuthReceiverSignature();
if (authSignature != envelopeKey.GetReceiverSignature())
return Forbid();
return Unauthorized();
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
@@ -93,5 +112,45 @@ namespace EnvelopeGenerator.Web.Controllers
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[Authorize]
[HttpPost("reject")]
public async Task<IActionResult> Reject()
{
try
{
var signature = this.GetAuthReceiverSignature();
var uuid = this.GetAuthEnvelopeUuid();
var mail = this.GetAuthReceiverMail();
if(uuid is null || signature is null || mail is null)
{
_logger.LogEnvelopeError(uuid: uuid, signature: signature,
message: @$"Unauthorized POST request in api\envelope\reject. One of claims, Envelope, signature or mail ({mail}) is null.");
return Unauthorized();
}
var envRcvRes = await _envRcvService.ReadByUuidSignatureAsync(uuid: uuid, signature: signature);
if (envRcvRes.IsFailed)
{
_logger.LogNotice(envRcvRes.Notices);
return Unauthorized();
}
return await _histService.RecordAsync(envRcvRes.Data.EnvelopeId, userReference: mail, EnvelopeStatus.DocumentRejected).ThenAsync(
Success: id => NoContent(),
Fail: IActionResult (mssg, ntc) =>
{
_logger.LogEnvelopeError(uuid: uuid, signature: signature, message: "Unexpected error happend in api/envelope/reject");
_logger.LogNotice(ntc);
return this.ViewInnerServiceError();
});
}
catch (Exception e)
{
_logger.LogError(e, "{Message}", e.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}
}