From 9a4b60cef18af0405feaf00a46bf8e10e39de0cf Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Thu, 22 Oct 2020 00:30:26 +0200 Subject: [PATCH] FEAT #15056 TIME 0:25 back - admin customization parameters for (non)binding Document Final Action --- migration/20.10/2010.sql | 5 ++ sql/data_fr.sql | 2 + .../controllers/ParameterController.php | 53 ++++++++++++------- .../search/controllers/SearchController.php | 19 ++++--- .../parameters-administration.component.ts | 4 +- 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/migration/20.10/2010.sql b/migration/20.10/2010.sql index 502e82c6a20..1a78526a13c 100755 --- a/migration/20.10/2010.sql +++ b/migration/20.10/2010.sql @@ -299,6 +299,11 @@ ALTER TABLE res_letterbox ADD COLUMN retention_frozen boolean DEFAULT FALSE NOT ALTER TABLE res_letterbox DROP COLUMN IF EXISTS binding; ALTER TABLE res_letterbox ADD COLUMN binding boolean; +DELETE FROM parameters WHERE id = 'bindingDocumentFinalAction'; +INSERT INTO parameters (id, param_value_string) VALUES ('bindingDocumentFinalAction', 'copy'); +DELETE FROM parameters WHERE id = 'nonBindingDocumentFinalAction'; +INSERT INTO parameters (id, param_value_string) VALUES ('nonBindingDocumentFinalAction', 'delete'); + /* CUSTOM FIELDS */ ALTER TABLE custom_fields DROP COLUMN IF EXISTS mode; DROP TYPE IF EXISTS custom_fields_modes; diff --git a/sql/data_fr.sql b/sql/data_fr.sql index 43146cbfd93..54a596efda2 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -1024,6 +1024,8 @@ INSERT INTO parameters (id, param_value_string) VALUES ('registeredMailNotDistri INSERT INTO parameters (id, param_value_string) VALUES ('registeredMailDistributedStatus', 'DSTRIBUTED'); INSERT INTO parameters (id, param_value_string) VALUES ('registeredMailImportedStatus', 'NEW'); INSERT INTO parameters (id, description, param_value_int) VALUES ('keepDiffusionRoleInOutgoingIndexation', 'Si activé (1), prend en compte les roles du modèle de diffusion de l''entité.', 1); +INSERT INTO parameters (id, param_value_string) VALUES ('bindingDocumentFinalAction', 'copy'); +INSERT INTO parameters (id, param_value_string) VALUES ('nonBindingDocumentFinalAction', 'delete'); ------------ --DIFFLIST_TYPES diff --git a/src/app/parameter/controllers/ParameterController.php b/src/app/parameter/controllers/ParameterController.php index c47ccf679d4..e76af5c462f 100755 --- a/src/app/parameter/controllers/ParameterController.php +++ b/src/app/parameter/controllers/ParameterController.php @@ -104,7 +104,7 @@ class ParameterController $body = $request->getParsedBody(); - if (in_array($args['id'], ['logo', 'bodyImage', 'applicationName'])) { + if (in_array($args['id'], ['logo', 'bodyImage', 'applicationName', 'bindingDocumentFinalAction', 'nonBindingDocumentFinalAction'])) { $customId = CoreConfigModel::getCustomId(); if (empty($customId)) { return $response->withStatus(400)->withJson(['errors' => 'A custom is needed for this operation']); @@ -118,9 +118,9 @@ class ParameterController if (strpos($body['image'], 'data:image/svg+xml;base64,') === false) { return $response->withStatus(400)->withJson(['errors' => 'Body image is not a base64 image']); } - $tmpFileName = $tmpPath . 'parameter_logo_' . rand() . '_file.svg'; + $tmpFileName = $tmpPath . 'parameter_logo_' . rand() . '_file.svg'; $body['logo'] = str_replace('data:image/svg+xml;base64,', '', $body['image']); - $file = base64_decode($body['logo']); + $file = base64_decode($body['logo']); file_put_contents($tmpFileName, $file); $size = strlen($file); @@ -135,12 +135,12 @@ class ParameterController } copy("dist/{$body['image']}", "custom/{$customId}/img/bodylogin.jpg"); } else { - $tmpFileName = $tmpPath . 'parameter_body_' . rand() . '_file.jpg'; + $tmpFileName = $tmpPath . 'parameter_body_' . rand() . '_file.jpg'; $body['image'] = str_replace('data:image/jpeg;base64,', '', $body['image']); - $file = base64_decode($body['image']); + $file = base64_decode($body['image']); file_put_contents($tmpFileName, $file); - $size = strlen($file); + $size = strlen($file); $imageSizes = getimagesize($tmpFileName); if ($imageSizes[0] < 1920 || $imageSizes[1] < 1080) { return $response->withStatus(400)->withJson(['errors' => 'Body image is not wide enough']); @@ -155,26 +155,39 @@ class ParameterController $fp = fopen("custom/{$customId}/apps/maarch_entreprise/xml/config.json", 'w'); fwrite($fp, json_encode($config, JSON_PRETTY_PRINT)); fclose($fp); + } elseif (in_array($args['id'] == ['bindingDocumentFinalAction', 'nonBindingDocumentFinalAction'])) { + $parameter = ParameterModel::getById(['id' => $args['id']]); + if (empty($parameter)) { + return $response->withStatus(400)->withJson(['errors' => 'Parameter not found']); + } + if (!in_array($body['param_value_string'], ['restrictAccess', 'transfer', 'copy', 'delete'])) { + return $response->withStatus(400)->withJson(['errors' => 'param_value_string must be between : restrictAccess, transfer, copy, delete']); + } + ParameterModel::update([ + 'description' => '', + 'param_value_string' => $body['param_value_string'], + 'id' => $args['id'] + ]); } if (!empty($tmpFileName) && is_file($tmpFileName)) { unset($tmpFileName); } - return $response->withStatus(204); - } - - $parameter = ParameterModel::getById(['id' => $args['id']]); - if (empty($parameter)) { - return $response->withStatus(400)->withJson(['errors' => 'Parameter not found']); - } - - $check = (empty($body['param_value_int']) || Validator::intVal()->validate($body['param_value_int'])); - $check = $check && (empty($body['param_value_string']) || Validator::stringType()->validate($body['param_value_string'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); + } else { + $parameter = ParameterModel::getById(['id' => $args['id']]); + if (empty($parameter)) { + return $response->withStatus(400)->withJson(['errors' => 'Parameter not found']); + } + + $check = (empty($body['param_value_int']) || Validator::intVal()->validate($body['param_value_int'])); + $check = $check && (empty($body['param_value_string']) || Validator::stringType()->validate($body['param_value_string'])); + if (!$check) { + return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); + } + + $body['id'] = $args['id']; + ParameterModel::update($body); } - $body['id'] = $args['id']; - ParameterModel::update($body); HistoryController::add([ 'tableName' => 'parameters', 'recordId' => $args['id'], diff --git a/src/app/search/controllers/SearchController.php b/src/app/search/controllers/SearchController.php index 38c65130476..5cf79f9750a 100644 --- a/src/app/search/controllers/SearchController.php +++ b/src/app/search/controllers/SearchController.php @@ -471,19 +471,22 @@ class SearchController $args['searchWhere'][] = '(' . implode(' OR ', $bindingWhere) . ')'; } if (!empty($body['retentionFrozen']) && !empty($body['retentionFrozen']['values']) && is_array($body['retentionFrozen']['values'])) { - $retentionRuleFrozenData = []; + $retentionFrozenData = []; + $retentionFrozenWhere = []; if (in_array(true, $body['retentionFrozen']['values'], true)) { - $retentionRuleFrozenData[] = 'true'; + $retentionFrozenData[] = 'true'; } if (in_array(false, $body['retentionFrozen']['values'], true)) { - $retentionRuleFrozenData[] = 'false'; + $retentionFrozenData[] = 'false'; } - if (in_array(null, $body['retentionFrozen']['values'])) { - $args['searchWhere'][] = '(retention_frozen in (?) OR retention_frozen is NULL)'; - } else { - $args['searchWhere'][] = 'retention_frozen in (?)'; + if (count($retentionFrozenData) > 0) { + $args['searchData'][] = $retentionFrozenData; + $retentionFrozenWhere[] = 'retention_frozen in (?)'; + } + if (in_array(null, $body['retentionFrozen']['values'], true)) { + $retentionFrozenWhere[] = 'retention_frozen is NULL'; } - $args['searchData'][] = $retentionRuleFrozenData; + $args['searchWhere'][] = '(' . implode(' OR ', $retentionFrozenWhere) . ')'; } if (!empty($body['initiator']) && !empty($body['initiator']['values']) && is_array($body['initiator']['values'])) { if (in_array(null, $body['initiator']['values'])) { diff --git a/src/frontend/app/administration/parameter/parameters-administration.component.ts b/src/frontend/app/administration/parameter/parameters-administration.component.ts index 22cc61e4f9c..28f7a121a46 100755 --- a/src/frontend/app/administration/parameter/parameters-administration.component.ts +++ b/src/frontend/app/administration/parameter/parameters-administration.component.ts @@ -46,7 +46,7 @@ export class ParametersAdministrationComponent implements OnInit { this.http.get('../rest/parameters') .subscribe((data: any) => { - this.parameters = data.parameters.filter((item: any) => ['homepage_message', 'loginpage_message', 'traffic_record_summary_sheet'].indexOf(item.id) === -1); + this.parameters = data.parameters.filter((item: any) => ['homepage_message', 'loginpage_message', 'traffic_record_summary_sheet', 'bindingDocumentFinalAction', 'nonBindingDocumentFinalAction'].indexOf(item.id) === -1); this.loading = false; setTimeout(() => { this.adminService.setDataSource('admin_parameters', this.parameters, this.sort, this.paginator, this.filterColumns); @@ -60,7 +60,7 @@ export class ParametersAdministrationComponent implements OnInit { if (r) { this.http.delete('../rest/parameters/' + paramId) .subscribe((data: any) => { - this.parameters = data.parameters.filter((item: any) => ['homepage_message', 'loginpage_message', 'traffic_record_summary_sheet'].indexOf(item.id) === -1); + this.parameters = data.parameters.filter((item: any) => ['homepage_message', 'loginpage_message', 'traffic_record_summary_sheet', 'bindingDocumentFinalAction', 'nonBindingDocumentFinalAction'].indexOf(item.id) === -1); this.adminService.setDataSource('admin_parameters', this.parameters, this.sort, this.paginator, this.filterColumns); this.notify.success(this.translate.instant('lang.parameterDeleted')); }, (err) => { -- GitLab