From 092b5c4f90eb51c8923f149750e77e7d9fa55588 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 12 Sep 2024 15:26:03 +0200 Subject: [PATCH] Signature: get the stored object back in the check signature API --- .../Controller/SignatureRequestController.php | 12 +- .../Resources/public/types.ts | 135 ++++++++++-------- .../public/vuejs/DocumentSignature/App.vue | 6 +- 3 files changed, 91 insertions(+), 62 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php b/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php index 606bafb15..14e33cca3 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php @@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Security; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class SignatureRequestController { @@ -31,6 +32,7 @@ class SignatureRequestController private readonly StoredObjectManagerInterface $storedObjectManager, private readonly EntityWorkflowManager $entityWorkflowManager, private readonly ChillEntityRenderManagerInterface $entityRender, + private readonly NormalizerInterface $normalizer, private readonly Security $security, ) {} @@ -72,6 +74,14 @@ class SignatureRequestController #[Route('/api/1.0/document/workflow/{id}/check-signature', name: 'chill_docstore_check_signature')] public function checkSignature(EntityWorkflowStepSignature $signature): JsonResponse { - return new JsonResponse($signature->getState(), JsonResponse::HTTP_OK, []); + $entityWorkflow = $signature->getStep()->getEntityWorkflow(); + $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow); + + return new JsonResponse( + [ + 'state' => $signature->getState(), + 'storedObject' => $this->normalizer->normalize($storedObject, 'json') + ], + JsonResponse::HTTP_OK, []); } } diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts b/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts index 921da3a9a..ee6b2bf98 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/types.ts @@ -1,102 +1,119 @@ -import {DateTime, User} from "../../../ChillMainBundle/Resources/public/types"; +import { + DateTime, + User, +} from "../../../ChillMainBundle/Resources/public/types"; -export type StoredObjectStatus = "empty"|"ready"|"failure"|"pending"; +export type StoredObjectStatus = "empty" | "ready" | "failure" | "pending"; export interface StoredObject { - id: number, - title: string|null, - uuid: string, - prefix: string, - status: StoredObjectStatus, - currentVersion: null|StoredObjectVersionCreated|StoredObjectVersionPersisted, - totalVersions: number, - datas: object, + id: number; + title: string | null; + uuid: string; + prefix: string; + status: StoredObjectStatus; + currentVersion: + | null + | StoredObjectVersionCreated + | StoredObjectVersionPersisted; + totalVersions: number; + datas: object; /** @deprecated */ - creationDate: DateTime, - createdAt: DateTime|null, - createdBy: User|null, + creationDate: DateTime; + createdAt: DateTime | null; + createdBy: User | null; _permissions: { - canEdit: boolean, - canSee: boolean, - }, + canEdit: boolean; + canSee: boolean; + }; _links?: { dav_link?: { - href: string - expiration: number - }, - }, + href: string; + expiration: number; + }; + }; } export interface StoredObjectVersion { /** * filename of the object in the object storage */ - filename: string, - iv: number[], - keyInfos: JsonWebKey, - type: string, + filename: string; + iv: number[]; + keyInfos: JsonWebKey; + type: string; } export interface StoredObjectVersionCreated extends StoredObjectVersion { - persisted: false, + persisted: false; } -export interface StoredObjectVersionPersisted extends StoredObjectVersionCreated { - version: number, - id: number, - createdAt: DateTime|null, - createdBy: User|null, +export interface StoredObjectVersionPersisted + extends StoredObjectVersionCreated { + version: number; + id: number; + createdAt: DateTime | null; + createdBy: User | null; } export interface StoredObjectStatusChange { - id: number, - filename: string, - status: StoredObjectStatus, - type: string, + id: number; + filename: string; + status: StoredObjectStatus; + type: string; } /** * Function executed by the WopiEditButton component. */ export type WopiEditButtonExecutableBeforeLeaveFunction = { - (): Promise -} + (): Promise; +}; /** * Object containing information for performering a POST request to a swift object store */ export interface PostStoreObjectSignature { - method: "POST", - max_file_size: number, - max_file_count: 1, - expires: number, - submit_delay: 180, - redirect: string, - prefix: string, - url: string, - signature: string, + method: "POST"; + max_file_size: number; + max_file_count: 1; + expires: number; + submit_delay: 180; + redirect: string; + prefix: string; + url: string; + signature: string; } export interface PDFPage { - index: number, - width: number, - height: number, + index: number; + width: number; + height: number; } export interface SignatureZone { - index: number | null, - x: number, - y: number, - width: number, - height: number, - PDFPage: PDFPage, + index: number | null; + x: number; + y: number; + width: number; + height: number; + PDFPage: PDFPage; } export interface Signature { - id: number, - storedObject: StoredObject, - zones: SignatureZone[], + id: number; + storedObject: StoredObject; + zones: SignatureZone[]; } -export type SignedState = 'pending' | 'signed' | 'rejected' | 'canceled' | 'error'; +export type SignedState = + | "pending" + | "signed" + | "rejected" + | "canceled" + | "error"; -export type CanvasEvent = 'select' | 'add'; +export interface CheckSignature { + state: SignedState; + storedObject: StoredObject; +} + +export type CanvasEvent = "select" | "add"; diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue index e1d3124ce..3294360ef 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue @@ -224,6 +224,7 @@ import { useToast } from "vue-toast-notification"; import "vue-toast-notification/dist/theme-sugar.css"; import { CanvasEvent, + CheckSignature, Signature, SignatureZone, SignedState, @@ -460,9 +461,10 @@ const drawAllZones = (page: number) => { const checkSignature = () => { const url = `/api/1.0/document/workflow/${signature.id}/check-signature`; - return makeFetch("GET", url) + return makeFetch("GET", url) .then((r) => { - signedState.value = r as SignedState; + signedState.value = r.state; + signature.storedObject = r.storedObject; checkForReady(); }) .catch((error) => {