feat(EnvelopeReceiverReadOnly): Modelldaten und Dokument im Endpunkt sind so eingestellt, dass sie als Bytes geladen werden.

This commit is contained in:
Developer 02 2024-10-05 02:04:57 +02:00
parent bc6955055a
commit efa9160c04
4 changed files with 78 additions and 24 deletions

View File

@ -66,21 +66,25 @@ namespace EnvelopeGenerator.Extensions
public static bool TryDecode(this string encodedKey, out string[] decodedKeys) public static bool TryDecode(this string encodedKey, out string[] decodedKeys)
{ {
if (!encodedKey.IsBase64String()) try
{ {
decodedKeys = Array.Empty<string>(); byte[] bytes = Convert.FromBase64String(encodedKey);
return false; string decodedString = Encoding.UTF8.GetString(bytes);
decodedKeys = decodedString.Split(new string[] { "::" }, StringSplitOptions.None);
return true;
} }
byte[] bytes = Convert.FromBase64String(encodedKey); catch(ArgumentNullException) { }
string decodedString = Encoding.UTF8.GetString(bytes); catch (FormatException) { }
decodedKeys = decodedString.Split(new string[] { "::" }, StringSplitOptions.None); catch(ArgumentException) { }
return true;
decodedKeys = Array.Empty<string>();
return false;
} }
public static EncodeType GetEncodeType(this string[] decodedKeys) => decoded.Length switch public static EncodeType GetEncodeType(this string[] decodedKeys) => decodedKeys.Length switch
{ {
2 => EncodeType.EnvelopeReceiver, 2 => EncodeType.EnvelopeReceiver,
3 => long.TryParse(decoded[1], out var _) ? EncodeType.EnvelopeReceiverReadOnly : EncodeType.Undefined, 3 => long.TryParse(decodedKeys[1], out var _) ? EncodeType.EnvelopeReceiverReadOnly : EncodeType.Undefined,
_ => EncodeType.Undefined, _ => EncodeType.Undefined,
}; };

View File

@ -28,6 +28,24 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
return await IncludeEnvelope(erros); return await IncludeEnvelope(erros);
} }
public override async Task<EnvelopeReceiverReadOnly?> ReadByIdAsync(long id)
{
var erro = await _dbSet.AsNoTracking()
.Include(erro => erro.Receiver)
.Where(erro => erro.Id == id)
.FirstOrDefaultAsync();
return await IncludeEnvelope(erro);
}
//TODO: Use IQueryable.Include instead of this when ID type is clarified.
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
private async Task<EnvelopeReceiverReadOnly> IncludeEnvelope(EnvelopeReceiverReadOnly erro)
{
erro.Envelope = await _envRepo.ReadByIdAsync((int)erro.EnvelopeId);
return erro;
}
//TODO: Use IQueryable.Include instead of this when ID type is clarified. //TODO: Use IQueryable.Include instead of this when ID type is clarified.
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")] [Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
private async Task<IEnumerable<EnvelopeReceiverReadOnly>> IncludeEnvelope(params EnvelopeReceiverReadOnly[] erros) private async Task<IEnumerable<EnvelopeReceiverReadOnly>> IncludeEnvelope(params EnvelopeReceiverReadOnly[] erros)

View File

@ -16,6 +16,7 @@ using EnvelopeGenerator.Web.Models;
using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Application.Resources;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using static EnvelopeGenerator.Common.Constants; using static EnvelopeGenerator.Common.Constants;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Web.Controllers namespace EnvelopeGenerator.Web.Controllers
{ {
@ -51,7 +52,7 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
try try
{ {
envelopeReceiverId = _urlEncoder.Encode(envelopeReceiverId); //envelopeReceiverId = _urlEncoder.Encode(envelopeReceiverId);
if (!envelopeReceiverId.TryDecode(out var decoded)) if (!envelopeReceiverId.TryDecode(out var decoded))
{ {
@ -198,7 +199,7 @@ namespace EnvelopeGenerator.Web.Controllers
{ {
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: "No document was found."); _logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: "No document was found.");
return this.ViewDocumentNotFound(); return this.ViewDocumentNotFound();
} }
var claims = new List<Claim> { var claims = new List<Claim> {
new(ClaimTypes.NameIdentifier, uuid), new(ClaimTypes.NameIdentifier, uuid),
@ -304,13 +305,12 @@ namespace EnvelopeGenerator.Web.Controllers
} }
} }
[Authorize] [HttpGet("EnvelopeKey/{readOnlyKey}/ReadOnly")]
[HttpGet("EnvelopeKey/{readOnlyId}/ReadOnly")] public async Task<IActionResult> EnvelopeReceiverReadOnly([FromRoute] string readOnlyKey)
public async Task<IActionResult> EnvelopeReceiverReadOnly(string readOnlyKey)
{ {
try try
{ {
readOnlyKey = _urlEncoder.Encode(readOnlyKey); //readOnlyKey = _urlEncoder.Encode(readOnlyKey);
// check if the readOnlyId is valid // check if the readOnlyId is valid
if (!readOnlyKey.TryDecode(out var decodedKeys) || decodedKeys.GetEncodeType() != EncodeType.EnvelopeReceiverReadOnly) if (!readOnlyKey.TryDecode(out var decodedKeys) || decodedKeys.GetEncodeType() != EncodeType.EnvelopeReceiverReadOnly)
@ -320,17 +320,43 @@ namespace EnvelopeGenerator.Web.Controllers
} }
var readOnlyId = decodedKeys.ParseReadOnlyId(); var readOnlyId = decodedKeys.ParseReadOnlyId();
return await _readOnlyService.ReadByIdAsync(readOnlyId).ThenAsync( var erro_res = await _readOnlyService.ReadByIdAsync(readOnlyId);
Success: erro => if (erro_res.IsFailed)
{
_logger.LogNotice(erro_res.Notices);
return this.ViewInnerServiceError();
}
var erro = erro_res.Data;
return await _envRcvService.ReadByUuidSignatureAsync(uuid: erro.Envelope!.Uuid, erro.Receiver!.Signature).ThenAsync(
SuccessAsync: async er =>
{
var envelopeKey = (er.Envelope!.Uuid, er.Receiver!.Signature).EncodeEnvelopeReceiverId();
EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeKey);
if (response.Envelope.Documents.Count > 0)
{ {
ViewData["model"] = erro; var document = await envelopeOldService.GetDocument(response.Envelope.Documents[0].Id, envelopeKey);
return View("ShowEnvelope"); byte[] bytes = await envelopeOldService.GetDocumentContents(document);
}, ViewData["EnvelopeKey"] = envelopeKey;
Fail: IActionResult (msg, ntc) => ViewData["DocumentBytes"] = bytes;
ViewData["IsReadOnly"] = true;
ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"];
return View("ShowEnvelope", er);
}
else
{ {
_logger.LogNotice(ntc); _logger.LogEnvelopeError(envelopeReceiverId: envelopeKey, message: "No document was found.");
return this.ViewInnerServiceError(); return this.ViewDocumentNotFound();
}); }
},
Fail: (messages, notices) =>
{
_logger.LogNotice(notices);
return this.ViewEnvelopeNotFound();
});
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,6 +1,7 @@
using DigitalData.Core.DTO; using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Extensions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -50,5 +51,10 @@ namespace EnvelopeGenerator.Web.Controllers
return StatusCode(StatusCodes.Status500InternalServerError); return StatusCode(StatusCodes.Status500InternalServerError);
}); });
} }
[HttpGet("key/{readOnlyId}")]
public IActionResult CreateLink(long readOnlyId) => Ok(
Request.Headers["Origin"].ToString() + "/EnvelopeKey/" + readOnlyId.EncodeEnvelopeReceiverId());
} }
} }