Compare commits
11 Commits
c7bc9fbcca
...
bugfix/sav
| Author | SHA1 | Date | |
|---|---|---|---|
| d0c3d79fbc | |||
| e81c7896a1 | |||
| 127e2b253e | |||
| 6d0b78072e | |||
| 3721ea9a1f | |||
| f86588551c | |||
| 0eaa9ff08f | |||
| ec79d7622e | |||
| f558d03bdf | |||
| db79053c62 | |||
| 85dd85aa92 |
@@ -245,6 +245,11 @@ Manual testing workflow:
|
|||||||
- Perform a senior-level page performance review across sender/receiver flows before further UX changes: verify route transitions, component mount/unmount behavior, loading-state correctness, duplicate API calls, and perceived latency (first meaningful paint and return-navigation responsiveness). Treat loading logic defects as architecture/performance issues first, not styling problems.
|
- Perform a senior-level page performance review across sender/receiver flows before further UX changes: verify route transitions, component mount/unmount behavior, loading-state correctness, duplicate API calls, and perceived latency (first meaningful paint and return-navigation responsiveness). Treat loading logic defects as architecture/performance issues first, not styling problems.
|
||||||
- Audit `EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/` for unnecessary request/payload remapping and remove redundant mappings where direct request DTO usage is safe; review client HTTP methods end-to-end for similar avoidable transformation layers.
|
- Audit `EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/` for unnecessary request/payload remapping and remove redundant mappings where direct request DTO usage is safe; review client HTTP methods end-to-end for similar avoidable transformation layers.
|
||||||
- Centralize dependency injection registrations into dedicated extension methods/modules (especially server + client service registrations in `Program.cs`) to reduce startup composition sprawl and improve maintainability.
|
- Centralize dependency injection registrations into dedicated extension methods/modules (especially server + client service registrations in `Program.cs`) to reduce startup composition sprawl and improve maintainability.
|
||||||
|
- Refactor `EnvelopeGenerator.Server/EnvelopeGenerator.Server/Controllers/PdfRenderController.cs` + matching client service contract to remove JSON/base64 `byte[]` transport for PDF rendering; prefer binary streaming (`application/octet-stream` or multipart), avoid `data:` URL bloat where possible, and validate end-to-end memory/latency behavior with large PDFs.
|
||||||
|
- Establish a DevExpress toast-based notification architecture using `DxToastProvider` + `IToastNotificationService` (tab/page-scoped provider strategy, standardized `ToastOptions` factory, and severity-to-style mapping) so sender/receiver flows show consistent, non-duplicated, actionable feedback.
|
||||||
|
- Eliminate manual property-by-property request→domain mapping drift (example: `CreateEnvelopeCommandHandler`) by introducing a standardized mapping policy (AutoMapper/profile conventions or reflection/source-generator based mapper) and enforcing it across envelope workflows; this needs to be solved in the shared company Core library level so all services get the same guardrails by default.
|
||||||
|
- P1 security workstream: remove dynamic SQL string composition/interpolation from active save/create/update paths (`string.Format`, `$"...{input}..."`, `ToSqlParam`) and migrate to parameterized queries only; treat this as a potential SQL injection vulnerability (stability + security risk), execute repo-wide audit, and add CI guardrails to block reintroduction.
|
||||||
|
- Alternative UX design (Server component): in `EnvelopeGenerator.Server/EnvelopeGenerator.Server/Components/Pages/EnvelopeSenderPage.razor`, enforce deterministic row double-click behavior as exactly one action (preview OR edit), and keep row action buttons/tooltips aligned with the same rule to eliminate ambiguous navigation.
|
||||||
|
|
||||||
## Database
|
## Database
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using DigitalData.Core.Exceptions;
|
||||||
|
using FluentValidation;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Application.Common.Behaviors;
|
||||||
|
|
||||||
|
public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
||||||
|
where TRequest : notnull
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<IValidator<TRequest>> _validators;
|
||||||
|
|
||||||
|
public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators)
|
||||||
|
{
|
||||||
|
_validators = validators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<TResponse> Handle(
|
||||||
|
TRequest request,
|
||||||
|
RequestHandlerDelegate<TResponse> next,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (_validators.Any())
|
||||||
|
{
|
||||||
|
var context = new ValidationContext<TRequest>(request);
|
||||||
|
var failures = _validators
|
||||||
|
.Select(v => v.Validate(context))
|
||||||
|
.SelectMany(r => r.Errors)
|
||||||
|
.Where(f => f is not null)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (failures.Count > 0)
|
||||||
|
{
|
||||||
|
var message = string.Join("; ", failures.Select(f => f.ErrorMessage).Distinct());
|
||||||
|
throw new BadRequestException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await next();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
namespace EnvelopeGenerator.Application.Common.Dto;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data Transfer Object representing document metadata and elements without binary payload.
|
||||||
|
/// </summary>
|
||||||
|
public record DocumentDetailsDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the unique identifier of the document.
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the envelope ID to which the document belongs.
|
||||||
|
/// </summary>
|
||||||
|
public int EnvelopeId { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the date and time when the document was added.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime AddedWhen { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the collection of elements associated with the document for receiver interactions, if any.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<DocReceiverElementDto>? Elements { get; init; }
|
||||||
|
}
|
||||||
@@ -3,30 +3,25 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Data Transfer Object representing a document within an envelope, including optional binary data and form elements.
|
/// Data Transfer Object representing a document within an envelope, including optional binary data and form elements.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DocumentDto
|
public record DocumentDto : DocumentDetailsDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the unique identifier of the document.
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public DocumentDto() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the envelope ID to which the document belongs.
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int EnvelopeId { get; set; }
|
/// <param name="byteData"></param>
|
||||||
|
/// <param name="details"></param>
|
||||||
/// <summary>
|
public DocumentDto(byte[] byteData, DocumentDetailsDto details) : base(details)
|
||||||
/// Gets or sets the date and time when the document was added.
|
{
|
||||||
/// </summary>
|
ByteData = byteData;
|
||||||
public DateTime AddedWhen { get; set; }
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the binary data of the document, if available.
|
/// Gets or sets the binary data of the document, if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[]? ByteData { get; set; }
|
public byte[]? ByteData { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the collection of elements associated with the document for receiver interactions, if any.
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<DocReceiverElementDto>? Elements { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@ public class MappingProfile : Profile
|
|||||||
.ForMember(dest => dest.EnvelopeTypeTitle,
|
.ForMember(dest => dest.EnvelopeTypeTitle,
|
||||||
opt => opt.MapFrom(src => src.Type != null ? src.Type.Title : null));
|
opt => opt.MapFrom(src => src.Type != null ? src.Type.Title : null));
|
||||||
CreateMap<Document, DocumentDto>();
|
CreateMap<Document, DocumentDto>();
|
||||||
|
CreateMap<Document, DocumentDetailsDto>();
|
||||||
CreateMap<History, HistoryDto>().ForMember(dest => dest.ActionDate, opt => opt.MapFrom(src => src.ChangedWhen));
|
CreateMap<History, HistoryDto>().ForMember(dest => dest.ActionDate, opt => opt.MapFrom(src => src.ChangedWhen));
|
||||||
CreateMap<History, HistoryCreateDto>().ForMember(dest => dest.ActionDate, opt => opt.MapFrom(src => src.ChangedWhen));
|
CreateMap<History, HistoryCreateDto>().ForMember(dest => dest.ActionDate, opt => opt.MapFrom(src => src.ChangedWhen));
|
||||||
CreateMap<EnvelopeReceiver, EnvelopeReceiverDto>();
|
CreateMap<EnvelopeReceiver, EnvelopeReceiverDto>();
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ using System.Reflection;
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
||||||
using EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
using EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
||||||
|
using EnvelopeGenerator.Application.Common.Behaviors;
|
||||||
|
using FluentValidation;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application;
|
namespace EnvelopeGenerator.Application;
|
||||||
|
|
||||||
@@ -60,6 +62,9 @@ public static class DependencyInjection
|
|||||||
{
|
{
|
||||||
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
|
// Generic request validation
|
||||||
|
cfg.AddOpenBehavior(typeof(ValidationBehavior<,>));
|
||||||
|
|
||||||
// Register SignCommand pipeline behaviors in execution order
|
// Register SignCommand pipeline behaviors in execution order
|
||||||
// 0. EnvelopeReceiverResolutionBehavior - Resolves EnvelopeReceiver from query parameters (executes FIRST)
|
// 0. EnvelopeReceiverResolutionBehavior - Resolves EnvelopeReceiver from query parameters (executes FIRST)
|
||||||
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, EnvelopeReceiverResolutionBehavior>();
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, EnvelopeReceiverResolutionBehavior>();
|
||||||
@@ -80,6 +85,8 @@ public static class DependencyInjection
|
|||||||
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, SendSignedMailBehavior>();
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, SendSignedMailBehavior>();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using AutoMapper.QueryableExtensions;
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using EnvelopeGenerator.Application.Common.Dto;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Application.Documents.Queries;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a query to read document metadata/details without binary payload.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="EnvelopeId">The identifier of the envelope associated with the document.</param>
|
||||||
|
/// <param name="UserId">The unique identifier of the sending user. Optional.</param>
|
||||||
|
public record ReadDocumentDetailsQuery(int EnvelopeId, int? UserId = null) : IRequest<DocumentDetailsDto?>;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles queries for reading document details without loading BYTE_DATA.
|
||||||
|
/// </summary>
|
||||||
|
public class ReadDocumentDetailsQueryHandler : IRequestHandler<ReadDocumentDetailsQuery, DocumentDetailsDto?>
|
||||||
|
{
|
||||||
|
private readonly IRepository<Document> _repo;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
public ReadDocumentDetailsQueryHandler(IRepository<Document> repo, IMapper mapper)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<DocumentDetailsDto?> Handle(ReadDocumentDetailsQuery query, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
var docQuery = _repo.Query.AsNoTracking();
|
||||||
|
|
||||||
|
if (query.UserId is int userId)
|
||||||
|
docQuery = docQuery.Where(doc => doc.Envelope.UserId == userId);
|
||||||
|
|
||||||
|
return await docQuery
|
||||||
|
.Where(d => d.EnvelopeId == query.EnvelopeId)
|
||||||
|
.ProjectTo<DocumentDetailsDto>(_mapper.ConfigurationProvider)
|
||||||
|
.FirstOrDefaultAsync(cancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Application.Documents.Queries;
|
||||||
|
|
||||||
|
public class ReadDocumentDetailsQueryValidator : AbstractValidator<ReadDocumentDetailsQuery>
|
||||||
|
{
|
||||||
|
public ReadDocumentDetailsQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.EnvelopeId)
|
||||||
|
.GreaterThan(0)
|
||||||
|
.WithMessage("EnvelopeId is required.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Application.Documents.Queries;
|
||||||
|
|
||||||
|
public class ReadDocumentQueryValidator : AbstractValidator<ReadDocumentQuery>
|
||||||
|
{
|
||||||
|
public ReadDocumentQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x)
|
||||||
|
.Must(x => (x.Id ?? 0) > 0 || (x.EnvelopeId ?? 0) > 0)
|
||||||
|
.WithMessage("Id or EnvelopeId is required.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Id)
|
||||||
|
.GreaterThan(0)
|
||||||
|
.When(x => x.Id.HasValue)
|
||||||
|
.WithMessage("Id must be greater than 0.");
|
||||||
|
|
||||||
|
RuleFor(x => x.EnvelopeId)
|
||||||
|
.GreaterThan(0)
|
||||||
|
.When(x => x.EnvelopeId.HasValue)
|
||||||
|
.WithMessage("EnvelopeId must be greater than 0.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
|
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
||||||
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
|
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
||||||
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
||||||
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
|
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
|
||||||
<PackageReference Include="MediatR" Version="12.5.0" />
|
<PackageReference Include="MediatR" Version="12.5.0" />
|
||||||
<PackageReference Include="Microsoft.Identity.Client" Version="4.82.1" />
|
<PackageReference Include="Microsoft.Identity.Client" Version="4.82.1" />
|
||||||
|
|||||||
@@ -168,6 +168,9 @@ public class CreateEnvelopeCommandHandler : IRequestHandler<CreateEnvelopeComman
|
|||||||
{
|
{
|
||||||
await Repository.UpdateAsync(e =>
|
await Repository.UpdateAsync(e =>
|
||||||
{
|
{
|
||||||
|
e.Title = title;
|
||||||
|
e.Message = message;
|
||||||
|
e.TfaEnabled = request.TFAEnabled;
|
||||||
e.EnvelopeTypeId = settings.EnvelopeTypeId;
|
e.EnvelopeTypeId = settings.EnvelopeTypeId;
|
||||||
e.Language = settings.Language;
|
e.Language = settings.Language;
|
||||||
e.UseAccessCode = settings.UseAccessCode;
|
e.UseAccessCode = settings.UseAccessCode;
|
||||||
@@ -182,9 +185,13 @@ public class CreateEnvelopeCommandHandler : IRequestHandler<CreateEnvelopeComman
|
|||||||
e.ExpiresWhen = settings.ExpiresWhen;
|
e.ExpiresWhen = settings.ExpiresWhen;
|
||||||
e.ExpiresWarningWhen = settings.ExpiresWarningWhen;
|
e.ExpiresWarningWhen = settings.ExpiresWarningWhen;
|
||||||
e.ContractType = settings.ContractType;
|
e.ContractType = settings.ContractType;
|
||||||
|
e.Status = EnvelopeStatus.EnvelopeSaved;
|
||||||
e.ChangedWhen = now;
|
e.ChangedWhen = now;
|
||||||
}, e => e.Id == envelope.Id, cancel);
|
}, e => e.Id == envelope.Id, cancel);
|
||||||
|
|
||||||
|
envelope.Title = title;
|
||||||
|
envelope.Message = message;
|
||||||
|
envelope.TfaEnabled = request.TFAEnabled;
|
||||||
envelope.EnvelopeTypeId = settings.EnvelopeTypeId;
|
envelope.EnvelopeTypeId = settings.EnvelopeTypeId;
|
||||||
envelope.Language = settings.Language;
|
envelope.Language = settings.Language;
|
||||||
envelope.UseAccessCode = settings.UseAccessCode;
|
envelope.UseAccessCode = settings.UseAccessCode;
|
||||||
@@ -199,6 +206,7 @@ public class CreateEnvelopeCommandHandler : IRequestHandler<CreateEnvelopeComman
|
|||||||
envelope.ExpiresWhen = settings.ExpiresWhen;
|
envelope.ExpiresWhen = settings.ExpiresWhen;
|
||||||
envelope.ExpiresWarningWhen = settings.ExpiresWarningWhen;
|
envelope.ExpiresWarningWhen = settings.ExpiresWarningWhen;
|
||||||
envelope.ContractType = settings.ContractType;
|
envelope.ContractType = settings.ContractType;
|
||||||
|
envelope.Status = EnvelopeStatus.EnvelopeSaved;
|
||||||
envelope.ChangedWhen = now;
|
envelope.ChangedWhen = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,7 @@
|
|||||||
{
|
{
|
||||||
<div class="sender-image-editor__empty">@L("SenderEditor_NoPagesToDisplay", "Keine Seiten zur Anzeige verfügbar.")</div>
|
<div class="sender-image-editor__empty">@L("SenderEditor_NoPagesToDisplay", "Keine Seiten zur Anzeige verfügbar.")</div>
|
||||||
}
|
}
|
||||||
else
|
else if (Pages.Count == 0 && !string.IsNullOrWhiteSpace(PdfDataUrl))
|
||||||
{
|
|
||||||
@if (Pages.Count == 0 && !string.IsNullOrWhiteSpace(PdfDataUrl))
|
|
||||||
{
|
{
|
||||||
<div class="sender-image-editor__native-preview" style="@GetZoomStyle()">
|
<div class="sender-image-editor__native-preview" style="@GetZoomStyle()">
|
||||||
<iframe class="sender-image-editor__native-frame"
|
<iframe class="sender-image-editor__native-frame"
|
||||||
@@ -57,59 +55,60 @@
|
|||||||
title="PDF Preview"></iframe>
|
title="PDF Preview"></iframe>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="sender-image-editor__pages" style="@GetZoomStyle()">
|
||||||
|
@for (var pageIndex = 0; pageIndex < PageCount; pageIndex++)
|
||||||
|
{
|
||||||
|
var pagePreview = pageIndex < Pages.Count ? Pages[pageIndex] : null;
|
||||||
|
var pageNumber = pagePreview?.PageNumber ?? (pageIndex + 1);
|
||||||
|
var widthPt = pagePreview?.WidthPt ?? 595.0;
|
||||||
|
var heightPt = pagePreview?.HeightPt ?? 842.0;
|
||||||
|
|
||||||
<div class="sender-image-editor__pages" style="@GetZoomStyle()">
|
<div class="sender-image-editor__page-block"
|
||||||
@for (var pageIndex = 0; pageIndex < PageCount; pageIndex++)
|
data-editor-page="@pageNumber"
|
||||||
{
|
data-page-width-pt="@widthPt"
|
||||||
var pagePreview = pageIndex < Pages.Count ? Pages[pageIndex] : null;
|
data-page-height-pt="@heightPt">
|
||||||
var pageNumber = pagePreview?.PageNumber ?? (pageIndex + 1);
|
<div class="sender-image-editor__page-canvas"
|
||||||
var widthPt = pagePreview?.WidthPt ?? 595.0;
|
data-editor-page-canvas="@pageNumber"
|
||||||
var heightPt = pagePreview?.HeightPt ?? 842.0;
|
style="@GetPageCanvasStyle(widthPt, heightPt)">
|
||||||
|
@if (!string.IsNullOrWhiteSpace(pagePreview?.ImageDataUrl))
|
||||||
|
{
|
||||||
|
<img class="sender-image-editor__page-image"
|
||||||
|
src="@(pagePreview!.ImageDataUrl)"
|
||||||
|
alt="PDF Page @pageNumber"
|
||||||
|
draggable="false" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="sender-image-editor__page-placeholder">@L("SenderEditor_PageLabel", "Seite") @pageNumber</div>
|
||||||
|
}
|
||||||
|
|
||||||
<div class="sender-image-editor__page-block"
|
@foreach (var field in Fields.Where(f => f.Page == pageNumber))
|
||||||
data-editor-page="@pageNumber"
|
{
|
||||||
data-page-width-pt="@widthPt"
|
<div class="sender-image-editor__field"
|
||||||
data-page-height-pt="@heightPt">
|
style="@GetFieldStyle(field, widthPt, heightPt)"
|
||||||
<div class="sender-image-editor__page-canvas"
|
title="@field.ReceiverName"
|
||||||
data-editor-page-canvas="@pageNumber"
|
@onmousedown="args => OnFieldMouseDownAsync(args, field)"
|
||||||
style="@GetPageCanvasStyle(widthPt, heightPt)">
|
@onmousedown:preventDefault="true"
|
||||||
@if (!string.IsNullOrWhiteSpace(pagePreview?.ImageDataUrl))
|
@onclick:stopPropagation="true">
|
||||||
{
|
<span class="sender-image-editor__field-label">@field.ReceiverName</span>
|
||||||
<img class="sender-image-editor__page-image"
|
<button type="button"
|
||||||
src="@(pagePreview!.ImageDataUrl)"
|
class="sender-image-editor__field-remove"
|
||||||
alt="PDF Page @pageNumber"
|
title='@L("Delete", "Löschen")'
|
||||||
draggable="false" />
|
draggable="false"
|
||||||
}
|
@onclick:stopPropagation="true"
|
||||||
else
|
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
||||||
{
|
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
||||||
<div class="sender-image-editor__page-placeholder">@L("SenderEditor_PageLabel", "Seite") @pageNumber</div>
|
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||||
}
|
</svg>
|
||||||
|
</button>
|
||||||
@foreach (var field in Fields.Where(f => f.Page == pageNumber))
|
</div>
|
||||||
{
|
}
|
||||||
<div class="sender-image-editor__field"
|
</div>
|
||||||
style="@GetFieldStyle(field, widthPt, heightPt)"
|
|
||||||
title="@field.ReceiverName"
|
|
||||||
@onmousedown="args => OnFieldMouseDownAsync(args, field)"
|
|
||||||
@onmousedown:preventDefault="true"
|
|
||||||
@onclick:stopPropagation="true">
|
|
||||||
<span class="sender-image-editor__field-label">@field.ReceiverName</span>
|
|
||||||
<button type="button"
|
|
||||||
class="sender-image-editor__field-remove"
|
|
||||||
title='@L("Delete", "Löschen")'
|
|
||||||
draggable="false"
|
|
||||||
@onclick:stopPropagation="true"
|
|
||||||
@onclick="() => RemoveField.InvokeAsync(field.Index)">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
||||||
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -826,11 +826,31 @@
|
|||||||
|
|
||||||
_originalPdfBytes = document?.ByteData;
|
_originalPdfBytes = document?.ByteData;
|
||||||
_pdfLoaded = _originalPdfBytes is { Length: > 0 };
|
_pdfLoaded = _originalPdfBytes is { Length: > 0 };
|
||||||
_pagePreviews = [];
|
|
||||||
_pageCount = _pagePreviews.Count > 0
|
if (_pdfLoaded)
|
||||||
? _pagePreviews.Count
|
{
|
||||||
: EstimatePdfPageCount(_originalPdfBytes)
|
try
|
||||||
?? Math.Max(1, _signatureFields.Select(f => f.Page).DefaultIfEmpty(1).Max());
|
{
|
||||||
|
_pagePreviews = (await PdfRenderService.RenderPagesAsync(_originalPdfBytes!))
|
||||||
|
.OrderBy(p => p.PageNumber)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
catch (Exception renderEx)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(renderEx, "Failed to render PDF page previews for envelope {EnvelopeId}. Falling back to native preview.", envelopeId);
|
||||||
|
_pagePreviews = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
_pageCount = _pagePreviews.Count > 0
|
||||||
|
? _pagePreviews.Count
|
||||||
|
: 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_pagePreviews = [];
|
||||||
|
_pageCount = Math.Max(1, _signatureFields.Select(f => f.Page).DefaultIfEmpty(1).Max());
|
||||||
|
}
|
||||||
|
|
||||||
_fileName = $"Envelope-{envelopeId}.pdf";
|
_fileName = $"Envelope-{envelopeId}.pdf";
|
||||||
_pendingReceiverForPlacement = null;
|
_pendingReceiverForPlacement = null;
|
||||||
_loadedEnvelopeId = envelopeId;
|
_loadedEnvelopeId = envelopeId;
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ public class DocumentService(IHttpClientFactory httpClientFactory)
|
|||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
||||||
|
|
||||||
|
private static HttpRequestException CreateHttpException(string messagePrefix, HttpStatusCode statusCode, string? reasonPhrase)
|
||||||
|
{
|
||||||
|
var statusCodeInt = (int)statusCode;
|
||||||
|
return new HttpRequestException(
|
||||||
|
$"{messagePrefix}. Status: {statusCodeInt} ({reasonPhrase ?? "Unknown error"})",
|
||||||
|
null,
|
||||||
|
statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches the PDF bytes for the given envelope key from the API.
|
/// Fetches the PDF bytes for the given envelope key from the API.
|
||||||
/// Throws HttpRequestException on failure with appropriate status code.
|
/// Throws HttpRequestException on failure with appropriate status code.
|
||||||
@@ -21,14 +30,7 @@ public class DocumentService(IHttpClientFactory httpClientFactory)
|
|||||||
var response = await http.GetAsync($"/api/Document/{Uri.EscapeDataString(envelopeKey)}", cancel);
|
var response = await http.GetAsync($"/api/Document/{Uri.EscapeDataString(envelopeKey)}", cancel);
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
throw CreateHttpException("Failed to load document", response.StatusCode, response.ReasonPhrase);
|
||||||
var statusCode = (int)response.StatusCode;
|
|
||||||
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
|
|
||||||
throw new HttpRequestException(
|
|
||||||
$"Failed to load document. Status: {statusCode} ({reasonPhrase})",
|
|
||||||
null,
|
|
||||||
response.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = await response.Content.ReadAsByteArrayAsync(cancel);
|
var bytes = await response.Content.ReadAsByteArrayAsync(cancel);
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -36,24 +38,38 @@ public class DocumentService(IHttpClientFactory httpClientFactory)
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches sender document details (including signature elements) by envelope id.
|
/// Fetches sender document details (including signature elements) by envelope id.
|
||||||
/// Uses GET /api/Document?EnvelopeId={envelopeId}.
|
/// Uses GET /api/Document/details?EnvelopeId={envelopeId}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<DocumentDto?> GetSenderDocumentDetailsByEnvelopeIdAsync(int envelopeId, CancellationToken cancel = default)
|
public async Task<DocumentDto?> GetSenderDocumentDetailsByEnvelopeIdAsync(int envelopeId, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
||||||
var response = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
|
var detailsResponse = await http.GetAsync($"/api/Document/details?EnvelopeId={envelopeId}", cancel);
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (detailsResponse.StatusCode == HttpStatusCode.NotFound)
|
||||||
{
|
{
|
||||||
var statusCode = (int)response.StatusCode;
|
var fallbackBytes = await TryGetSenderDocumentBytesByEnvelopeIdAsync(http, envelopeId, cancel);
|
||||||
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
|
if (fallbackBytes is null)
|
||||||
throw new HttpRequestException(
|
return null;
|
||||||
$"Failed to load sender document details. Status: {statusCode} ({reasonPhrase})",
|
|
||||||
null,
|
return new DocumentDto(fallbackBytes, new DocumentDetailsDto
|
||||||
response.StatusCode);
|
{
|
||||||
|
EnvelopeId = envelopeId,
|
||||||
|
AddedWhen = DateTime.UtcNow,
|
||||||
|
Elements = []
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.Content.ReadFromJsonAsync<DocumentDto>(_jsonOptions, cancel);
|
if (!detailsResponse.IsSuccessStatusCode)
|
||||||
|
throw CreateHttpException("Failed to load sender document details", detailsResponse.StatusCode, detailsResponse.ReasonPhrase);
|
||||||
|
|
||||||
|
var details = await detailsResponse.Content.ReadFromJsonAsync<DocumentDetailsDto>(_jsonOptions, cancel)
|
||||||
|
?? throw new HttpRequestException("Failed to deserialize sender document details response.");
|
||||||
|
|
||||||
|
var byteData = await TryGetSenderDocumentBytesByEnvelopeIdAsync(http, envelopeId, cancel);
|
||||||
|
if (byteData is null)
|
||||||
|
byteData = [];
|
||||||
|
|
||||||
|
return new DocumentDto(byteData, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,16 +81,24 @@ public class DocumentService(IHttpClientFactory httpClientFactory)
|
|||||||
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
||||||
var response = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
|
var response = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
|
||||||
|
|
||||||
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
throw CreateHttpException("Failed to load sender document bytes", response.StatusCode, response.ReasonPhrase);
|
||||||
var statusCode = (int)response.StatusCode;
|
|
||||||
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
|
|
||||||
throw new HttpRequestException(
|
|
||||||
$"Failed to load sender document bytes. Status: {statusCode} ({reasonPhrase})",
|
|
||||||
null,
|
|
||||||
response.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.Content.ReadAsByteArrayAsync(cancel);
|
return await response.Content.ReadAsByteArrayAsync(cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task<byte[]?> TryGetSenderDocumentBytesByEnvelopeIdAsync(HttpClient http, int envelopeId, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
var bytesResponse = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
|
||||||
|
if (bytesResponse.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (!bytesResponse.IsSuccessStatusCode)
|
||||||
|
throw CreateHttpException("Failed to load sender document bytes", bytesResponse.StatusCode, bytesResponse.ReasonPhrase);
|
||||||
|
|
||||||
|
return await bytesResponse.Content.ReadAsByteArrayAsync(cancel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,17 +31,30 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
|
|||||||
/// <param name="cancel">Cancellation token.</param>
|
/// <param name="cancel">Cancellation token.</param>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
||||||
public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery? query = null)
|
public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery query)
|
||||||
{
|
{
|
||||||
if (query is null)
|
|
||||||
return BadRequest("Missing document query.");
|
|
||||||
|
|
||||||
var senderDoc = await mediator.Send(query, cancel);
|
var senderDoc = await mediator.Send(query, cancel);
|
||||||
return senderDoc?.ByteData is byte[] senderDocByte
|
return senderDoc?.ByteData is byte[] senderDocByte
|
||||||
? File(senderDocByte, "application/octet-stream")
|
? File(senderDocByte, "application/octet-stream")
|
||||||
: NotFound("Document is empty.");
|
: NotFound("Document is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns sender document metadata and element details (without binary payload) for editor loading.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">Document query with EnvelopeId.</param>
|
||||||
|
/// <param name="cancel">Cancellation token.</param>
|
||||||
|
[HttpGet("details")]
|
||||||
|
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
||||||
|
public async Task<IActionResult> GetDocumentDetails(CancellationToken cancel, [FromQuery] ReadDocumentDetailsQuery query)
|
||||||
|
{
|
||||||
|
var senderDoc = await mediator.Send(query with { UserId = User.GetId() }, cancel);
|
||||||
|
if (senderDoc is null)
|
||||||
|
return NotFound("Document is empty.");
|
||||||
|
|
||||||
|
return Ok(senderDoc);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the document for the specified envelope key.
|
/// Gets the document for the specified envelope key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace EnvelopeGenerator.Server.Controllers;
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class PdfRenderController(IPdfPageImageRenderer renderer) : ControllerBase
|
public class PdfRenderController(IPdfPageImageRenderer renderer) : ControllerBase
|
||||||
{
|
{
|
||||||
|
// TODO(perf): Replace JSON/base64 transport for PdfBytes with application/octet-stream (or multipart) and stream-based request parsing to reduce payload size and allocation pressure for large PDFs.
|
||||||
[HttpPost("pages")]
|
[HttpPost("pages")]
|
||||||
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
||||||
public async Task<IActionResult> RenderPages([FromBody] PdfRenderRequestDto? request, CancellationToken cancel)
|
public async Task<IActionResult> RenderPages([FromBody] PdfRenderRequestDto? request, CancellationToken cancel)
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ public class EnvelopeReceiverPageDataService(
|
|||||||
return await mediator.Send(new ReadDocumentQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken);
|
return await mediator.Send(new ReadDocumentQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads document metadata/elements for the authenticated sender without binary payload.
|
||||||
|
/// </summary>
|
||||||
|
public async Task<DocumentDetailsDto?> GetDocumentMetadataOfSenderAsync(ClaimsPrincipal user, int envelopeId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await mediator.Send(new ReadDocumentDetailsQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the current receiver's signature placeholders.
|
/// Loads the current receiver's signature placeholders.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user