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 class ControllerBaseExtensions
|
||||||
{
|
{
|
||||||
public static (string EnvelopeUuid, string ReceiverSignature)? GetAuthenticatedEnvelopeDetails(this ControllerBase controller)
|
public static string? GetClaimValue(this ControllerBase controller, string claimType) => controller.User.FindFirstValue(claimType);
|
||||||
{
|
|
||||||
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? GetAuthenticatedEnvelopeUuid(this ControllerBase controller)
|
public static string? GetAuthEnvelopeUuid(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||||
{
|
|
||||||
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? GetAuthenticatedReceiverSignature(this ControllerBase controller)
|
public static string? GetAuthReceiverSignature(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Hash);
|
||||||
{
|
|
||||||
if (controller?.User?.Identity?.IsAuthenticated ?? false)
|
public static string? GetAuthReceiverName(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Name);
|
||||||
{
|
|
||||||
var receiverSignature = controller.User.FindFirst(ClaimTypes.Hash)?.Value;
|
public static string? GetAuthReceiverMail(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Email);
|
||||||
if (!string.IsNullOrEmpty(receiverSignature))
|
|
||||||
return receiverSignature;
|
public static string? GetAuthEnvelopeTitle(this ControllerBase controller) => controller.User.FindFirstValue(EnvelopeClaimTypes.Title);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: integrate localizer for ready-to-use views
|
//TODO: integrate localizer for ready-to-use views
|
||||||
public static ViewResult ViewError(this Controller controller, ErrorViewModel errorViewModel) => controller.View("_Error", errorViewModel);
|
public static ViewResult ViewError(this Controller controller, ErrorViewModel errorViewModel) => controller.View("_Error", errorViewModel);
|
||||||
|
|||||||
@ -52,7 +52,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var authSignature = this.GetAuthenticatedReceiverSignature();
|
var authSignature = this.GetAuthReceiverSignature();
|
||||||
|
|
||||||
if (authSignature != envelopeKey.GetReceiverSignature())
|
if (authSignature != envelopeKey.GetReceiverSignature())
|
||||||
return Forbid();
|
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.Common;
|
||||||
using EnvelopeGenerator.Web.Services;
|
using EnvelopeGenerator.Web.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
|
||||||
|
using static EnvelopeGenerator.Common.Constants;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Web.Controllers
|
namespace EnvelopeGenerator.Web.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
public class EnvelopeController : BaseController
|
public class EnvelopeController : BaseController
|
||||||
{
|
{
|
||||||
private readonly EnvelopeOldService envelopeService;
|
private readonly EnvelopeOldService envelopeService;
|
||||||
private readonly ActionService? actionService;
|
private readonly ActionService? actionService;
|
||||||
private readonly UrlEncoder _urlEncoder;
|
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;
|
envelopeService = envelope;
|
||||||
actionService = database?.Services?.actionService;
|
actionService = database?.Services?.actionService;
|
||||||
_urlEncoder = urlEncoder;
|
_urlEncoder = urlEncoder;
|
||||||
|
_histService = envelopeHistoryService;
|
||||||
|
_receiverService = receiverService;
|
||||||
|
_envRcvService = envelopeReceiverService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[NonAction]
|
[NonAction]
|
||||||
@ -49,17 +68,17 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("api/envelope/{envelopeKey}")]
|
[HttpPost("{envelopeKey}")]
|
||||||
public async Task<IActionResult> Update(string envelopeKey, int index)
|
public async Task<IActionResult> Update(string envelopeKey, int index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
envelopeKey = _urlEncoder.Encode(envelopeKey);
|
envelopeKey = _urlEncoder.Encode(envelopeKey);
|
||||||
|
|
||||||
var authSignature = this.GetAuthenticatedReceiverSignature();
|
var authSignature = this.GetAuthReceiverSignature();
|
||||||
|
|
||||||
if (authSignature != envelopeKey.GetReceiverSignature())
|
if (authSignature != envelopeKey.GetReceiverSignature())
|
||||||
return Forbid();
|
return Unauthorized();
|
||||||
|
|
||||||
// Validate Envelope Key and load envelope
|
// Validate Envelope Key and load envelope
|
||||||
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
|
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
|
||||||
@ -93,5 +112,45 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
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<IConfigService, ConfigService>();
|
||||||
builder.Services.AddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
|
builder.Services.AddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
|
||||||
builder.Services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
|
builder.Services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
|
||||||
|
builder.Services.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
|
||||||
builder.Services.AddScoped<IDocumentStatusService, DocumentStatusService>();
|
builder.Services.AddScoped<IDocumentStatusService, DocumentStatusService>();
|
||||||
builder.Services.AddScoped<IEmailTemplateService, EmailTemplateService>();
|
builder.Services.AddScoped<IEmailTemplateService, EmailTemplateService>();
|
||||||
builder.Services.AddScoped<IEnvelopeService, EnvelopeService>();
|
builder.Services.AddScoped<IEnvelopeService, EnvelopeService>();
|
||||||
@ -104,7 +105,6 @@ try
|
|||||||
builder.Services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
|
builder.Services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
|
||||||
builder.Services.AddScoped<IReceiverService, ReceiverService>();
|
builder.Services.AddScoped<IReceiverService, ReceiverService>();
|
||||||
builder.Services.AddScoped<IUserReceiverService, UserReceiverService>();
|
builder.Services.AddScoped<IUserReceiverService, UserReceiverService>();
|
||||||
builder.Services.AddHistoryService();
|
|
||||||
|
|
||||||
//Auto mapping profiles
|
//Auto mapping profiles
|
||||||
builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user