Skip to content

Commit 370f8a2

Browse files
authored
Merge pull request #6368 from LibreSign/backport/6365/stable32
[stable32] feat: file id selection
2 parents e2e68ca + 370cdda commit 370f8a2

File tree

18 files changed

+960
-120
lines changed

18 files changed

+960
-120
lines changed

lib/Controller/FileController.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ private function validate(?string $type = null, $identifier = null): DataRespons
246246
* List identification documents that need to be approved
247247
*
248248
* @param string|null $signer_uuid Signer UUID
249-
* @param list<string>|null $nodeIds The list of nodeIds (also called fileIds). It's the ids of files at Nextcloud
249+
* @param list<int>|null $fileIds The list of fileIds (database file IDs). It's the ids of LibreSign files
250+
* @param list<int>|null $nodeIds The list of nodeIds (also called fileIds). It's the ids of files at Nextcloud
250251
* @param list<int>|null $status Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.
251252
* @param int|null $page the number of page to return
252253
* @param int|null $length Total of elements to return
@@ -266,6 +267,7 @@ public function list(
266267
?int $page = null,
267268
?int $length = null,
268269
?string $signer_uuid = null,
270+
?array $fileIds = null,
269271
?array $nodeIds = null,
270272
?array $status = null,
271273
?int $start = null,
@@ -276,6 +278,7 @@ public function list(
276278
): DataResponse {
277279
$filter = array_filter([
278280
'signer_uuid' => $signer_uuid,
281+
'fileIds' => $fileIds,
279282
'nodeIds' => $nodeIds,
280283
'status' => $status,
281284
'start' => $start,
@@ -355,6 +358,64 @@ public function getThumbnail(
355358
return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback);
356359
}
357360

361+
/**
362+
* Return the thumbnail of a LibreSign file by fileId
363+
*
364+
* @param integer $fileId The LibreSign fileId (database id)
365+
* @param integer $x Width of generated file
366+
* @param integer $y Height of generated file
367+
* @param boolean $a Crop, boolean value, default false
368+
* @param boolean $forceIcon Force to generate a new thumbnail
369+
* @param string $mode To force a given mimetype for the file
370+
* @param boolean $mimeFallback If we have no preview enabled, we can redirect to the mime icon if any
371+
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
372+
*
373+
* 200: OK
374+
* 303: Redirect
375+
* 400: Bad request
376+
* 403: Forbidden
377+
* 404: Not found
378+
*/
379+
#[NoAdminRequired]
380+
#[NoCSRFRequired]
381+
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/file/thumbnail/file_id/{fileId}', requirements: ['apiVersion' => '(v1)'])]
382+
public function getThumbnailByFileId(
383+
int $fileId = -1,
384+
int $x = 32,
385+
int $y = 32,
386+
bool $a = false,
387+
bool $forceIcon = true,
388+
string $mode = 'fill',
389+
bool $mimeFallback = false,
390+
) {
391+
if ($fileId === -1 || $x === 0 || $y === 0) {
392+
return new DataResponse([], Http::STATUS_BAD_REQUEST);
393+
}
394+
395+
try {
396+
$libreSignFile = $this->fileMapper->getById($fileId);
397+
if ($libreSignFile->getUserId() !== $this->userSession->getUser()->getUID()) {
398+
return new DataResponse([], Http::STATUS_FORBIDDEN);
399+
}
400+
401+
if ($libreSignFile->getNodeType() === 'envelope') {
402+
if ($mimeFallback) {
403+
$url = $this->mimeIconProvider->getMimeIconUrl('folder');
404+
if ($url) {
405+
return new RedirectResponse($url);
406+
}
407+
}
408+
return new DataResponse([], Http::STATUS_NOT_FOUND);
409+
}
410+
411+
$node = $this->accountService->getPdfByUuid($libreSignFile->getUuid());
412+
} catch (DoesNotExistException) {
413+
return new DataResponse([], Http::STATUS_NOT_FOUND);
414+
}
415+
416+
return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback);
417+
}
418+
358419
/**
359420
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
360421
*/

lib/Db/SignRequestMapper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,15 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
612612
}
613613
if (!empty($filter['nodeIds'])) {
614614
$qb->andWhere(
615-
$qb->expr()->in('f.node_id', $qb->createNamedParameter($filter['nodeIds'], IQueryBuilder::PARAM_STR_ARRAY))
615+
$qb->expr()->orX(
616+
$qb->expr()->in('f.node_id', $qb->createNamedParameter($filter['nodeIds'], IQueryBuilder::PARAM_INT_ARRAY)),
617+
$qb->expr()->in('f.signed_node_id', $qb->createNamedParameter($filter['nodeIds'], IQueryBuilder::PARAM_INT_ARRAY))
618+
)
619+
);
620+
}
621+
if (!empty($filter['fileIds'])) {
622+
$qb->andWhere(
623+
$qb->expr()->in('f.id', $qb->createNamedParameter($filter['fileIds'], IQueryBuilder::PARAM_INT_ARRAY))
616624
);
617625
}
618626
if (!empty($filter['status'])) {

openapi-full.json

Lines changed: 242 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4456,6 +4456,19 @@
44564456
"nullable": true
44574457
}
44584458
},
4459+
{
4460+
"name": "fileIds[]",
4461+
"in": "query",
4462+
"description": "The list of fileIds (database file IDs). It's the ids of LibreSign files",
4463+
"schema": {
4464+
"type": "array",
4465+
"nullable": true,
4466+
"items": {
4467+
"type": "integer",
4468+
"format": "int64"
4469+
}
4470+
}
4471+
},
44594472
{
44604473
"name": "nodeIds[]",
44614474
"in": "query",
@@ -4464,7 +4477,8 @@
44644477
"type": "array",
44654478
"nullable": true,
44664479
"items": {
4467-
"type": "string"
4480+
"type": "integer",
4481+
"format": "int64"
44684482
}
44694483
}
44704484
},
@@ -4819,6 +4833,233 @@
48194833
}
48204834
}
48214835
},
4836+
"/ocs/v2.php/apps/libresign/api/{apiVersion}/file/thumbnail/file_id/{fileId}": {
4837+
"get": {
4838+
"operationId": "file-get-thumbnail-by-file-id",
4839+
"summary": "Return the thumbnail of a LibreSign file by fileId",
4840+
"tags": [
4841+
"file"
4842+
],
4843+
"security": [
4844+
{
4845+
"bearer_auth": []
4846+
},
4847+
{
4848+
"basic_auth": []
4849+
}
4850+
],
4851+
"parameters": [
4852+
{
4853+
"name": "apiVersion",
4854+
"in": "path",
4855+
"required": true,
4856+
"schema": {
4857+
"type": "string",
4858+
"enum": [
4859+
"v1"
4860+
],
4861+
"default": "v1"
4862+
}
4863+
},
4864+
{
4865+
"name": "fileId",
4866+
"in": "path",
4867+
"description": "The LibreSign fileId (database id)",
4868+
"required": true,
4869+
"schema": {
4870+
"type": "integer",
4871+
"format": "int64",
4872+
"default": -1
4873+
}
4874+
},
4875+
{
4876+
"name": "x",
4877+
"in": "query",
4878+
"description": "Width of generated file",
4879+
"schema": {
4880+
"type": "integer",
4881+
"format": "int64",
4882+
"default": 32
4883+
}
4884+
},
4885+
{
4886+
"name": "y",
4887+
"in": "query",
4888+
"description": "Height of generated file",
4889+
"schema": {
4890+
"type": "integer",
4891+
"format": "int64",
4892+
"default": 32
4893+
}
4894+
},
4895+
{
4896+
"name": "a",
4897+
"in": "query",
4898+
"description": "Crop, boolean value, default false",
4899+
"schema": {
4900+
"type": "integer",
4901+
"default": 0,
4902+
"enum": [
4903+
0,
4904+
1
4905+
]
4906+
}
4907+
},
4908+
{
4909+
"name": "forceIcon",
4910+
"in": "query",
4911+
"description": "Force to generate a new thumbnail",
4912+
"schema": {
4913+
"type": "integer",
4914+
"default": 1,
4915+
"enum": [
4916+
0,
4917+
1
4918+
]
4919+
}
4920+
},
4921+
{
4922+
"name": "mode",
4923+
"in": "query",
4924+
"description": "To force a given mimetype for the file",
4925+
"schema": {
4926+
"type": "string",
4927+
"default": "fill"
4928+
}
4929+
},
4930+
{
4931+
"name": "mimeFallback",
4932+
"in": "query",
4933+
"description": "If we have no preview enabled, we can redirect to the mime icon if any",
4934+
"schema": {
4935+
"type": "integer",
4936+
"default": 0,
4937+
"enum": [
4938+
0,
4939+
1
4940+
]
4941+
}
4942+
},
4943+
{
4944+
"name": "OCS-APIRequest",
4945+
"in": "header",
4946+
"description": "Required to be true for the API request to pass",
4947+
"required": true,
4948+
"schema": {
4949+
"type": "boolean",
4950+
"default": true
4951+
}
4952+
}
4953+
],
4954+
"responses": {
4955+
"200": {
4956+
"description": "OK",
4957+
"content": {
4958+
"*/*": {
4959+
"schema": {
4960+
"type": "string",
4961+
"format": "binary"
4962+
}
4963+
}
4964+
}
4965+
},
4966+
"400": {
4967+
"description": "Bad request",
4968+
"content": {
4969+
"application/json": {
4970+
"schema": {
4971+
"type": "object",
4972+
"required": [
4973+
"ocs"
4974+
],
4975+
"properties": {
4976+
"ocs": {
4977+
"type": "object",
4978+
"required": [
4979+
"meta",
4980+
"data"
4981+
],
4982+
"properties": {
4983+
"meta": {
4984+
"$ref": "#/components/schemas/OCSMeta"
4985+
},
4986+
"data": {}
4987+
}
4988+
}
4989+
}
4990+
}
4991+
}
4992+
}
4993+
},
4994+
"403": {
4995+
"description": "Forbidden",
4996+
"content": {
4997+
"application/json": {
4998+
"schema": {
4999+
"type": "object",
5000+
"required": [
5001+
"ocs"
5002+
],
5003+
"properties": {
5004+
"ocs": {
5005+
"type": "object",
5006+
"required": [
5007+
"meta",
5008+
"data"
5009+
],
5010+
"properties": {
5011+
"meta": {
5012+
"$ref": "#/components/schemas/OCSMeta"
5013+
},
5014+
"data": {}
5015+
}
5016+
}
5017+
}
5018+
}
5019+
}
5020+
}
5021+
},
5022+
"404": {
5023+
"description": "Not found",
5024+
"content": {
5025+
"application/json": {
5026+
"schema": {
5027+
"type": "object",
5028+
"required": [
5029+
"ocs"
5030+
],
5031+
"properties": {
5032+
"ocs": {
5033+
"type": "object",
5034+
"required": [
5035+
"meta",
5036+
"data"
5037+
],
5038+
"properties": {
5039+
"meta": {
5040+
"$ref": "#/components/schemas/OCSMeta"
5041+
},
5042+
"data": {}
5043+
}
5044+
}
5045+
}
5046+
}
5047+
}
5048+
}
5049+
},
5050+
"303": {
5051+
"description": "Redirect",
5052+
"headers": {
5053+
"Location": {
5054+
"schema": {
5055+
"type": "string"
5056+
}
5057+
}
5058+
}
5059+
}
5060+
}
5061+
}
5062+
},
48225063
"/ocs/v2.php/apps/libresign/api/{apiVersion}/file": {
48235064
"post": {
48245065
"operationId": "file-save",

0 commit comments

Comments
 (0)