diff --git a/rest/index.php b/rest/index.php index 242366ef5933ee5fb01a28daa60af7263327100d..1c2ea1bc882f281b19d9a71fdf6ecf8eec7fffb3 100755 --- a/rest/index.php +++ b/rest/index.php @@ -455,8 +455,7 @@ $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/ac //Search $app->post('/search', \Search\controllers\SearchController::class . ':get'); -$app->get('/search/configuration', \Search\controllers\SearchAdministrationController::class . ':get'); -$app->put('/search/configuration', \Search\controllers\SearchAdministrationController::class . ':update'); +$app->get('/search/configuration', \Search\controllers\SearchController::class . ':getConfiguration'); $app->get('/searchTemplates', \Search\controllers\SearchTemplateController::class . ':get'); $app->post('/searchTemplates', \Search\controllers\SearchTemplateController::class . ':create'); diff --git a/src/app/configuration/controllers/ConfigurationController.php b/src/app/configuration/controllers/ConfigurationController.php index b8466a158f62f164659f2f76dfe2f9687c42e4a8..faa4baf991e8afc82227f250ac9fcd0223824d04 100755 --- a/src/app/configuration/controllers/ConfigurationController.php +++ b/src/app/configuration/controllers/ConfigurationController.php @@ -16,6 +16,7 @@ namespace Configuration\controllers; use Configuration\models\ConfigurationModel; use Group\controllers\PrivilegeController; +use History\controllers\HistoryController; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; @@ -69,11 +70,43 @@ class ConfigurationController } $data['charset'] = empty($data['charset']) ? 'utf-8' : $data['charset']; unset($data['passwordAlreadyExists']); + } elseif ($args['privilege'] == 'admin_search') { + if (!Validator::notEmpty()->arrayType()->validate($data['listDisplay'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay is empty or not an array']); + } + if (isset($data['listDisplay']['subInfos']) && !Validator::arrayType()->validate($data['listDisplay']['subInfos'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos] is not set or not an array']); + } + if (!Validator::intVal()->validate($data['listDisplay']['templateColumns'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[templateColumns] is not set or not an array']); + } + foreach ($data['listDisplay']['subInfos'] as $value) { + if (!Validator::stringType()->notEmpty()->validate($value['value'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos][value] is empty or not a string']); + } elseif (!isset($value['cssClasses']) || !is_array($value['cssClasses'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos][cssClasses] is not set or not an array']); + } + } + + if (empty($data['listEvent']['defaultTab'])) { + $data['listEvent']['defaultTab'] = 'dashboard'; + } + + $data = ['listDisplay' => $data['listDisplay'], 'listEvent' => $data['listEvent']]; + } $data = json_encode($data); ConfigurationModel::update(['set' => ['value' => $data], 'where' => ['privilege = ?'], 'data' => [$args['privilege']]]); + HistoryController::add([ + 'tableName' => 'configurations', + 'recordId' => $args['privilege'], + 'eventType' => 'UP', + 'eventId' => 'configurationUp', + 'info' => _CONFIGURATION_UPDATED . ' : ' . $args['privilege'] + ]); + return $response->withJson(['success' => 'success']); } diff --git a/src/app/search/controllers/SearchAdministrationController.php b/src/app/search/controllers/SearchAdministrationController.php deleted file mode 100644 index e5ab7739e5bb5cafeda2f3ff18b3d7b23270de16..0000000000000000000000000000000000000000 --- a/src/app/search/controllers/SearchAdministrationController.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php - -/** -* Copyright Maarch since 2008 under licence GPLv3. -* See LICENCE.txt file at the root folder for more details. -* This file is part of Maarch software. -* -*/ - -/** -* @brief Search Administration Controller -* @author dev@maarch.org -*/ - -namespace Search\controllers; - -use Configuration\models\ConfigurationModel; -use Group\controllers\PrivilegeController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class SearchAdministrationController -{ - public function get(Request $request, Response $response) { - $configuration = ConfigurationModel::getByPrivilege(['privilege' => 'admin_search']); - $configuration = json_decode($configuration, true); - - return $response->withJson(['configuration' => $configuration]); - } - - public function update(Request $request, Response $response) - { - if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_search', 'userId' => $GLOBALS['id']])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $body = $request->getParsedBody(); - - if (!Validator::notEmpty()->arrayType()->validate($body['listDisplay'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay is empty or not an array']); - } - if (isset($body['listDisplay']['subInfos']) && !Validator::arrayType()->validate($body['listDisplay']['subInfos'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos] is not set or not an array']); - } - if (!Validator::intVal()->validate($body['listDisplay']['templateColumns'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[templateColumns] is not set or not an array']); - } - foreach ($body['listDisplay']['subInfos'] as $value) { - if (!Validator::stringType()->notEmpty()->validate($value['value'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos][value] is empty or not a string']); - } elseif (!isset($value['cssClasses']) || !is_array($value['cssClasses'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body listDisplay[subInfos][cssClasses] is not set or not an array']); - } - } - - if (empty($body['listEvent']['defaultTab'])) { - $body['listEvent']['defaultTab'] = 'dashboard'; - } - - $configuration = ['listDisplay' => $body['listDisplay'], 'listEvent' => $body['listEvent']]; - $configuration = json_encode($configuration); - - ConfigurationModel::update([ - 'set' => ['value' => $configuration], - 'where' => ['privilege = ?'], - 'data' => ['admin_search'] - ]); - - return $response->withStatus(204); - } -} diff --git a/src/app/search/controllers/SearchController.php b/src/app/search/controllers/SearchController.php index 9de17d6193e2f74cd94272f2307a2ac574e5b863..c7a95c00af292efa2c55dc1ffe7d9c95ec6066a4 100644 --- a/src/app/search/controllers/SearchController.php +++ b/src/app/search/controllers/SearchController.php @@ -17,6 +17,7 @@ namespace Search\controllers; use Attachment\models\AttachmentModel; use Basket\models\BasketModel; use Basket\models\RedirectBasketModel; +use Configuration\models\ConfigurationModel; use Contact\controllers\ContactController; use Contact\models\ContactModel; use CustomField\models\CustomFieldModel; @@ -245,6 +246,13 @@ class SearchController return $response->withJson(['resources' => $resources, 'count' => count($allResources), 'allResources' => $allResources]); } + public function getConfiguration(Request $request, Response $response) { + $configuration = ConfigurationModel::getByPrivilege(['privilege' => 'admin_search']); + $configuration = json_decode($configuration['value'], true); + + return $response->withJson(['configuration' => $configuration]); + } + private static function getUserDataClause(array $args) { ValidatorModel::notEmpty($args, ['userId', 'login']); diff --git a/src/core/lang/lang-en.php b/src/core/lang/lang-en.php index 616a2db957c47a388f29ad827e821898a69fedfe..bbd40788796d2feff426b313258fe26fee064dc5 100755 --- a/src/core/lang/lang-en.php +++ b/src/core/lang/lang-en.php @@ -482,3 +482,5 @@ define('_NOT_GENERATED', 'Not generated'); define('_REGISTERED_MAIL_DISTRIBUTED', 'Acknowledgement receipt received : registered mail distributed'); define('_REGISTERED_MAIL_NOT_DISTRIBUTED', 'Acknowledgement receipt received : registered mail not distributed'); + +define('_CONFIGURATION_UPDATED', 'Configuration updated'); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index 735e9ae4da0cf2b99e514ae708c8ab4ae5ff45b1..954853b176fea035aab96d9beaa4bd733c0e5b6c 100755 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -482,3 +482,5 @@ define('_NOT_GENERATED', 'Non généré'); define('_REGISTERED_MAIL_DISTRIBUTED', 'Accusé de réception reçu : recommandé distribué'); define('_REGISTERED_MAIL_NOT_DISTRIBUTED', 'Accusé de réception reçu : recommandé non distribué'); + +define('_CONFIGURATION_UPDATED', 'Configuration modifiée');