Commit d0fde705 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #17080 TIME 1:45 save document original name

parent 1216568f
......@@ -279,6 +279,7 @@ CREATE TABLE res_attachments
signatory_user_serial_id int,
fulltext_result character varying(10) DEFAULT NULL::character varying,
external_id jsonb DEFAULT '{}',
original_filename character varying(255) DEFAULT NULL::character varying,
CONSTRAINT res_attachments_pkey PRIMARY KEY (res_id)
)
WITH (OIDS=FALSE);
......@@ -924,6 +925,7 @@ CREATE TABLE res_letterbox
linked_resources jsonb NOT NULL DEFAULT '[]',
retention_frozen boolean DEFAULT FALSE NOT NULL,
binding boolean,
original_filename character varying(255) DEFAULT NULL::character varying,
CONSTRAINT res_letterbox_pkey PRIMARY KEY (res_id)
)
WITH (OIDS=FALSE);
......
......@@ -94,7 +94,7 @@ class AttachmentController
'select' => [
'res_id as "resId"', 'res_id_master as "resIdMaster"', 'status', 'title', 'identifier as chrono', 'typist', 'modified_by as "modifiedBy"', 'relation', 'attachment_type as type',
'recipient_id as "recipientId"', 'recipient_type as "recipientType"', 'origin_id as "originId"', 'creation_date as "creationDate"', 'modification_date as "modificationDate"',
'validation_date as "validationDate"', 'format', 'fulltext_result as "fulltextResult"', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"'
'validation_date as "validationDate"', 'format', 'fulltext_result as "fulltextResult"', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"', 'original_filename as "originalFilename"'
]
]);
if (empty($attachment) || in_array($attachment['status'], ['DEL', 'OBS'])) {
......@@ -519,7 +519,7 @@ class AttachmentController
}
$attachment = AttachmentModel::get([
'select' => ['res_id', 'docserver_id', 'res_id_master', 'format', 'title', 'signatory_user_serial_id', 'typist', 'attachment_type'],
'select' => ['res_id', 'docserver_id', 'res_id_master', 'format', 'title', 'signatory_user_serial_id', 'typist', 'attachment_type', 'original_filename'],
'where' => ['res_id = ?', 'status not in (?)'],
'data' => [$args['id'], ['DEL']],
'limit' => 1
......@@ -585,7 +585,8 @@ class AttachmentController
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($fileContent);
$filename = TextFormatModel::formatFilename(['filename' => $attachment['title'], 'maxLength' => 250]);
$filename = !empty($attachment['original_filename']) ? $attachment['original_filename'] : $attachment['title'];
$filename = TextFormatModel::formatFilename(['filename' => $filename, 'maxLength' => 250]);
if ($data['mode'] == 'base64') {
if ($attachment['attachment_type'] == 'signed_response') {
......@@ -619,7 +620,7 @@ class AttachmentController
}
$attachment = AttachmentModel::get([
'select' => ['res_id', 'docserver_id', 'path', 'filename', 'res_id_master', 'title', 'fingerprint', 'relation'],
'select' => ['res_id', 'docserver_id', 'path', 'filename', 'res_id_master', 'title', 'fingerprint', 'relation', 'original_filename'],
'where' => ['res_id = ?', 'status not in (?)'],
'data' => [$args['id'], ['DEL']],
'limit' => 1
......@@ -673,7 +674,8 @@ class AttachmentController
$mimeType = $finfo->buffer($fileContent);
$pathInfo = pathinfo($pathToDocument);
$data = $request->getQueryParams();
$filename = TextFormatModel::formatFilename(['filename' => $attachmentTodisplay['title'], 'maxLength' => 250]);
$filename = !empty($attachmentTodisplay['original_filename']) ? $attachmentTodisplay['original_filename'] : $attachmentTodisplay['title'];
$filename = TextFormatModel::formatFilename(['filename' => $filename, 'maxLength' => 250]);
if ($attachmentTodisplay['relation'] > 1) {
$filename .= '_V' . $attachmentTodisplay['relation'];
} else {
......@@ -751,7 +753,7 @@ class AttachmentController
ValidatorModel::intVal($args, ['id']);
ValidatorModel::boolType($args, ['original']);
$document = AttachmentModel::getById(['select' => ['docserver_id', 'path', 'filename', 'title', 'status', 'fingerprint'], 'id' => $args['id']]);
$document = AttachmentModel::getById(['select' => ['docserver_id', 'path', 'filename', 'title', 'status', 'fingerprint', 'original_filename'], 'id' => $args['id']]);
if (empty($args['original'])) {
if ($document['status'] == 'SIGN') {
......@@ -801,8 +803,9 @@ class AttachmentController
$encodedDocument = base64_encode($fileContent);
if (!empty($document['title'])) {
$document['title'] = TextFormatModel::formatFilename(['filename' => $document['title'], 'maxLength' => 30]);
if (!empty($document['title']) || !empty($document['original_filename'])) {
$document['title'] = !empty($document['original_filename']) ? $document['original_filename'] : $document['title'];
$document['title'] = TextFormatModel::formatFilename(['filename' => $document['title'], 'maxLength' => 250]);
}
$pathInfo = pathinfo($pathToDocument);
......@@ -1003,6 +1006,10 @@ class AttachmentController
}
}
if (!empty($body['originalFilename']) && !Validator::stringType()->length(1, 255)->validate($body['format'])) {
return ['errors' => 'Body originalName is not a string or is more than 255 characters'];
}
return true;
}
......
......@@ -434,7 +434,7 @@ class ResController extends ResourceControlController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$document = ResModel::getById(['select' => ['filename', 'format', 'typist', 'subject'], 'resId' => $aArgs['resId']]);
$document = ResModel::getById(['select' => ['filename', 'format', 'typist', 'subject', 'original_filename'], 'resId' => $aArgs['resId']]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
} elseif (empty($document['filename'])) {
......@@ -443,6 +443,7 @@ class ResController extends ResourceControlController
$originalFormat = $document['format'];
$creatorId = $document['typist'];
$subject = $document['subject'];
$originalFilename = $document['originalFilename'] ?? null;
$convertedDocument = ConvertPdfController::getConvertedPdfById(['resId' => $aArgs['resId'], 'collId' => 'letterbox_coll']);
if (!empty($convertedDocument['errors'])) {
......@@ -489,7 +490,8 @@ class ResController extends ResourceControlController
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($fileContent);
$filename = TextFormatModel::formatFilename(['filename' => $subject, 'maxLength' => 250]);
$filename = !empty($originalFilename) ? $originalFilename : $subject;
$filename = TextFormatModel::formatFilename(['filename' => $filename, 'maxLength' => 250]);
if ($data['mode'] == 'base64') {
$listInstance = ListInstanceModel::get([
......@@ -569,7 +571,7 @@ class ResController extends ResourceControlController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['version', 'filename', 'subject']]);
$resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['version', 'filename', 'subject', 'original_filename']]);
if (empty($resource['filename'])) {
return $response->withStatus(400)->withJson(['errors' => 'Document has no file']);
} elseif (!Validator::intVal()->validate($args['version']) || $args['version'] > $resource['version'] || $args['version'] < 1) {
......@@ -578,6 +580,7 @@ class ResController extends ResourceControlController
$queryParams = $request->getQueryParams();
$subject = $resource['subject'];
$originalFilename = $resource['original_filename'];
$type = 'PDF';
if (!empty($queryParams['type']) && in_array($queryParams['type'], ['PDF', 'SIGN', 'NOTE'])) {
......@@ -628,7 +631,8 @@ class ResController extends ResourceControlController
}
$pathInfo = pathinfo($pathToDocument);
$filename = TextFormatModel::formatFilename(['filename' => $subject, 'maxLength' => 250]);
$filename = !empty($originalFilename) ? $originalFilename : $subject;
$filename = TextFormatModel::formatFilename(['filename' => $filename, 'maxLength' => 250]);
return $response->withJson(['encodedDocument' => base64_encode($fileContent), 'filename' => $filename.'_V'.$args['version'].'.'.$pathInfo['extension']]);
}
......@@ -638,7 +642,7 @@ class ResController extends ResourceControlController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$document = ResModel::getById(['select' => ['docserver_id', 'path', 'filename', 'category_id', 'version', 'fingerprint', 'subject'], 'resId' => $args['resId']]);
$document = ResModel::getById(['select' => ['docserver_id', 'path', 'filename', 'category_id', 'version', 'fingerprint', 'subject', 'original_filename'], 'resId' => $args['resId']]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
......@@ -647,6 +651,7 @@ class ResController extends ResourceControlController
return $response->withStatus(400)->withJson(['errors' => 'Document has no file']);
}
$subject = $document['subject'];
$originalFilename = $document['original_filename'];
$convertedDocument = AdrModel::getDocuments([
'select' => ['docserver_id', 'path', 'filename', 'fingerprint'],
......@@ -695,7 +700,8 @@ class ResController extends ResourceControlController
$mimeType = $finfo->buffer($fileContent);
$pathInfo = pathinfo($pathToDocument);
$data = $request->getQueryParams();
$filename = TextFormatModel::formatFilename(['filename' => $subject, 'maxLength' => 250]);
$filename = !empty($originalFilename) ? $originalFilename : $subject;
$filename = TextFormatModel::formatFilename(['filename' => $filename, 'maxLength' => 250]);
if ($data['mode'] == 'base64') {
return $response->withJson(['encodedDocument' => base64_encode($fileContent), 'extension' => $pathInfo['extension'], 'mimeType' => $mimeType, 'filename' => $filename.'.'.$pathInfo['extension']]);
......@@ -989,7 +995,7 @@ class ResController extends ResourceControlController
ValidatorModel::intVal($aArgs, ['resId']);
ValidatorModel::boolType($aArgs, ['original']);
$document = ResModel::getById(['select' => ['docserver_id', 'path', 'filename', 'subject', 'fingerprint'], 'resId' => $aArgs['resId']]);
$document = ResModel::getById(['select' => ['docserver_id', 'path', 'filename', 'subject', 'fingerprint', 'original_filename'], 'resId' => $aArgs['resId']]);
if (empty($aArgs['original'])) {
$convertedDocument = ConvertPdfController::getConvertedPdfById(['resId' => $aArgs['resId'], 'collId' => 'letterbox_coll']);
......@@ -1030,6 +1036,7 @@ class ResController extends ResourceControlController
$encodedDocument = base64_encode($fileContent);
if (!empty($document['subject'])) {
$document['subject'] = !empty($document['original_filename']) ? $document['original_filename'] : $document['subject'];
$document['subject'] = TextFormatModel::formatFilename(['filename' => $document['subject'], 'maxLength' => 30]);
}
......@@ -1352,7 +1359,7 @@ class ResController extends ResourceControlController
$resource = ResModel::getById([
'resId' => $args['resId'],
'select' => ['format', 'fingerprint', 'filesize', 'fulltext_result', 'creation_date', 'filename', 'docserver_id', 'path', 'typist']
'select' => ['format', 'fingerprint', 'filesize', 'fulltext_result', 'creation_date', 'filename', 'docserver_id', 'path', 'typist', 'original_filename']
]);
if (!empty($resource['docserver_id'])) {
......@@ -1365,6 +1372,8 @@ class ResController extends ResourceControlController
$resource['typistLabel'] = UserModel::getLabelledUserById(['id' => $resource['typist']]);
$resource['creationDate'] = $resource['creation_date'];
unset($resource['creation_date']);
$resource['originalFilename'] = $resource['original_filename'];
unset($resource['original_filename']);
$allowedFiles = StoreController::getAllowedFiles();
$allowedFiles = array_column($allowedFiles, 'canConvert', 'extension');
......
......@@ -255,6 +255,10 @@ class ResourceControlController
}
}
if (!empty($body['originalFilename']) && !Validator::stringType()->length(1, 255)->validate($body['format'])) {
return ['errors' => 'Body originalName is not a string or is more than 255 characters'];
}
return true;
}
......
......@@ -254,7 +254,8 @@ class StoreController
'integrations' => json_encode($integrations),
'linked_resources' => !empty($args['linkedResources']) ? json_encode($args['linkedResources']) : '[]',
'external_id' => $externalId,
'creation_date' => 'CURRENT_TIMESTAMP'
'creation_date' => 'CURRENT_TIMESTAMP',
'original_filename' => $args['originalFilename'] ?? null
];
return $preparedData;
......@@ -426,7 +427,8 @@ class StoreController
'in_signature_book' => $inSignatureBook ? 'true' : 'false',
'external_id' => $externalId,
'creation_date' => 'CURRENT_TIMESTAMP',
'signatory_user_serial_id' => !empty($args['signatory_user_serial_id']) ? $args['signatory_user_serial_id'] : null
'signatory_user_serial_id' => !empty($args['signatory_user_serial_id']) ? $args['signatory_user_serial_id'] : null,
'original_filename' => $args['originalFilename'] ?? null
];
return $preparedData;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment