diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index fa22d52ba6494cd769d5b2a728ea8ef4e0fa67e7..cb25ff59e16a49df962fc1aae5678d000a3a6c4f 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -485,7 +485,7 @@ class AttachmentController } $attachment = AttachmentModel::get([ - 'select' => ['res_id', 'docserver_id', 'res_id_master', 'format', 'title', 'signatory_user_serial_id'], + 'select' => ['res_id', 'docserver_id', 'res_id_master', 'format', 'title', 'signatory_user_serial_id', 'typist', 'attachment_type'], 'where' => ['res_id = ?', 'status not in (?)'], 'data' => [$args['id'], ['DEL']], 'limit' => 1 @@ -553,11 +553,19 @@ class AttachmentController $mimeType = $finfo->buffer($fileContent); if ($data['mode'] == 'base64') { + if ($attachment['attachment_type'] == 'signed_response') { + if (!empty($attachment['signatory_user_serial_id'])) { + $signatoryId = $attachment['signatory_user_serial_id']; + } else { + $signatoryId = $attachment['typist']; + } + } + return $response->withJson([ 'encodedDocument' => base64_encode($fileContent), 'originalFormat' => $attachment['format'], 'mimeType' => $mimeType, - 'signatoryId' => $attachment['signatory_user_serial_id'] + 'signatoryId' => $signatoryId ]); } else { $pathInfo = pathinfo($pathToDocument); diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php index 2f694005f6957bd0dc70b234b597cd56a7fc1e9a..30f5534d74791b8c3221ece4a4187880a69c7b7c 100755 --- a/src/app/signatureBook/controllers/SignatureBookController.php +++ b/src/app/signatureBook/controllers/SignatureBookController.php @@ -673,14 +673,14 @@ class SignatureBookController $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['res_id_master']]); $signedDocument = AttachmentModel::get([ - 'select' => ['signatory_user_serial_id'], + 'select' => ['signatory_user_serial_id', 'typist'], 'where' => ['origin = ?', 'status != ?'], 'data' => ["{$args['id']},res_attachments", 'DEL'] ]); if (empty($attachment) || !ResController::hasRightByResId(['resId' => [$attachment['res_id_master']], 'userId' => $GLOBALS['id']])) { return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } elseif ($signedDocument[0]['signatory_user_serial_id'] != $GLOBALS['id']) { + } elseif ($signedDocument[0]['signatory_user_serial_id'] != $GLOBALS['id'] && $signedDocument[0]['typist'] != $GLOBALS['id']) { return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); }