feat(EnvelopeReceiverReadOnly): Modelldaten und Dokument im Endpunkt sind so eingestellt, dass sie als Bytes geladen werden.
This commit is contained in:
parent
bc6955055a
commit
efa9160c04
@ -66,21 +66,25 @@ namespace EnvelopeGenerator.Extensions
|
||||
|
||||
public static bool TryDecode(this string encodedKey, out string[] decodedKeys)
|
||||
{
|
||||
if (!encodedKey.IsBase64String())
|
||||
try
|
||||
{
|
||||
decodedKeys = Array.Empty<string>();
|
||||
return false;
|
||||
byte[] bytes = Convert.FromBase64String(encodedKey);
|
||||
string decodedString = Encoding.UTF8.GetString(bytes);
|
||||
decodedKeys = decodedString.Split(new string[] { "::" }, StringSplitOptions.None);
|
||||
return true;
|
||||
}
|
||||
byte[] bytes = Convert.FromBase64String(encodedKey);
|
||||
string decodedString = Encoding.UTF8.GetString(bytes);
|
||||
decodedKeys = decodedString.Split(new string[] { "::" }, StringSplitOptions.None);
|
||||
return true;
|
||||
catch(ArgumentNullException) { }
|
||||
catch (FormatException) { }
|
||||
catch(ArgumentException) { }
|
||||
|
||||
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,
|
||||
3 => long.TryParse(decoded[1], out var _) ? EncodeType.EnvelopeReceiverReadOnly : EncodeType.Undefined,
|
||||
3 => long.TryParse(decodedKeys[1], out var _) ? EncodeType.EnvelopeReceiverReadOnly : EncodeType.Undefined,
|
||||
_ => EncodeType.Undefined,
|
||||
};
|
||||
|
||||
|
||||
@ -28,6 +28,24 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
|
||||
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.
|
||||
[Obsolete("Use IQueryable.Include instead of this when ID type is clarified.")]
|
||||
private async Task<IEnumerable<EnvelopeReceiverReadOnly>> IncludeEnvelope(params EnvelopeReceiverReadOnly[] erros)
|
||||
|
||||
@ -16,6 +16,7 @@ using EnvelopeGenerator.Web.Models;
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
@ -51,7 +52,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
envelopeReceiverId = _urlEncoder.Encode(envelopeReceiverId);
|
||||
//envelopeReceiverId = _urlEncoder.Encode(envelopeReceiverId);
|
||||
|
||||
if (!envelopeReceiverId.TryDecode(out var decoded))
|
||||
{
|
||||
@ -198,7 +199,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: "No document was found.");
|
||||
return this.ViewDocumentNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
var claims = new List<Claim> {
|
||||
new(ClaimTypes.NameIdentifier, uuid),
|
||||
@ -304,13 +305,12 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("EnvelopeKey/{readOnlyId}/ReadOnly")]
|
||||
public async Task<IActionResult> EnvelopeReceiverReadOnly(string readOnlyKey)
|
||||
[HttpGet("EnvelopeKey/{readOnlyKey}/ReadOnly")]
|
||||
public async Task<IActionResult> EnvelopeReceiverReadOnly([FromRoute] string readOnlyKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
readOnlyKey = _urlEncoder.Encode(readOnlyKey);
|
||||
//readOnlyKey = _urlEncoder.Encode(readOnlyKey);
|
||||
|
||||
// check if the readOnlyId is valid
|
||||
if (!readOnlyKey.TryDecode(out var decodedKeys) || decodedKeys.GetEncodeType() != EncodeType.EnvelopeReceiverReadOnly)
|
||||
@ -320,17 +320,43 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
}
|
||||
|
||||
var readOnlyId = decodedKeys.ParseReadOnlyId();
|
||||
return await _readOnlyService.ReadByIdAsync(readOnlyId).ThenAsync(
|
||||
Success: erro =>
|
||||
var erro_res = await _readOnlyService.ReadByIdAsync(readOnlyId);
|
||||
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;
|
||||
return View("ShowEnvelope");
|
||||
},
|
||||
Fail: IActionResult (msg, ntc) =>
|
||||
var document = await envelopeOldService.GetDocument(response.Envelope.Documents[0].Id, envelopeKey);
|
||||
byte[] bytes = await envelopeOldService.GetDocumentContents(document);
|
||||
ViewData["EnvelopeKey"] = envelopeKey;
|
||||
ViewData["DocumentBytes"] = bytes;
|
||||
ViewData["IsReadOnly"] = true;
|
||||
ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"];
|
||||
return View("ShowEnvelope", er);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogNotice(ntc);
|
||||
return this.ViewInnerServiceError();
|
||||
});
|
||||
_logger.LogEnvelopeError(envelopeReceiverId: envelopeKey, message: "No document was found.");
|
||||
return this.ViewDocumentNotFound();
|
||||
}
|
||||
},
|
||||
Fail: (messages, notices) =>
|
||||
{
|
||||
_logger.LogNotice(notices);
|
||||
return this.ViewEnvelopeNotFound();
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using DigitalData.Core.DTO;
|
||||
using EnvelopeGenerator.Application.Contracts;
|
||||
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly;
|
||||
using EnvelopeGenerator.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
@ -50,5 +51,10 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("key/{readOnlyId}")]
|
||||
public IActionResult CreateLink(long readOnlyId) => Ok(
|
||||
Request.Headers["Origin"].ToString() + "/EnvelopeKey/" + readOnlyId.EncodeEnvelopeReceiverId());
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user