diff --git a/apps/maarch_entreprise/Views/status-administration.component.html b/apps/maarch_entreprise/Views/status-administration.component.html index 49b19727b749344c957a128ea5789e7b06b60e2e..79bc84b49fbb9faa0335b38b7bf1743c96f9dee0 100644 --- a/apps/maarch_entreprise/Views/status-administration.component.html +++ b/apps/maarch_entreprise/Views/status-administration.component.html @@ -118,11 +118,11 @@ le statut <b>{{status.id}}</b> ne vous sera <b>PAS proposé</b> pour le critère de recherche STATUS de la recherche avancée de documents. </span> <span id="infoCanBeModifiedTooltip"> - si <b>NON coché</b>,<br/> + Si <b>NON coché</b>,<br/> vous ne pourrez <b>PAS modifier</b> les meta-données des documents ayant le statut <b>{{status.id}}</b>. </span> <span id="infoIsFolderStatusTooltip"> - si <b>coché</b>,<br/> - Le statut <b>{{status.id}}</b> pourra être utilisé pour des <b>bannettes de dossiers</b>. + Si <b>coché</b>,<br/> + le statut <b>{{status.id}}</b> pourra être utilisé pour des <b>bannettes de dossiers</b>. </span> </div> \ No newline at end of file diff --git a/core/Controllers/StatusController.php b/core/Controllers/StatusController.php index 15b113bf93cc6dec265ce5130dfe5d1ec6e58a1f..d0e5d42dd724998a60f9dac52159d8a3c4c7ec50 100644 --- a/core/Controllers/StatusController.php +++ b/core/Controllers/StatusController.php @@ -70,14 +70,14 @@ class StatusController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $errors = $this->control($request, 'create'); + $request = $request->getParams(); + $aArgs = self::manageValue($request); + $errors = $this->control($aArgs, 'create'); if (!empty($errors)) { return $response->withStatus(500)->withJson(['errors' => $errors]); } - $aArgs = $request->getParams(); - $return = StatusModel::create($aArgs); if ($return) { @@ -98,13 +98,14 @@ class StatusController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $errors = $this->control($request, 'update'); + $request = $request->getParams(); + $aArgs = self::manageValue($request); + $errors = $this->control($aArgs, 'update'); if (!empty($errors)) { return $response->withStatus(500)->withJson(['errors' => $errors]); } - $aArgs = $request->getParams(); $return = StatusModel::update($aArgs); @@ -143,27 +144,43 @@ class StatusController return $response->withJson([$obj]); } + protected function manageValue($request){ + foreach ($request as $key => $value) { + if(in_array($key, ['is_system', 'is_folder_status', 'can_be_searched', 'can_be_modified'])){ + if(empty($value)){ + $request[$key] = 'N'; + } else { + $request[$key] = 'Y'; + } + } + } + + $request['is_system'] = 'N'; + + return $request; + } + protected function control($request, $mode) { $errors = []; if ($mode == 'update') { $obj = StatusModel::getById([ - 'id' => $request->getParam('id') + 'id' => $request['id'] ]); if (empty($obj)) { array_push( $errors, - _ID . ' ' . $request->getParam('id') . ' ' . _NOT_EXISTS + _ID . ' ' . $request['id'] . ' ' . _NOT_EXISTS ); } } - if (!Validator::notEmpty()->validate($request->getParam('id'))) { + if (!Validator::notEmpty()->validate($request['id'])) { array_push($errors, _ID . ' ' . _IS_EMPTY); } elseif ($mode == 'create') { $obj = StatusModel::getById([ - 'id' => $request->getParam('id') + 'id' => $request['id'] ]); if (!empty($obj)) { array_push( @@ -173,53 +190,53 @@ class StatusController } } - if (!Validator::regex('/^[\w.-]*$/')->validate($request->getParam('id')) || - !Validator::length(1, 10)->validate($request->getParam('id'))) { + if (!Validator::regex('/^[\w.-]*$/')->validate($request['id']) || + !Validator::length(1, 10)->validate($request['id'])) { array_push($errors, 'id not valid'); } - if (!Validator::notEmpty()->validate($request->getParam('label_status')) || - !Validator::length(1, 50)->validate($request->getParam('label_status'))) { + if (!Validator::notEmpty()->validate($request['label_status']) || + !Validator::length(1, 50)->validate($request['label_status'])) { array_push($errors, 'label_status not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('is_system')) && - !Validator::contains('Y')->validate($request->getParam('is_system')) && - !Validator::contains('N')->validate($request->getParam('is_system')) + if ( Validator::notEmpty()->validate($request['is_system']) && + !Validator::contains('Y')->validate($request['is_system']) && + !Validator::contains('N')->validate($request['is_system']) ) { array_push($errors, 'is_system not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('is_folder_status')) && - !Validator::contains('Y')->validate($request->getParam('is_folder_status')) && - !Validator::contains('N')->validate($request->getParam('is_folder_status')) + if ( Validator::notEmpty()->validate($request['is_folder_status']) && + !Validator::contains('Y')->validate($request['is_folder_status']) && + !Validator::contains('N')->validate($request['is_folder_status']) ) { array_push($errors, 'is_folder_status not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('img_filename')) && - (!Validator::regex('/^[\w-.]+$/')->validate($request->getParam('img_filename')) || - !Validator::length(1, 255)->validate($request->getParam('img_filename'))) + if ( Validator::notEmpty()->validate($request['img_filename']) && + (!Validator::regex('/^[\w-.]+$/')->validate($request['img_filename']) || + !Validator::length(1, 255)->validate($request['img_filename'])) ) { array_push($errors, 'img_filename not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('maarch_module')) && - !Validator::length(null, 255)->validate($request->getParam('maarch_module')) + if ( Validator::notEmpty()->validate($request['maarch_module']) && + !Validator::length(null, 255)->validate($request['maarch_module']) ) { array_push($errors, 'maarch_module not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('can_be_searched')) && - !Validator::contains('Y')->validate($request->getParam('can_be_searched')) && - !Validator::contains('N')->validate($request->getParam('can_be_searched')) + if ( Validator::notEmpty()->validate($request['can_be_searched']) && + !Validator::contains('Y')->validate($request['can_be_searched']) && + !Validator::contains('N')->validate($request['can_be_searched']) ) { array_push($errors, 'can_be_searched not valid'); } - if ( Validator::notEmpty()->validate($request->getParam('can_be_modified')) && - !Validator::contains('Y')->validate($request->getParam('can_be_modified')) && - !Validator::contains('N')->validate($request->getParam('can_be_modified')) + if ( Validator::notEmpty()->validate($request['can_be_modified']) && + !Validator::contains('Y')->validate($request['can_be_modified']) && + !Validator::contains('N')->validate($request['can_be_modified']) ) { array_push($errors, 'can_be_modified'); } diff --git a/core/Test/StatusControllerTest.php b/core/Test/StatusControllerTest.php index 15e2019690a1d9672c544db44329ea4a9ac12000..c4604bbeddb1a0265d8016f9fef6442dcbcd5168 100644 --- a/core/Test/StatusControllerTest.php +++ b/core/Test/StatusControllerTest.php @@ -54,7 +54,7 @@ class StatusControllerTest extends \PHPUnit_Framework_TestCase $response = $status->create($fullRequest, new \Slim\Http\Response()); $compare = '[[{"id":"TEST","label_status":"TEST",' - . '"is_system":"Y","is_folder_status":"N","img_filename":null,' + . '"is_system":"N","is_folder_status":"N","img_filename":null,' . '"maarch_module":"apps","can_be_searched":"Y",' . '"can_be_modified":"Y"}]]'; @@ -76,7 +76,7 @@ class StatusControllerTest extends \PHPUnit_Framework_TestCase $response = $status->update($fullRequest, new \Slim\Http\Response()); $compare = '[[{"id":"TEST","label_status":"TEST AFTER UP",' - . '"is_system":"Y","is_folder_status":"N","img_filename":null,' + . '"is_system":"N","is_folder_status":"N","img_filename":null,' . '"maarch_module":"apps","can_be_searched":"Y",' . '"can_be_modified":"Y"}]]';