Endpunkt für die Ablehnung von Umschlägen hinzugefügt.
This commit is contained in:
parent
34b3c46720
commit
7697939d7e
@ -1,14 +0,0 @@
|
||||
using EnvelopeGenerator.Application.Contracts;
|
||||
using EnvelopeGenerator.Application.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Application
|
||||
{
|
||||
public static class DIExtensions
|
||||
{
|
||||
public static IServiceCollection AddHistoryService(this IServiceCollection services, Func<EnvelopeStatus, ReferenceType>? classifier = null) => services
|
||||
.AddSingleton(classifier ?? EnvelopeHistoryService.DefaultClassifier)
|
||||
.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
|
||||
}
|
||||
}
|
||||
@ -6,39 +6,17 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
public static class ControllerBaseExtensions
|
||||
{
|
||||
public static (string EnvelopeUuid, string ReceiverSignature)? GetAuthenticatedEnvelopeDetails(this ControllerBase controller)
|
||||
{
|
||||
if(controller?.User?.Identity?.IsAuthenticated ?? false)
|
||||
{
|
||||
var envelopeUuid = controller.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
var receiverSignature = controller.User.FindFirst(ClaimTypes.Hash)?.Value;
|
||||
if (!string.IsNullOrEmpty(envelopeUuid) && !string.IsNullOrEmpty(receiverSignature))
|
||||
return (EnvelopeUuid: envelopeUuid, ReceiverSignature: receiverSignature);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string? GetClaimValue(this ControllerBase controller, string claimType) => controller.User.FindFirstValue(claimType);
|
||||
|
||||
public static string? GetAuthenticatedEnvelopeUuid(this ControllerBase controller)
|
||||
{
|
||||
if (controller?.User?.Identity?.IsAuthenticated ?? false)
|
||||
{
|
||||
var envelopeUuid = controller.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (!string.IsNullOrEmpty(envelopeUuid))
|
||||
return envelopeUuid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string? GetAuthEnvelopeUuid(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
public static string? GetAuthenticatedReceiverSignature(this ControllerBase controller)
|
||||
{
|
||||
if (controller?.User?.Identity?.IsAuthenticated ?? false)
|
||||
{
|
||||
var receiverSignature = controller.User.FindFirst(ClaimTypes.Hash)?.Value;
|
||||
if (!string.IsNullOrEmpty(receiverSignature))
|
||||
return receiverSignature;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string? GetAuthReceiverSignature(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Hash);
|
||||
|
||||
public static string? GetAuthReceiverName(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Name);
|
||||
|
||||
public static string? GetAuthReceiverMail(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Email);
|
||||
|
||||
public static string? GetAuthEnvelopeTitle(this ControllerBase controller) => controller.User.FindFirstValue(EnvelopeClaimTypes.Title);
|
||||
|
||||
//TODO: integrate localizer for ready-to-use views
|
||||
public static ViewResult ViewError(this Controller controller, ErrorViewModel errorViewModel) => controller.View("_Error", errorViewModel);
|
||||
|
||||
@ -52,7 +52,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var authSignature = this.GetAuthenticatedReceiverSignature();
|
||||
var authSignature = this.GetAuthReceiverSignature();
|
||||
|
||||
if (authSignature != envelopeKey.GetReceiverSignature())
|
||||
return Forbid();
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,6 +95,7 @@ try
|
||||
builder.Services.AddScoped<IConfigService, ConfigService>();
|
||||
builder.Services.AddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
|
||||
builder.Services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
|
||||
builder.Services.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
|
||||
builder.Services.AddScoped<IDocumentStatusService, DocumentStatusService>();
|
||||
builder.Services.AddScoped<IEmailTemplateService, EmailTemplateService>();
|
||||
builder.Services.AddScoped<IEnvelopeService, EnvelopeService>();
|
||||
@ -104,7 +105,6 @@ try
|
||||
builder.Services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
|
||||
builder.Services.AddScoped<IReceiverService, ReceiverService>();
|
||||
builder.Services.AddScoped<IUserReceiverService, UserReceiverService>();
|
||||
builder.Services.AddHistoryService();
|
||||
|
||||
//Auto mapping profiles
|
||||
builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user