Commit 4be1a9da authored by Guillaume Heurtier's avatar Guillaume Heurtier

FIX #11691 TIME 3:00 added delete attachment

parent f2dfe9b9
......@@ -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');
......
......@@ -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']);
......
......@@ -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;
}
}
......@@ -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');
......
......@@ -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');
......
......@@ -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
......
Markdown is supported
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