Skip to content
Snippets Groups Projects
Verified Commit b2fad173 authored by Damien's avatar Damien
Browse files

FEAT #12346 TIME 1:20 Resource modification & only documents

parent 41163ce9
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ namespace ContentManagement\controllers;
use Attachment\models\AttachmentModel;
use Docserver\models\DocserverModel;
use Resource\controllers\ResController;
use Resource\models\ResModel;
use Slim\Http\Request;
use Slim\Http\Response;
use SrcCore\controllers\UrlController;
......@@ -254,6 +255,23 @@ class JnlpController
file_put_contents($tmpPath . $newFileOnTmp, base64_decode($mergedDocument['encodedDocument']));
$pathToCopy = $tmpPath . $newFileOnTmp;
} elseif ($queryParams['objectType'] == 'resourceModification') {
if (!ResController::hasRightByResId(['resId' => [$queryParams['objectId']], 'userId' => $GLOBALS['id']])) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Resource out of perimeter"]]);
$response->write($xmlResponse);
return $response->withHeader('Content-Type', 'application/xml');
}
$resource = ResModel::getById(['resId' => $body['objectId'], 'select' => ['docserver_id', 'path', 'filename']]);
if (empty($resource['filename'])) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Resource has no file"]]);
$response->write($xmlResponse);
return $response->withHeader('Content-Type', 'application/xml');
}
$docserver = DocserverModel::getByDocserverId(['docserverId' => $resource['docserver_id'], 'select' => ['path_template']]);
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $resource['path']) . $resource['filename'];
$extension = pathinfo($pathToCopy, PATHINFO_EXTENSION);
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$extension}";
} elseif ($queryParams['objectType'] == 'attachmentModification') {
$attachment = AttachmentModel::getById(['id' => $queryParams['objectId'], 'select' => ['docserver_id', 'path', 'filename', 'res_id_master']]);
if (empty($attachment)) {
......@@ -268,7 +286,6 @@ class JnlpController
}
$docserver = DocserverModel::getByDocserverId(['docserverId' => $attachment['docserver_id'], 'select' => ['path_template']]);
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $attachment['path']) . $attachment['filename'];
$extension = pathinfo($pathToCopy, PATHINFO_EXTENSION);
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$extension}";
......
......@@ -17,6 +17,7 @@ namespace ContentManagement\controllers;
use Attachment\models\AttachmentModel;
use Docserver\models\DocserverModel;
use Resource\controllers\ResController;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use Slim\Http\Request;
use Slim\Http\Response;
......@@ -87,6 +88,19 @@ class OnlyOfficeController
'data' => $dataToMerge
]);
$fileContent = base64_decode($mergedDocument['encodedDocument']);
} elseif ($body['objectType'] == 'resourceModification') {
if (!ResController::hasRightByResId(['resId' => [$body['objectId']], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(400)->withJson(['errors' => 'Resource out of perimeter']);
}
$resource = ResModel::getById(['resId' => $body['objectId'], 'select' => ['docserver_id', 'path', 'filename']]);
if (empty($resource['filename'])) {
return $response->withStatus(400)->withJson(['errors' => 'Resource has no file']);
}
$docserver = DocserverModel::getByDocserverId(['docserverId' => $resource['docserver_id'], 'select' => ['path_template']]);
$path = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $resource['path']) . $resource['filename'];
$fileContent = file_get_contents($path);
} elseif ($body['objectType'] == 'attachmentModification') {
$attachment = AttachmentModel::getById(['id' => $body['objectId'], 'select' => ['docserver_id', 'path', 'filename', 'res_id_master']]);
if (empty($attachment)) {
......
......@@ -209,7 +209,7 @@ class ConvertPdfController
return $convertedDocument;
}
private static function canConvert(array $args)
public static function canConvert(array $args)
{
ValidatorModel::notEmpty($args, ['extension']);
ValidatorModel::stringType($args, ['extension']);
......@@ -220,6 +220,7 @@ class ConvertPdfController
foreach ($loadedXml->FORMAT as $value) {
if (strtoupper((string)$value->name) == strtoupper($args['extension']) && (string)$value->canConvert == 'true') {
$canConvert = true;
break;
}
}
}
......
......@@ -250,7 +250,9 @@ class ResController extends ResourceControlController
unset($body['diffusionList']);
}
$control = ResourceControlController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'isProcessing' => $isProcessing]);
$onlyDocument = !empty($queryParams['onlyDocument']);
$control = ResourceControlController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'isProcessing' => $isProcessing, 'onlyDocument' => $onlyDocument]);
if (!empty($control['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
}
......@@ -268,15 +270,23 @@ class ResController extends ResourceControlController
]);
}
if ($onlyDocument) {
$body = [
'encodedFile' => $body['encodedFile'],
'format' => $body['format']
];
}
$body['resId'] = $args['resId'];
$resId = StoreController::storeResource($body);
if (empty($resId) || !empty($resId['errors'])) {
return $response->withStatus(500)->withJson(['errors' => '[ResController update] ' . $resId['errors']]);
}
ResController::updateAdjacentData(['body' => $body, 'resId' => $args['resId']]);
if (!$onlyDocument) {
ResController::updateAdjacentData(['body' => $body, 'resId' => $args['resId']]);
}
if (!empty($body['encodedFile'])) {
if ($onlyDocument) {
ConvertPdfController::convert([
'resId' => $args['resId'],
'collId' => 'letterbox_coll',
......
......@@ -15,6 +15,7 @@
namespace Resource\controllers;
use Contact\models\ContactModel;
use Convert\controllers\ConvertPdfController;
use Convert\models\AdrModel;
use CustomField\models\CustomFieldModel;
use Doctype\models\DoctypeModel;
......@@ -118,7 +119,11 @@ class ResourceControlController
{
$body = $args['body'];
$resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['status', 'model_id', 'external_signatory_book_id']]);
if (empty($body)) {
return ['errors' => 'Body is not set or empty'];
}
$resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['status', 'model_id', 'external_signatory_book_id', 'format']]);
if (empty($resource['status'])) {
return ['errors' => 'Resource status is empty. It can not be modified'];
}
......@@ -127,26 +132,33 @@ class ResourceControlController
return ['errors' => 'Resource can not be modified because of status'];
}
if (empty($body)) {
return ['errors' => 'Body is not set or empty'];
} elseif (!Validator::intVal()->notEmpty()->validate($body['doctype'])) {
return ['errors' => 'Body doctype is empty or not an integer'];
} elseif (!empty($body['encodedFile']) && !empty($resource['external_signatory_book_id'])) {
return ['errors' => 'Resource is in external signature book, file can not be modified'];
} elseif (!empty($body['encodedFile']) && ResourceControlController::isSigned(['resId' => $args['resId']])) {
return ['errors' => 'Resource is signed, file can not be modified'];
if ($args['onlyDocument'] && empty($body['encodedFile'])) {
return ['errors' => 'Body encodedFile is not set or empty'];
} elseif (!empty($body['encodedFile'])) {
if (!empty($resource['external_signatory_book_id'])) {
return ['errors' => 'Resource is in external signature book, file can not be modified'];
} elseif (ResourceControlController::isSigned(['resId' => $args['resId']])) {
return ['errors' => 'Resource is signed, file can not be modified'];
} elseif (!empty($resource['format']) && !ConvertPdfController::canConvert(['extension' => $resource['format']])) {
return ['errors' => 'Resource is not convertible, file can not be modified'];
}
$control = ResourceControlController::controlFileData(['body' => $body]);
if (!empty($control['errors'])) {
return ['errors' => $control['errors']];
}
if ($args['onlyDocument']) {
return true;
}
}
if (!Validator::intVal()->notEmpty()->validate($body['doctype'])) {
return ['errors' => 'Body doctype is empty or not an integer'];
}
$doctype = DoctypeModel::getById(['id' => $body['doctype'], 'select' => [1]]);
if (empty($doctype)) {
return ['errors' => 'Body doctype does not exist'];
}
$control = ResourceControlController::controlFileData(['body' => $body]);
if (!empty($control['errors'])) {
return ['errors' => $control['errors']];
}
$control = ResourceControlController::controlAdjacentData(['body' => $body, 'isWebServiceUser' => false]);
if (!empty($control['errors'])) {
return ['errors' => $control['errors']];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment