diff --git a/rest/index.php b/rest/index.php index 0d4874fa0d416db13c9149e121968a2bffc1d7fc..94f16e0d7f33173f6b2caefe54c805341cd86dc8 100755 --- a/rest/index.php +++ b/rest/index.php @@ -71,6 +71,7 @@ $app->get('/attachments/{id}/originalContent', \Attachment\controllers\Attachmen $app->get('/attachments/{id}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent'); $app->put('/attachments/{id}/inSendAttachment', \Attachment\controllers\AttachmentController::class . ':setInSendAttachment'); $app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes'); +$app->delete('/attachments/{id}', \Attachment\controllers\AttachmentController::class . ':delete'); //AutoComplete $app->get('/autocomplete/contacts', \SrcCore\controllers\AutoCompleteController::class . ':getContacts'); diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index e6fbc9fbd6148691425f5e044ae27aa7d0163706..868b302895495a8f534237b8c7553d8052a1bb9e 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -447,6 +447,43 @@ class AttachmentController return $response->withJson(['attachmentsTypes' => $attachmentsTypes]); } + public function delete(Request $request, Response $response, array $args) + { + if (!Validator::intVal()->notEmpty()->validate($args['id'])) { + return $response->withStatus(400)->withJson(['errors' => 'Route id must be an integer val']); + } + + $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['origin_id', 'res_id_master', 'attachment_type', 'res_id', 'title']]); + if (empty($attachment)) { + return $response->withStatus(400)->withJson(['errors' => 'Attachment not found']); + } + + if (!ResController::hasRightByResId(['resId' => [$attachment['res_id_master']], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + + if ($attachment['attachment_type'] == 'signed_response') { + AttachmentModel::delete(['id' => $attachment['res_id']]); + } else { + if (empty($attachment['origin_id'])) { + $idToDelete = $attachment['res_id']; + } else { + $idToDelete = $attachment['origin_id']; + } + + AttachmentModel::delete(['id' => $idToDelete]); + } + HistoryController::add([ + 'tableName' => 'res_attachments', + 'recordId' => $args['id'], + 'eventType' => 'DEL', + 'info' => _DOC_DELETED . " : {$attachment['title']}", + 'eventId' => 'attachmentSuppression', + ]); + + return $response->withStatus(204); + } + public static function getEncodedDocument(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['id']); diff --git a/src/app/attachment/models/AttachmentModelAbstract.php b/src/app/attachment/models/AttachmentModelAbstract.php index 728dbb5a753da757d37088f99926c68b75dd34bf..316259a7aa0938c587e4ca565248f48ea8cf87b1 100755 --- a/src/app/attachment/models/AttachmentModelAbstract.php +++ b/src/app/attachment/models/AttachmentModelAbstract.php @@ -284,4 +284,21 @@ abstract class AttachmentModelAbstract return true; } + + public static function delete(array $args) + { + ValidatorModel::notEmpty($args, ['id']); + ValidatorModel::intVal($args, ['id']); + + DatabaseModel::update([ + 'table' => 'res_attachments', + 'set' => [ + 'status' => 'DEL' + ], + 'where' => ['res_id = ? or origin_id = ?'], + 'data' => [$args['id'], $args['id']] + ]); + + return true; + } } diff --git a/src/core/lang/lang-en.php b/src/core/lang/lang-en.php index 1344a511bc77ae034fa7e3d457bf2b419024a178..d3124ff683e822f6ac4b17c8aa4768036fd474e4 100755 --- a/src/core/lang/lang-en.php +++ b/src/core/lang/lang-en.php @@ -141,6 +141,7 @@ define('_DOC_DISPLAYING', 'Displaying document'); define('_AR_DISPLAYING', 'Displaying acknowledgement receipt'); define('_DOC_ADDED', 'Document added'); define('_ATTACH_DISPLAYING', 'Displaying attachment'); +define('_DOC_DELETED', 'Document deleted'); define('_NOTE_ADDED', 'Note added'); define('_NOTE_UPDATED', 'Note updated'); define('_NOTE_DELETED', 'Note deleted'); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index f12a708090db7506309b32d74501b3be8a3e0d51..6ccffc0ed4311113c6edd2461642b31b2abec7b5 100755 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -141,6 +141,7 @@ define('_DOC_DISPLAYING', 'Visualisation du document'); define('_AR_DISPLAYING', 'Visualisation de l\'accusé de réception'); define('_DOC_ADDED', 'Document ajouté'); define('_ATTACH_DISPLAYING', 'Visualisation de la pièce jointe'); +define('_DOC_DELETED', 'Document supprimé'); define('_NOTE_ADDED', 'Annotation ajoutée'); define('_NOTE_UPDATED', 'Annotation modifiée'); define('_NOTE_DELETED', 'Annotation supprimée'); diff --git a/src/core/lang/lang-nl.php b/src/core/lang/lang-nl.php index 035537e54e1352f44ef3840612d6bdb3960061d5..30f486a288fc7b3bae6923f76148339d785058a9 100755 --- a/src/core/lang/lang-nl.php +++ b/src/core/lang/lang-nl.php @@ -140,6 +140,7 @@ define('_BACK_FROM_VACATION', 'bij terugkeer na afwezigheid'); define('_DOC_DISPLAYING', 'Weergave van het document'); define('_DOC_ADDED', 'Document toegevoegd'); define('_ATTACH_DISPLAYING', 'Weergave van de bijlage'); +define('_DOC_DELETED', 'Document deleted');//TRANSLATE define('_NOTE_ADDED', 'note added _TO_TRANSLATE'); define('_NOTE_UPDATED', 'Note updated');//TRANSLATE define('_NOTE_DELETED', 'Note deleted');//TRANSLATE