Signaturprüfung zur Filterung der Umschlagempfänger hinzugefügt

This commit is contained in:
Developer 02 2024-04-08 16:22:17 +02:00
parent db83eb90ee
commit 2512de0f26
9 changed files with 38 additions and 25 deletions

View File

@ -9,6 +9,6 @@ namespace EnvelopeGenerator.Application.Contracts
{ {
Task<IServiceResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool receivers = false, bool history = false, bool documentReceiverElement = false); Task<IServiceResult<IEnumerable<EnvelopeDto>>> ReadAllWithAsync(bool documents = false, bool receivers = false, bool history = false, bool documentReceiverElement = false);
Task<IServiceResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false); Task<IServiceResult<EnvelopeDto>> ReadByUuidAsync(string uuid, string? signature = null, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false);
} }
} }

View File

@ -1,4 +1,6 @@
namespace EnvelopeGenerator.Application.DTOs using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.DTOs
{ {
public record EnvelopeReceiverDto( public record EnvelopeReceiverDto(
int EnvelopeId, int EnvelopeId,
@ -9,5 +11,7 @@
string CompanyName, string CompanyName,
string PrivateMessage, string PrivateMessage,
DateTime AddedWhen, DateTime AddedWhen,
DateTime? ChangedWhen); DateTime? ChangedWhen,
Envelope? Envelope,
Receiver? Receiver);
} }

View File

@ -23,9 +23,9 @@ namespace EnvelopeGenerator.Application.Services
return Successful(readDto); return Successful(readDto);
} }
public async Task<IServiceResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false) public async Task<IServiceResult<EnvelopeDto>> ReadByUuidAsync(string uuid, string? signature = null, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false)
{ {
var envelope = await _repository.ReadByUuidAsync(uuid: uuid, withDocuments: withDocuments, withReceivers: withReceivers, withHistory: withHistory, withDocumentReceiverElement: withDocumentReceiverElement); var envelope = await _repository.ReadByUuidAsync(uuid: uuid, signature: signature, withDocuments: withDocuments, withReceivers: withReceivers, withHistory: withHistory, withDocumentReceiverElement: withDocumentReceiverElement);
if (envelope is null) if (envelope is null)
return Failed<EnvelopeDto>(); return Failed<EnvelopeDto>();

View File

@ -7,6 +7,6 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
{ {
Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool receivers = false, bool history = false, bool documentReceiverElement = true); Task<IEnumerable<Envelope>> ReadAllWithAsync(bool documents = false, bool receivers = false, bool history = false, bool documentReceiverElement = true);
Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false); Task<Envelope?> ReadByUuidAsync(string uuid, string? signature = null, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false);
} }
} }

View File

@ -31,10 +31,13 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
return await query.ToListAsync(); return await query.ToListAsync();
} }
public async Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false) public async Task<Envelope?> ReadByUuidAsync(string uuid, string? signature = null, bool withDocuments = false, bool withReceivers = false, bool withHistory = false, bool withDocumentReceiverElement = false)
{ {
var query = _dbSet.Where(e => e.Uuid == uuid); var query = _dbSet.Where(e => e.Uuid == uuid);
if (signature is not null)
query = query.Where(e => e.Receivers != null && e.Receivers.Any(er => er.Receiver != null && er.Receiver.Signature == signature));
if (withDocuments) if (withDocuments)
if (withDocumentReceiverElement) if (withDocumentReceiverElement)
query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements); query = query.Include(e => e.Documents!).ThenInclude(d => d.Elements);
@ -42,7 +45,7 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
query = query.Include(e => e.Documents); query = query.Include(e => e.Documents);
if (withReceivers) if (withReceivers)
query = query.Include(e => e.Receivers); query = query.Include(e => e.Receivers!).ThenInclude(er => er.Receiver);
if (withHistory) if (withHistory)
query = query.Include(e => e.History); query = query.Include(e => e.History);

View File

@ -20,7 +20,7 @@ namespace EnvelopeGenerator.Web.Controllers
} }
[HttpGet("api/envelope/{envelopeKey}")] [HttpGet("api/envelope/{envelopeKey}")]
public async Task<IActionResult> Get([FromRoute] string envelopeKey, [FromBody] string accessCode) public async Task<IActionResult> Get([FromRoute] string envelopeKey)
{ {
try try
{ {

View File

@ -15,11 +15,13 @@ namespace EnvelopeGenerator.Web.Controllers
private readonly EnvelopeOldService envelopeOldService; private readonly EnvelopeOldService envelopeOldService;
private readonly IConfiguration _config; private readonly IConfiguration _config;
private readonly IEnvelopeReceiverService _envRcvService; private readonly IEnvelopeReceiverService _envRcvService;
private readonly IEnvelopeService _envelopeService;
public HomeController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IConfiguration configuration, IEnvelopeReceiverService envelopeReceiverService) : base(databaseService, logger) public HomeController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IConfiguration configuration, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeService envelopeService) : base(databaseService, logger)
{ {
this.envelopeOldService = envelopeOldService; this.envelopeOldService = envelopeOldService;
_envRcvService = envelopeReceiverService; _envRcvService = envelopeReceiverService;
_envelopeService = envelopeService;
_config = configuration; _config = configuration;
} }
@ -69,24 +71,20 @@ namespace EnvelopeGenerator.Web.Controllers
public IActionResult ShowEnvelope([FromRoute] string envelopeReceiverId) => Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked"); public IActionResult ShowEnvelope([FromRoute] string envelopeReceiverId) => Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
[HttpPost("/EnvelopeKey/{envelopeReceiverId}/Locked")] [HttpPost("/EnvelopeKey/{envelopeReceiverId}/Locked")]
public async Task<IActionResult> ShowEnvelopePost([FromRoute] string envelopeReceiverId, [FromForm] string access_code) public async Task<IActionResult> ShowEnvelope([FromRoute] string envelopeReceiverId, [FromForm] string access_code)
{ {
var uuid = envelopeReceiverId.DecodeEnvelopeReceiverId().EnvelopeUuid; var decodedId = envelopeReceiverId.DecodeEnvelopeReceiverId();
var verification = await _envRcvService.VerifyAccessCode(uuid, access_code);
var verification = await _envRcvService.VerifyAccessCode(decodedId.EnvelopeUuid, access_code);
EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeReceiverId); EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeReceiverId);
string accessCode = response.Receiver.AccessCode;
if (string.IsNullOrEmpty(access_code)) if (verification.IsSuccess)
{
return Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
}
if (accessCode == access_code)
{ {
var envelope = await _envelopeService.ReadByUuidAsync(decodedId.EnvelopeUuid, decodedId.ReceiverSignature, true, true, true);
database.Services.actionService.EnterCorrectAccessCode(response.Envelope, response.Receiver); //for history database.Services.actionService.EnterCorrectAccessCode(response.Envelope, response.Receiver); //for history
ViewData["EnvelopeKey"] = envelopeReceiverId; ViewData["EnvelopeKey"] = envelopeReceiverId;
return View("ShowEnvelope"); ViewData["EnveResponse"] = response;
return View("ShowEnvelope", envelope);
} }
else else
{ {

View File

@ -1,6 +1,7 @@
using DigitalData.Core.API; using DigitalData.Core.API;
using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Application.Services;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Infrastructure.Contracts; using EnvelopeGenerator.Infrastructure.Contracts;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -24,9 +25,12 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
if(envelopeKey is not null) if(envelopeKey is not null)
{ {
Tuple<string, string> decode = Common.Helpers.DecodeEnvelopeReceiverId(envelopeKey); var decoded = envelopeKey.DecodeEnvelopeReceiverId();
var envelopeUuid = decode.Item1;
var envlopeServiceResult = await _service.ReadByUuidAsync(envelopeUuid, withDocuments: true, withReceivers: true, withHistory: true); var envlopeServiceResult = await _service.ReadByUuidAsync(
uuid: decoded.EnvelopeUuid,
signature: decoded.ReceiverSignature,
withDocuments: withDocuments, withReceivers: withReceivers, withHistory: withHistory);
if (envlopeServiceResult.IsSuccess) if (envlopeServiceResult.IsSuccess)
{ {

View File

@ -74,7 +74,7 @@
* Creates a GET HTTP request to `url` * Creates a GET HTTP request to `url`
* @param {any} url * @param {any} url
*/ */
getRequest(url) { getRequest(url, body) {
const token = this.getCSRFToken() const token = this.getCSRFToken()
const options = { const options = {
credentials: 'include', credentials: 'include',
@ -84,6 +84,10 @@
} }
} }
if (body !== undefined) {
options.body = JSON.stringify(body);
}
return fetch(url, options) return fetch(url, options)
} }