diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql index 0b0d469bb6bbb3db54a1d0430aa20d9f2ae1231b..2ed58e58e34daa2c51815982e064df832356aeba 100644 --- a/migration/19.12/1912.sql +++ b/migration/19.12/1912.sql @@ -231,8 +231,12 @@ END$$; /* ATTACHMENTS */ ALTER TABLE res_attachments DROP COLUMN IF EXISTS origin_id; ALTER TABLE res_attachments ADD COLUMN origin_id INTEGER; -ALTER TABLE res_attachments DROP COLUMN IF EXISTS modification_date; -ALTER TABLE res_attachments ADD modification_date timestamp without time zone DEFAULT NOW(); +DO $$ BEGIN + IF (SELECT count(attname) FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'res_attachments') AND attname = 'doc_date') THEN + ALTER TABLE res_attachments RENAME COLUMN doc_date TO modification_date; + ALTER TABLE res_attachments ALTER COLUMN modification_date set DEFAULT NOW(); + END IF; +END$$; /* DOCSERVERS */ diff --git a/sql/structure.sql b/sql/structure.sql index d11d19a08c1dc78cb48b53595d9e5b88b2ad3a5a..011ed856f089ed8e9dacabf875f813a65f012029 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -252,11 +252,11 @@ CREATE TABLE res_attachments format character varying(50) NOT NULL, typist character varying(128) NOT NULL, creation_date timestamp without time zone NOT NULL, + modification_date timestamp without time zone DEFAULT NOW(), author character varying(255) DEFAULT NULL::character varying, identifier character varying(255) DEFAULT NULL::character varying, source character varying(255) DEFAULT NULL::character varying, relation bigint, - doc_date timestamp without time zone, docserver_id character varying(32) NOT NULL, path character varying(255) DEFAULT NULL::character varying, filename character varying(255) DEFAULT NULL::character varying, diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index 1efe65c4d09f188a59f30115cceb43ec2f583de0..d76dd3cd3fc7b48d3190a62dbfdbace909d73cfc 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -123,15 +123,15 @@ class AttachmentController return $response->withStatus(204); } - public function getByResId(Request $request, Response $response, array $aArgs) + public function getByResId(Request $request, Response $response, array $args) { - if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => [$aArgs['resId']], 'userId' => $GLOBALS['id']])) { + if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } $queryParams = $request->getQueryParams(); if (!empty($queryParams['limit']) && !Validator::intVal()->validate($queryParams['limit'])) { - return $response->withStatus(403)->withJson(['errors' => 'Query limit is not an int val']); + return $response->withStatus(403)->withJson(['errors' => 'Query limit is not an integer']); } $excludeAttachmentTypes = ['converted_pdf', 'print_folder']; @@ -139,33 +139,36 @@ class AttachmentController $excludeAttachmentTypes[] = 'document_with_notes'; } - $attachments = AttachmentModel::getListByResIdMaster([ - 'resId' => $aArgs['resId'], - 'login' => $GLOBALS['userId'], - 'excludeAttachmentTypes' => $excludeAttachmentTypes, - 'orderBy' => ['res_id DESC'], - 'limit' => (int)$queryParams['limit'] + $attachments = AttachmentModel::get([ + 'select' => [ + 'res_id as "resId"', 'identifier as chrono', 'title', 'creation_date as "creationDate"', 'modification_date as "modificationDate"', + 'relation', 'status', 'attachment_type as type', 'origin_id as "originId"', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"' + ], + 'where' => ['res_id_master = ?', 'status not in (?)', 'attachment_type not in (?)'], + 'data' => [$args['resId'], ['DEL', 'OBS'], $excludeAttachmentTypes], + 'orderBy' => ['modification_date DESC'], + 'limit' => (int)$queryParams['limit'] ?? 0 ]); + $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); foreach ($attachments as $key => $attachment) { - $attachments[$key]['contact'] = ''; - if (!empty($attachment['dest_address_id'])) { - $contact = ContactModel::getOnView([ - 'select' => [ - 'is_corporate_person', 'lastname', 'firstname', - 'ca_id', 'society', 'contact_firstname', 'contact_lastname' + if (!empty($attachmentsTypes[$attachment['type']]['label'])) { + $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['type']]['label']; + } + + $oldVersions = []; + if (!empty($attachment['originId'])) { + $oldVersions = AttachmentModel::get([ + 'select' => [ + 'res_id as "resId"', 'identifier as chrono', 'title', 'creation_date as "creationDate"', 'modification_date as "modificationDate"', + 'relation', 'status', 'attachment_type as type' ], - 'where' => ['ca_id = ?'], - 'data' => [$attachment['dest_address_id']] + 'where' => ['(origin_id = ? OR res_id = ?)', 'res_id != ?', 'status not in (?)', 'attachment_type not in (?)'], + 'data' => [$attachment['originId'], $attachment['originId'], $attachment['resId'], ['DEL'], $excludeAttachmentTypes], + 'orderBy' => ['relation DESC'] ]); - if (!empty($contact[0])) { - $contact = AutoCompleteController::getFormattedContact(['contact' => $contact[0]]); - $attachments[$key]['contact'] = $contact['contact']['contact']; - } - } - if (!empty($attachmentsTypes[$attachment['attachment_type']]['label'])) { - $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['attachment_type']]['label']; } + $attachments[$key]['versions'] = $oldVersions; } $mailevaConfig = CoreConfigModel::getMailevaConfiguration(); @@ -722,6 +725,18 @@ class AttachmentController { $body = $args['body']; + if (!empty($body['validationDate'])) { + if (!Validator::date()->notEmpty()->validate($body['validationDate'])) { + return ['errors' => "Body validationDate is not a date"]; + } + } + + if (!empty($body['effectiveDate'])) { + if (!Validator::date()->notEmpty()->validate($body['effectiveDate'])) { + return ['errors' => "Body effectiveDate is not a date"]; + } + } + return true; } } diff --git a/src/app/attachment/models/AttachmentModelAbstract.php b/src/app/attachment/models/AttachmentModelAbstract.php index f5e65821d9cce0d7667fdb9f3c1687efb73bfb5c..c81333b2201b58047a266f1739dd129d16e0bcf5 100755 --- a/src/app/attachment/models/AttachmentModelAbstract.php +++ b/src/app/attachment/models/AttachmentModelAbstract.php @@ -85,14 +85,10 @@ abstract class AttachmentModelAbstract $aAttachments = DatabaseModel::select([ 'select' => [ - 'res_id', 'res_attachments.identifier', 'title', 'format', 'creation_date', - 'doc_date as update_date', 'validation_date as return_date', 'effective_date as real_return_date', - 'u.firstname as firstname_updated', 'u.lastname as lastname_updated', 'relation', 'docserver_id', 'path', - 'filename', 'fingerprint', 'filesize', 'label_status as status', 'attachment_type', 'dest_contact_id', - 'dest_address_id', 'ut.firstname as firstname_typist', 'ut.lastname as lastname_typist', 'in_signature_book', 'in_send_attach' + 'res_id', 'identifier', 'title', 'creation_date', 'modification_date', 'validation_date as return_date', 'effective_date as real_return_date', + 'relation', 'status', 'attachment_type', 'in_signature_book', 'in_send_attach' ], - 'table' => ['res_attachments', 'users ut', 'status', 'users u'], - 'left_join' => ['res_attachments.typist = ut.user_id', 'res_attachments.status = status.id', 'res_attachments.updated_by = u.user_id'], + 'table' => ['res_attachments'], 'where' => ['res_id_master = ?', 'res_attachments.status not in (?)', 'attachment_type not in (?)', '((res_attachments.status = ? AND typist = ?) OR res_attachments.status != ?)'], 'data' => [$aArgs['resId'], ['OBS', 'DEL'], $aArgs['excludeAttachmentTypes'], 'TMP', $aArgs['login'], 'TMP'], 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php index d17b51e6d7885bc19648a77e6b0f54248124a1b2..dd124faa097cc7bfff35cb970bcf72c0d64c2a2f 100755 --- a/src/app/resource/controllers/StoreController.php +++ b/src/app/resource/controllers/StoreController.php @@ -204,6 +204,8 @@ class StoreController 'origin_id' => $args['originId'] ?? null, 'res_id_master' => $args['resIdMaster'], 'attachment_type' => $args['type'], + 'validation_date' => $args['validationDate'] ?? null, + 'effective_date' => $args['effectiveDate'] ?? null, 'in_signature_book' => empty($args['inSignatureBook']) ? 'false' : 'true', 'external_id' => $externalId, 'format' => $args['format'], diff --git a/src/core/models/DatabasePDO.php b/src/core/models/DatabasePDO.php index 368ae59ecf5b1b338aba57b2e0ff96f7ecbfae95..eeeee256ab5d35521eaecc78b42d501a0576adc6 100755 --- a/src/core/models/DatabasePDO.php +++ b/src/core/models/DatabasePDO.php @@ -101,7 +101,7 @@ class DatabasePDO $options = [ \PDO::ATTR_PERSISTENT => true, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_CASE => \PDO::CASE_LOWER + \PDO::ATTR_CASE => \PDO::CASE_NATURAL ]; try { diff --git a/src/frontend/app/administration/docserver/docserver-administration.component.html b/src/frontend/app/administration/docserver/docserver-administration.component.html index feea159f59bf70dae1134cbf035c9ba721a9b68a..25ce1132ccad6ae6c10a6ade89669f2c8d4c765a 100755 --- a/src/frontend/app/administration/docserver/docserver-administration.component.html +++ b/src/frontend/app/administration/docserver/docserver-administration.component.html @@ -38,9 +38,6 @@ <mat-option value="attachments_coll"> attachments_coll </mat-option> - <mat-option value="attachments_version_coll"> - attachments_version_coll - </mat-option> <mat-option value="archive_transfer_coll"> archive_transfer_coll </mat-option> @@ -64,4 +61,4 @@ </mat-card> </mat-sidenav-content> </mat-sidenav-container> -</div> \ No newline at end of file +</div>