From d128fe1ab91f3275952557dd09fe455d0081d46f Mon Sep 17 00:00:00 2001 From: Vinciane <vinciane.bizet@maarch.org> Date: Fri, 8 Feb 2019 12:41:29 +0100 Subject: [PATCH] FIX #9349 fix front and controller - initialize listinstances[] + empty - variable lang fusion - DEL and END resource status - code format --- .../controllers/ListInstanceController.php | 39 +++++++++++-------- .../controllers/ListTemplateController.php | 6 ++- .../models/ListInstanceModelAbstract.php | 3 +- ...ministration-redirect-modal.component.html | 2 +- src/frontend/lang/lang-en.ts | 3 +- src/frontend/lang/lang-fr.ts | 3 +- src/frontend/lang/lang-nl.ts | 7 ++-- 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php index 8e2fe7db114..3090cba03b7 100755 --- a/src/app/entity/controllers/ListInstanceController.php +++ b/src/app/entity/controllers/ListInstanceController.php @@ -23,6 +23,7 @@ use Entity\models\EntityModel; use SrcCore\models\DatabaseModel; use User\models\UserModel; use Resource\models\ResModel; +use Group\models\ServiceModel; class ListInstanceController { @@ -72,17 +73,23 @@ class ListInstanceController return $response->withJson($listinstances); } - public function getListWhereUserIsDest(Request $request, Response $response, array $aArgs) { + public function getListWhereUserIsDest(Request $request, Response $response, array $aArgs) + { + if (!ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } $data = ListInstanceModel::getListWhereUserIsDest(['select' => ['li.*'], 'id' => $aArgs['itemId']]); - if($data) { + $listinstances = []; + + if (!empty($data)) { $res_id = 0; - $array=[]; - foreach($data as $value) { - if($res_id == 0) { + $array = []; + foreach ($data as $value) { + if ($res_id == 0) { $res_id = $value['res_id']; - } else if( $res_id != $value['res_id']) { + } elseif ($res_id != $value['res_id']) { $listinstances[] = ['resId' => $res_id, "listinstances" => $array]; $res_id = $value['res_id']; $array = []; @@ -92,31 +99,29 @@ class ListInstanceController $listinstances[] = ['resId' => $res_id, "listinstances" => $array]; } - return $response->withJson(['listinstances' => $listinstances]); + return $response->withJson(['listinstances' => $listinstances]); } public function update(Request $request, Response $response) { $data = $request->getParams(); - if(empty($data['listinstances'])) { - return $response->withStatus(400)->withJson(['errors' => 'listinstance is missing or is empty']); + if (empty($data['listinstances'])) { + return $response->withStatus(400)->withJson(['errors' => 'listinstances is missing or is empty']); } DatabaseModel::beginTransaction(); foreach ($data['listinstances'] as $ListInstanceByRes) { - - foreach($ListInstanceByRes['listinstances'] as $instance) { - - if( empty($instance['res_id']) || empty($instance['item_id']) || empty($instance['item_type']) || empty($instance['item_mode']) || empty($instance['difflist_type']) ) { + foreach ($ListInstanceByRes['listinstances'] as $instance) { + if (empty($instance['res_id']) || empty($instance['item_id']) || empty($instance['item_type']) || empty($instance['item_mode']) || empty($instance['difflist_type'])) { DatabaseModel::rollbackTransaction(); return $response->withStatus(400)->withJson(['errors' => 'Some data are empty']); } - if( isset($instance['listinstance_id']) && !empty($instance['listinstance_id']) ) { + if (isset($instance['listinstance_id']) && !empty($instance['listinstance_id'])) { $check = ListInstanceModel::getById(['select' => ['listinstance_id'], 'id' => $instance['listinstance_id']]); - if( !$check) { + if (!$check) { DatabaseModel::rollbackTransaction(); return $response->withStatus(400)->withJson(['errors' => 'listinstance_id is not correct']); } @@ -136,13 +141,13 @@ class ListInstanceController ListInstanceModel::create($instance); - if($instance['item_mode'] == 'dest') { + if ($instance['item_mode'] == 'dest') { ResModel::update([ 'set' => ['dest_user' => $instance['item_id']], 'where' => ['res_id = ?'], 'data' => [$instance['res_id']] ]); - } + } } } diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index 3025d168be0..d837bdb33b2 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -218,7 +218,6 @@ class ListTemplateController public function delete(Request $request, Response $response, array $aArgs) { - $listTemplates = ListTemplateModel::getById(['id' => $aArgs['id'], 'select' => ['object_id', 'object_type']]); if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && !strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') && !strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_')) { @@ -271,12 +270,15 @@ class ListTemplateController public function updateByUserWithEntityDest(Request $request, Response $response) { + if (!ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + $data = $request->getParams(); DatabaseModel::beginTransaction(); foreach ($data['redirectListModels'] as $listModel) { - //check if user exist $user = UserModel::getByLogin(['login' => $listModel['redirectUserId']]); if (empty($user) || $user['status'] != "OK") { DatabaseModel::rollbackTransaction(); diff --git a/src/app/entity/models/ListInstanceModelAbstract.php b/src/app/entity/models/ListInstanceModelAbstract.php index 3a19dc31106..33f09ab7af5 100755 --- a/src/app/entity/models/ListInstanceModelAbstract.php +++ b/src/app/entity/models/ListInstanceModelAbstract.php @@ -216,11 +216,10 @@ abstract class ListInstanceModelAbstract 'table' => ['listinstance li', 'res_letterbox res', 'mlb_coll_ext mlb'], 'left_join' => ['li.res_id = res.res_id', 'res.res_id = mlb.res_id'], 'where' => ['res.dest_user = ?', 'li.difflist_type = ?', 'mlb.closing_date is null'], - 'data' => [$aArgs['id'], 'entity_id'], + 'data' => [$aArgs['id'], 'entity_id', ['END', 'DEL']], 'order_by' => ['res_id ASC'] ]); return $aListinstance; } - } diff --git a/src/frontend/app/administration/user/users-administration-redirect-modal.component.html b/src/frontend/app/administration/user/users-administration-redirect-modal.component.html index de11c507e00..25af20f413b 100755 --- a/src/frontend/app/administration/user/users-administration-redirect-modal.component.html +++ b/src/frontend/app/administration/user/users-administration-redirect-modal.component.html @@ -39,7 +39,7 @@ <div class="modal-body" *ngIf="data.userDestRedirect.isResDestUser"> <h2 mat-dialog-title>{{lang.redirectUserListInstances}}</h2> <div class="alert alert-warning" role="alert"> - <b>{{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> <span> {{lang.isResDest}}, {{lang.chooseNewDestUser}}</span> : + <b>{{this.data.userDestRedirect.firstname}} {{this.data.userDestRedirect.lastname}}</b> <span [innerHTML]="lang.chooseNewDestUser"></span> : </div> <div id="{{this.data.userDestRedirect.user_id}}" class="form-group"> diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index d32c209cb1e..a3fcc72194d 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -802,8 +802,7 @@ export const LANG_EN = { "destination" : "entity destination", "selectAllResInBasket" : "Select all mails in basket", "redirectUserListInstances" : "Change of recipient for mail being processed", - "isResDest" : "is the recipient of mail being processed", - "chooseNewDestUser" : "please select a replacement user", + "chooseNewDestUser" : "is the <b>recipient</b> of mail being processed, please select a <b>replacement user</b>", "newDest" : "New recipient for", "newDestRes" : "New recipient for mails" }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index e4419357007..431937696ab 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -828,8 +828,7 @@ export const LANG_FR = { "destination" : "entité traitante", "selectAllResInBasket" : "Sélectionner tous les courriers de la bannette", "redirectUserListInstances" : "Changement de destinataire pour les courriers en cours de traitement", - "isResDest" : "est destinataire de courriers en cours de traitement", - "chooseNewDestUser" : "veuillez choisir un utilisateur de remplacement", + "chooseNewDestUser" : "est en <b>destinataire</b> de courriers en cours de traitement, veuillez choisir un utilisateur de <b>remplacement</b>", "newDest" : "Nouveau destinataire pour", "newDestRes" : "Nouveau destinataire pour les courriers" }; diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index d4cb7ed6a20..33b7044a694 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -831,8 +831,7 @@ export const LANG_NL = { "destination" : "_TO_TRANSLATE", "selectAllResInBasket" : "_TO_TRANSLATE", "redirectUserListInstances" : "_TO_TRANSLATE_Change of recipient for mail being processed", - "isResDest" : "_TO_TRANSLATE_is the recipient of mail being processed", - "chooseNewDestUser" : "_TO_TRANSLATE_please select a replacement user", - "newDest" : "_TO_TRANSLATE_New recipient for", - "newDestRes" : "_TO_TRANSLATE_New recipient for mails" + "chooseNewDestUser" : "is the <b>recipient</b> of mail being processed, please select a <b>replacement user</b>", //_TO_TRANSLATE_ + "newDest" : "New recipient for", //_TO_TRANSLATE_ + "newDestRes" : "New recipient for mails" //_TO_TRANSLATE_ }; -- GitLab