diff --git a/rest/index.php b/rest/index.php index 43840896540deb157b80029a92de9dfe649e50b8..c6e9cb5bf6b7254360f67cdcd1fa4b72e3bd3c50 100755 --- a/rest/index.php +++ b/rest/index.php @@ -163,6 +163,7 @@ $app->get('/entities/{id}', \Entity\controllers\EntityController::class . ':getB $app->put('/entities/{id}', \Entity\controllers\EntityController::class . ':update'); $app->delete('/entities/{id}', \Entity\controllers\EntityController::class . ':delete'); $app->get('/entities/{id}/details', \Entity\controllers\EntityController::class . ':getDetailledById'); +$app->get('/entities/{id}/users', \Entity\controllers\EntityController::class . ':getUsersById'); $app->put('/entities/{id}/reassign/{newEntityId}', \Entity\controllers\EntityController::class . ':reassignEntity'); $app->put('/entities/{id}/status', \Entity\controllers\EntityController::class . ':updateStatus'); $app->get('/entityTypes', \Entity\controllers\EntityController::class . ':getTypes'); diff --git a/sql/data_en.sql b/sql/data_en.sql index 615884e81c7448e77f06f56184869b8139bbd367..94b76b689f12c0880b7a7337c57c56617db4d9db 100644 --- a/sql/data_en.sql +++ b/sql/data_en.sql @@ -936,7 +936,7 @@ TRUNCATE TABLE contact_addresses; INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled) VALUES (1, 1, 1, '', 'Jean-Louis', 'ERCOLANI', 'title1', 'Directeur Général', '', '11', 'Boulevard du Sud-Est', '', 'MAARCH LES BAINS', '99000', 'France', '', 'jeanlouis.ercolani@maarch.org', 'http://www.maarch.com', '', '', '', 'bblier', 'VILLE', 'N', 'Y'); INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled) VALUES (2, 1, 2, '', 'Karim', 'SY', 'title1', 'Administrateur', '', '', 'Sacré Coeur 3', 'Villa 9653 4ème phase', 'DAKAR', '', 'SENEGAL', '', 'karim.sy@maarch.org', 'http://www.maarch.com', '', '', '', 'bblier', 'VILLE', 'N', 'Y'); INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled) VALUES (3, 1, 1, '', 'Laurent', 'GIOVANNONI', 'title1', 'Directeur Général Adjoint', NULL, '11', 'Boulevard du Sud-Est', '', 'MAARCH LES BAINS', '99000', 'FRANCE', '', 'laurent.giovannoni@maarch.org', 'http://www.maarch.com', '', '', '', 'bblier', 'COU', 'N', 'Y'); -INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled) VALUES (4, 2, 1, '', 'Nicolas', 'MARTIN', 'title1', '', NULL, '13', 'RUE LA PREFECTURE', '', 'MAARCH LES BAINS', '', '', '', '', 'http://www.maarch.com', '', '', '', 'bblier', 'COU', 'N', 'Y'); +INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled, external_id) VALUES (4, 2, 1, '', 'Nicolas', 'MARTIN', 'title1', '', NULL, '13', 'RUE LA PREFECTURE', '', 'MAARCH LES BAINS', '', '', '', '', 'http://www.maarch.com', '', '', '', 'bblier', 'COU', 'N', 'Y', '{"m2m":"org_987654321_DGS_SF"}'); INSERT INTO contact_addresses (id, contact_id, contact_purpose_id, departement, firstname, lastname, title, function, occupancy, address_num, address_street, address_complement, address_town, address_postal_code, address_country, phone, email, website, salutation_header, salutation_footer, other_data, user_id, entity_id, is_private, enabled) VALUES (5, 3, 1, '', 'Brigitte', 'BERGER', 'title1', 'Directrice Générale', NULL, '25', 'PLACE DES MIMOSAS', '', 'MAARCH LES BAINS', '99000', 'FRANCE', '', 'info@maarch.org', 'http://www.maarch.com', '', '', '', 'bblier', 'COU', 'N', 'Y'); Select setval('contact_addresses_id_seq', (select max(id)+1 from contact_addresses), false); -- Default contact_communication diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index ebb2ebe3d223cf405065ab74e3f21ed485dcdcf6..8b58a3a1f95fafa448f4e7775d8c08e0d55a840f 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -16,6 +16,7 @@ use Attachment\models\AttachmentModel; use Convert\controllers\ConvertPdfController; use Docserver\models\DocserverModel; use Entity\controllers\ListInstanceController; +use Entity\models\ListInstanceModel; use History\controllers\HistoryController; use Note\models\NoteModel; use Resource\models\ResModel; @@ -242,7 +243,13 @@ class ActionMethodController $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); - $controller = ListInstanceController::updateListInstance(['data' => [['resId' => $args['resId'], 'listInstances' => $args['data']]], 'userId' => $currentUser['id']]); + $listInstances = []; + if (!empty($args['data']['onlyRedirectDest'])) { + $listInstances = ListInstanceModel::get(['select' => ['*'], 'where' => ['res_id = ?', 'difflist_type = ?', 'item_mode != ?'], 'data' => [$args['resId'], 'entity_id', 'dest']]); + } + + $listInstances = array_merge($listInstances, $args['data']['listInstances']); + $controller = ListInstanceController::updateListInstance(['data' => [['resId' => $args['resId'], 'listInstances' => $listInstances]], 'userId' => $currentUser['id']]); if (!empty($controller['errors'])) { return ['errors' => [$controller['errors']]]; } diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 9202f238e98604c217025a9359b20913a0808129..ad52dfdfdbe7b5b4f5cbe89378e446e895381c35 100755 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -458,6 +458,28 @@ class EntityController return $response->withJson(['success' => 'success']); } + public function getUsersById(Request $request, Response $response, array $aArgs) + { + $entity = entitymodel::getById(['id' => $aArgs['id'], 'select' => ['entity_id']]); + if (empty($entity)) { + return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); + } + + $users = UserEntityModel::getWithUsers([ + 'select' => ['DISTINCT users.id', 'users.user_id', 'firstname', 'lastname'], + 'where' => ['users_entities.entity_id = ?', 'status not in (?)'], + 'data' => [$entity['entity_id'], ['DEL', 'ABS']], + 'orderBy' => ['lastname', 'firstname'] + ]); + + foreach ($users as $key => $user) { + $users[$key]['labelToDisplay'] = "{$user['firstname']} {$user['lastname']}"; + $users[$key]['descriptionToDisplay'] = UserModel::getPrimaryEntityByUserId(['userId' => $user['user_id']])['entity_label']; + } + + return $response->withJson(['users' => $users]); + } + public function getTypes(Request $request, Response $response) { return $response->withJson(['types' => EntityModel::getTypes()]); diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php index 369d55039a28d683da34a1a23227e7dae48f7982..83901d4ca40aed5f6fc851f989c1aee33395676a 100755 --- a/src/app/entity/controllers/ListInstanceController.php +++ b/src/app/entity/controllers/ListInstanceController.php @@ -130,11 +130,21 @@ class ListInstanceController 'data' => [$ListInstanceByRes['resId'], $ListInstanceByRes['listInstances'][0]['difflist_type']] ]); + $recipientFound = false; + foreach ($ListInstanceByRes['listInstances'] as $instance) { + if ($instance['item_mode'] == 'dest') { + $recipientFound = true; + } + } + if (!$recipientFound) { + return ['errors' => 'Dest is missing', 'code' => 403]; + } + foreach ($ListInstanceByRes['listInstances'] as $instance) { $listControl = ['item_id', 'item_type', 'item_mode', 'difflist_type']; foreach ($listControl as $itemControl) { if (empty($instance[$itemControl])) { - return ['errors' => $itemControl . ' are empty', 'code' => 400]; + return ['errors' => "ListInstance {$itemControl} is not set or empty", 'code' => 400]; } } diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index 2d35ef8278f34387e9ddaa0164853622df8fa759..2ea008aa33c7119524e7982d3dbbe13e6b53b1ea 100755 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -140,9 +140,11 @@ abstract class UserModelAbstract if (empty($user)) { return []; } - $users[$args['login']] = $user[0]; + if (empty($args['select']) || in_array('id', $args['select'])) { + $users[$args['login']] = $user[0]; + } - return $users[$args['login']]; + return $user[0]; } public static function getByLowerLogin(array $aArgs)