Signature: get the stored object back in the check signature API

This commit is contained in:
nobohan 2024-09-12 15:26:03 +02:00
parent ae1459cf77
commit 092b5c4f90
3 changed files with 91 additions and 62 deletions

View File

@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class SignatureRequestController class SignatureRequestController
{ {
@ -31,6 +32,7 @@ class SignatureRequestController
private readonly StoredObjectManagerInterface $storedObjectManager, private readonly StoredObjectManagerInterface $storedObjectManager,
private readonly EntityWorkflowManager $entityWorkflowManager, private readonly EntityWorkflowManager $entityWorkflowManager,
private readonly ChillEntityRenderManagerInterface $entityRender, private readonly ChillEntityRenderManagerInterface $entityRender,
private readonly NormalizerInterface $normalizer,
private readonly Security $security, private readonly Security $security,
) {} ) {}
@ -72,6 +74,14 @@ class SignatureRequestController
#[Route('/api/1.0/document/workflow/{id}/check-signature', name: 'chill_docstore_check_signature')] #[Route('/api/1.0/document/workflow/{id}/check-signature', name: 'chill_docstore_check_signature')]
public function checkSignature(EntityWorkflowStepSignature $signature): JsonResponse 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, []);
} }
} }

View File

@ -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 { export interface StoredObject {
id: number, id: number;
title: string|null, title: string | null;
uuid: string, uuid: string;
prefix: string, prefix: string;
status: StoredObjectStatus, status: StoredObjectStatus;
currentVersion: null|StoredObjectVersionCreated|StoredObjectVersionPersisted, currentVersion:
totalVersions: number, | null
datas: object, | StoredObjectVersionCreated
| StoredObjectVersionPersisted;
totalVersions: number;
datas: object;
/** @deprecated */ /** @deprecated */
creationDate: DateTime, creationDate: DateTime;
createdAt: DateTime|null, createdAt: DateTime | null;
createdBy: User|null, createdBy: User | null;
_permissions: { _permissions: {
canEdit: boolean, canEdit: boolean;
canSee: boolean, canSee: boolean;
}, };
_links?: { _links?: {
dav_link?: { dav_link?: {
href: string href: string;
expiration: number expiration: number;
}, };
}, };
} }
export interface StoredObjectVersion { export interface StoredObjectVersion {
/** /**
* filename of the object in the object storage * filename of the object in the object storage
*/ */
filename: string, filename: string;
iv: number[], iv: number[];
keyInfos: JsonWebKey, keyInfos: JsonWebKey;
type: string, type: string;
} }
export interface StoredObjectVersionCreated extends StoredObjectVersion { export interface StoredObjectVersionCreated extends StoredObjectVersion {
persisted: false, persisted: false;
} }
export interface StoredObjectVersionPersisted extends StoredObjectVersionCreated { export interface StoredObjectVersionPersisted
version: number, extends StoredObjectVersionCreated {
id: number, version: number;
createdAt: DateTime|null, id: number;
createdBy: User|null, createdAt: DateTime | null;
createdBy: User | null;
} }
export interface StoredObjectStatusChange { export interface StoredObjectStatusChange {
id: number, id: number;
filename: string, filename: string;
status: StoredObjectStatus, status: StoredObjectStatus;
type: string, type: string;
} }
/** /**
* Function executed by the WopiEditButton component. * Function executed by the WopiEditButton component.
*/ */
export type WopiEditButtonExecutableBeforeLeaveFunction = { export type WopiEditButtonExecutableBeforeLeaveFunction = {
(): Promise<void> (): Promise<void>;
} };
/** /**
* Object containing information for performering a POST request to a swift object store * Object containing information for performering a POST request to a swift object store
*/ */
export interface PostStoreObjectSignature { export interface PostStoreObjectSignature {
method: "POST", method: "POST";
max_file_size: number, max_file_size: number;
max_file_count: 1, max_file_count: 1;
expires: number, expires: number;
submit_delay: 180, submit_delay: 180;
redirect: string, redirect: string;
prefix: string, prefix: string;
url: string, url: string;
signature: string, signature: string;
} }
export interface PDFPage { export interface PDFPage {
index: number, index: number;
width: number, width: number;
height: number, height: number;
} }
export interface SignatureZone { export interface SignatureZone {
index: number | null, index: number | null;
x: number, x: number;
y: number, y: number;
width: number, width: number;
height: number, height: number;
PDFPage: PDFPage, PDFPage: PDFPage;
} }
export interface Signature { export interface Signature {
id: number, id: number;
storedObject: StoredObject, storedObject: StoredObject;
zones: SignatureZone[], 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";

View File

@ -224,6 +224,7 @@ import { useToast } from "vue-toast-notification";
import "vue-toast-notification/dist/theme-sugar.css"; import "vue-toast-notification/dist/theme-sugar.css";
import { import {
CanvasEvent, CanvasEvent,
CheckSignature,
Signature, Signature,
SignatureZone, SignatureZone,
SignedState, SignedState,
@ -460,9 +461,10 @@ const drawAllZones = (page: number) => {
const checkSignature = () => { const checkSignature = () => {
const url = `/api/1.0/document/workflow/${signature.id}/check-signature`; const url = `/api/1.0/document/workflow/${signature.id}/check-signature`;
return makeFetch("GET", url) return makeFetch<CheckSignature, CheckSignature>("GET", url)
.then((r) => { .then((r) => {
signedState.value = r as SignedState; signedState.value = r.state;
signature.storedObject = r.storedObject;
checkForReady(); checkForReady();
}) })
.catch((error) => { .catch((error) => {