diff --git a/sql/data_fr.sql b/sql/data_fr.sql index eddb1264cc0af27adcc88469b956dc6e11daf1ee..a2c78b1add334c95e1d77349add40ec12078f489 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -796,6 +796,8 @@ DELETE FROM security WHERE group_id = 'MAARCHTOGEC'; INSERT INTO security (group_id, coll_id, where_clause, maarch_comment) VALUES ('MAARCHTOGEC', 'letterbox_coll', '1=0', 'Aucun courrier'); DELETE FROM security WHERE group_id = 'SERVICE'; INSERT INTO security (group_id, coll_id, where_clause, maarch_comment) VALUES ('SERVICE', 'letterbox_coll', '1=0', 'Aucun courrier'); +DELETE FROM security WHERE group_id = 'WEBSERVICE'; +INSERT INTO security (group_id, coll_id, where_clause, maarch_comment) VALUES ('WEBSERVICE', 'letterbox_coll', '1=0', 'Aucun courrier'); -- Donnees manuelles ------------ @@ -1082,7 +1084,7 @@ TRUNCATE TABLE users_baskets_preferences; INSERT INTO users_baskets_preferences (user_serial_id, group_serial_id, basket_id, display) SELECT usergroup_content.user_id, usergroups.id, groupbasket.basket_id, TRUE FROM usergroups, groupbasket, usergroup_content WHERE groupbasket.group_id = usergroups.group_id AND usergroups.id = usergroup_content.group_id -ORDER BY users.id; +ORDER BY usergroup_content.user_id; ------------ --ACTIONS_GROUPBASKETS diff --git a/src/app/group/models/ServiceModelAbstract.php b/src/app/group/models/ServiceModelAbstract.php index 8e7fc43730a7cf08c2763116b3fc8e2bbbd7edbe..170d100170279bb291cc81749c0fe4efc19be8d9 100755 --- a/src/app/group/models/ServiceModelAbstract.php +++ b/src/app/group/models/ServiceModelAbstract.php @@ -16,6 +16,7 @@ namespace Group\models; use SrcCore\models\CoreConfigModel; use SrcCore\models\DatabaseModel; use SrcCore\models\ValidatorModel; +use User\models\UserGroupModel; use User\models\UserModel; abstract class ServiceModelAbstract @@ -328,16 +329,13 @@ abstract class ServiceModelAbstract ValidatorModel::notEmpty($args, ['userId']); ValidatorModel::intVal($args, ['userId']); - $user = UserModel::getById(['id' => $args['userId'], 'select' => ['user_id']]); - $groups = UserModel::getGroupsByLogin(['login' => $user['user_id']]); - - foreach ($groups as $group) { - if ($group['can_index']) { - return true; - } - } + $canIndex = UserGroupModel::getWithGroups([ + 'select' => [1], + 'where' => ['usergroup_content.user_id = ?', 'usergroups.can_index = ?'], + 'data' => [$args['userId'], true] + ]); - return false; + return !empty($canIndex); } protected static function getLoadedXml(array $aArgs = []) diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 8623cc9e79a8aae9e5bfd432ab970b0491b5a356..f3b6e7488e168e67a3408843de4c723a84e861e0 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -49,6 +49,7 @@ use SrcCore\models\ValidatorModel; use Status\models\StatusModel; use Tag\models\TagModel; use Tag\models\TagResModel; +use User\models\UserGroupModel; use User\models\UserModel; class ResController @@ -996,14 +997,15 @@ class ResController $body = $args['body']; if (!empty($body['destination'])) { - $groups = UserModel::getGroupsByLogin(['login' => $GLOBALS['userId']]); + $groups = UserGroupModel::getWithGroups([ + 'select' => ['usergroups.indexation_parameters'], + 'where' => ['usergroup_content.user_id = ?', 'usergroups.can_index = ?'], + 'data' => [$GLOBALS['id'], true] + ]); $clauseToProcess = ''; $allowedEntities = []; foreach ($groups as $group) { - if (!$group['can_index']) { - continue; - } $group['indexation_parameters'] = json_decode($group['indexation_parameters'], true); foreach ($group['indexation_parameters']['keywords'] as $keywordValue) { if (strpos($clauseToProcess, IndexingController::KEYWORDS[$keywordValue]) === false) { diff --git a/src/app/user/models/UserGroupModel.php b/src/app/user/models/UserGroupModel.php index 4d0c8e7eb7cff03e2c30f5dfc23c42f30f16561f..f6945d7814d6cabb85a1931cc4447e63630819ea 100644 --- a/src/app/user/models/UserGroupModel.php +++ b/src/app/user/models/UserGroupModel.php @@ -82,4 +82,25 @@ class UserGroupModel return true; } + + public static function getWithGroups(array $args = []) + { + ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy']); + ValidatorModel::intType($args, ['limit']); + + $where = ['usergroup_content.group_id = usergroups.id']; + if (!empty($args['where'])) { + $where = array_merge($where, $args['where']); + } + $usersGroups = DatabaseModel::select([ + 'select' => $args['select'] ?? ['*'], + 'table' => ['usergroup_content, usergroups'], + 'where' => $where, + 'data' => $args['data'] ?? [], + 'order_by' => $args['orderBy'] ?? [], + 'limit' => $args['limit'] ?? 0 + ]); + + return $usersGroups; + } } diff --git a/test/unitTests/app/resource/ResControllerTest.php b/test/unitTests/app/resource/ResControllerTest.php index 062cda9226d005a9789cbb9a00416ee1cc11c601..65f365383ce291adc248e5ce46efc4933ba76e54 100755 --- a/test/unitTests/app/resource/ResControllerTest.php +++ b/test/unitTests/app/resource/ResControllerTest.php @@ -355,6 +355,9 @@ class ResControllerTest extends TestCase ] ]; + $entity = \Entity\models\EntityModel::getByEntityId(['entityId' => 'PJS', 'select' => ['id']]); + $this->assertInternalType('int', $entity['id']); + foreach ($aNewDocument as $key => $value) { $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'POST']); $request = \Slim\Http\Request::createFromEnvironment($environment); @@ -370,8 +373,8 @@ class ResControllerTest extends TestCase 'documentDate' => '2019-01-01 17:18:47', 'arrivalDate' => '2019-01-01 17:18:47', 'doctype' => $value[0], - 'destination' => 15, - 'initiator' => 15, + 'destination' => $entity['id'], + 'initiator' => $entity['id'], 'subject' => $key .' Breaking News : 12345 Superman is alive - PHP unit', 'typist' => 19, 'priority' => $value[1], diff --git a/test/unitTests/define.php b/test/unitTests/define.php index 82bb63aa98bb1dbc8349c1389aa804ad9074565f..f0998976832488d8d884ad41df3f486e3e9b0fc7 100755 --- a/test/unitTests/define.php +++ b/test/unitTests/define.php @@ -13,6 +13,8 @@ $userId = 'superadmin'; $userInfo = \User\models\UserModel::getByLogin(['login' => $userId, 'select' => ['id']]); $id = $userInfo['id']; +date_default_timezone_set(\SrcCore\models\CoreConfigModel::getTimezone()); + $language = \SrcCore\models\CoreConfigModel::getLanguage(); require_once("src/core/lang/lang-{$language}.php");