diff --git a/rest/index.php b/rest/index.php index 7e159a22f78db63d8880c8248d39b7ba48ec824c..1205d6dc4691f7ff93d611a625802a49498eccd7 100755 --- a/rest/index.php +++ b/rest/index.php @@ -348,6 +348,7 @@ $app->get('/resources/{resId}/listInstance', \Entity\controllers\ListInstanceCon $app->get('/resources/{resId}/visaCircuit', \Entity\controllers\ListInstanceController::class . ':getVisaCircuitByResId'); $app->get('/resources/{resId}/opinionCircuit', \Entity\controllers\ListInstanceController::class . ':getOpinionCircuitByResId'); $app->get('/resources/{resId}/availableCircuits', \Entity\controllers\ListTemplateController::class . ':getAvailableCircuitsByResId'); +$app->delete('/resources/{resId}/circuits/{type}', \Entity\controllers\ListInstanceController::class . ':deleteCircuit'); $app->get('/resources/{resId}/linkedResources', \Resource\controllers\LinkController::class . ':getLinkedResources'); $app->post('/resources/{resId}/linkedResources', \Resource\controllers\LinkController::class . ':linkResources'); $app->delete('/resources/{resId}/linkedResources/{id}', \Resource\controllers\LinkController::class . ':unlinkResources'); diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php index 718052dc2a695507f399e051ae6316e38d008183..c8ff8504925e13fff5f5c0ae1e63f0354fcbf64f 100755 --- a/src/app/entity/controllers/ListInstanceController.php +++ b/src/app/entity/controllers/ListInstanceController.php @@ -67,6 +67,7 @@ class ListInstanceController $listInstances = ListInstanceModel::getVisaCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'users.id', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]); foreach ($listInstances as $key => $value) { $listInstances[$key]['item_id'] = $listInstances[$key]['id']; + $listInstances[$key]['item_type'] = 'user'; $listInstances[$key]['labelToDisplay'] = $listInstances[$key]['item_firstname'].' '.$listInstances[$key]['item_lastname']; } @@ -82,6 +83,7 @@ class ListInstanceController $listInstances = ListInstanceModel::getAvisCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'users.id', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment'], 'id' => $aArgs['resId']]); foreach ($listInstances as $key => $value) { $listInstances[$key]['item_id'] = $listInstances[$key]['id']; + $listInstances[$key]['item_type'] = 'user'; $listInstances[$key]['labelToDisplay'] = $listInstances[$key]['item_firstname'].' '.$listInstances[$key]['item_lastname']; } @@ -95,9 +97,7 @@ class ListInstanceController return $response->withStatus(400)->withJson(['errors' => 'Body is not set or not an array']); } - $currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]); - - $controller = ListInstanceController::updateListInstance(['data' => $body, 'userId' => $currentUser['id']]); + $controller = ListInstanceController::updateListInstance(['data' => $body, 'userId' => $GLOBALS['id']]); if (!empty($controller['errors'])) { return $response->withStatus($controller['code'])->withJson(['errors' => $controller['errors']]); } @@ -152,7 +152,7 @@ class ListInstanceController } } - foreach ($ListInstanceByRes['listInstances'] as $instance) { + foreach ($ListInstanceByRes['listInstances'] as $key => $instance) { $listControl = ['item_id', 'item_type', 'item_mode', 'difflist_type']; foreach ($listControl as $itemControl) { if ($itemControl == 'item_mode' && $ListInstanceByRes['listInstances'][0]['difflist_type'] != 'entity_id') { @@ -207,16 +207,17 @@ class ListInstanceController } ListInstanceModel::create([ - 'res_id' => $ListInstanceByRes['resId'], - 'sequence' => 0, - 'item_id' => $instance['item_id'], - 'item_type' => $instance['item_type'], - 'item_mode' => $instance['item_mode'], - 'added_by_user' => $currentUser['user_id'], - 'difflist_type' => $instance['difflist_type'], - 'process_date' => $instance['process_date'] ?? null, - 'process_comment' => $instance['process_comment'] ?? null, - 'viewed' => empty($instance['viewed']) ? 0 : $instance['viewed'] + 'res_id' => $ListInstanceByRes['resId'], + 'sequence' => $key, + 'item_id' => $instance['item_id'], + 'item_type' => $instance['item_type'], + 'item_mode' => $instance['item_mode'], + 'added_by_user' => $currentUser['user_id'], + 'difflist_type' => $instance['difflist_type'], + 'process_date' => $instance['process_date'] ?? null, + 'process_comment' => $instance['process_comment'] ?? null, + 'requested_signature' => $instance['requested_signature'] ?? false, + 'viewed' => empty($instance['viewed']) ? 0 : $instance['viewed'] ]); if ($instance['item_mode'] == 'dest') { @@ -265,4 +266,29 @@ class ListInstanceController return ['success' => 'success']; } + + public function deleteCircuit(Request $request, Response $response, array $args) + { + if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Resource out of perimeter']); + } elseif (!Validator::stringType()->validate($args['type']) || !in_array($args['type'], ['visaCircuit', 'opinionCircuit'])) { + return $response->withStatus(403)->withJson(['errors' => 'Query params type is empty or not valid']); + } elseif ($args['type'] == 'visaCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_visa_workflow', 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } elseif ($args['type'] == 'opinionCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_avis_workflow', 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + + $mappingTypes = [ + 'visaCircuit' => 'VISA_CIRCUIT', + 'opinionCircuit' => 'AVIS_CIRCUIT', + ]; + + ListInstanceModel::delete([ + 'where' => ['res_id = ?', 'difflist_type = ?'], + 'data' => [$args['resId'], $mappingTypes[$args['type']]] + ]); + + return $response->withStatus(204); + } } diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index 729021ce876ad4895c6bb9b4ff67c0a790d1d13a..426e75713200e7d947f8e29075657d5a058d7561 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -108,12 +108,10 @@ class ListTemplateController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - if ($body['type'] == 'visaCircuit' - && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_visa_workflow', 'userId' => $GLOBALS['id']])) { + if ($body['type'] == 'visaCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_visa_workflow', 'userId' => $GLOBALS['id']])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - if ($body['type'] == 'opinionCircuit' - && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_avis_workflow', 'userId' => $GLOBALS['id']])) { + if ($body['type'] == 'opinionCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'config_avis_workflow', 'userId' => $GLOBALS['id']])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } $owner = $GLOBALS['id']; diff --git a/src/app/entity/models/ListInstanceModelAbstract.php b/src/app/entity/models/ListInstanceModelAbstract.php index fdedf1aeecd705cbfa30228752a3606c18b98163..bbb3951685bb98fdfd7e5052c2cbea050ae4cd15 100755 --- a/src/app/entity/models/ListInstanceModelAbstract.php +++ b/src/app/entity/models/ListInstanceModelAbstract.php @@ -19,23 +19,23 @@ use SrcCore\models\DatabaseModel; abstract class ListInstanceModelAbstract { - public static function get(array $aArgs) + public static function get(array $args) { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy', 'groupBy']); - ValidatorModel::intType($aArgs, ['limit']); + ValidatorModel::notEmpty($args, ['select']); + ValidatorModel::arrayType($args, ['select', 'where', 'data', 'orderBy', 'groupBy']); + ValidatorModel::intType($args, ['limit']); - $aListInstances = DatabaseModel::select([ - 'select' => $aArgs['select'], + $listInstances = DatabaseModel::select([ + 'select' => $args['select'], 'table' => ['listinstance'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'groupBy' => empty($aArgs['groupBy']) ? [] : $aArgs['groupBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] + 'where' => empty($args['where']) ? [] : $args['where'], + 'data' => empty($args['data']) ? [] : $args['data'], + 'order_by' => empty($args['orderBy']) ? [] : $args['orderBy'], + 'groupBy' => empty($args['groupBy']) ? [] : $args['groupBy'], + 'limit' => empty($args['limit']) ? 0 : $args['limit'] ]); - return $aListInstances; + return $listInstances; } public static function getById(array $aArgs) @@ -76,7 +76,8 @@ abstract class ListInstanceModelAbstract 'viewed' => $args['viewed'], 'difflist_type' => $args['difflist_type'], 'process_date' => $args['process_date'], - 'process_comment' => $args['process_comment'] + 'process_comment' => $args['process_comment'], + 'requested_signature' => empty($args['requested_signature']) ? 'false' : 'true' ] ]); diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index fe6e186b33f55f0275c0ac8ceab1d13574751b92..309838f9bcd9edbb1a838240c6017e1f635f3f93 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -233,9 +233,19 @@ class ResController $attachments = AttachmentModel::get(['select' => ['count(1)'], 'where' => ['res_id_master = ?', 'status in (?)'], 'data' => [$args['resId'], ['TRA', 'A_TRA', 'FRZ']]]); $formattedData['attachments'] = $attachments[0]['count']; + $formattedData['diffusionList'] = 0; + $formattedData['visaCircuit'] = 0; + $formattedData['opinionCircuit'] = 0; + $listInstanceItems = ListInstanceModel::get(['select' => ['count(1)', 'difflist_type'], 'where' => ['res_id = ?'], 'data' => [$args['resId']], 'groupBy' => ['difflist_type']]); + foreach ($listInstanceItems as $item) { + $type = $item['difflist_type'] == 'entity_id' ? 'diffusionList' : ($item['difflist_type'] == 'visaCircuit' ? 'visaCircuitItems' : 'opinionCircuit'); + $formattedData[$type] = $item['count']; + } + $followed = UserFollowedResourceModel::get([ - 'where' => ['user_id = ?', 'res_id = ?'], - 'data' => [$GLOBALS['id'], $args['resId']] + 'select' => [1], + 'where' => ['user_id = ?', 'res_id = ?'], + 'data' => [$GLOBALS['id'], $args['resId']] ]); $formattedData['followed'] = !empty($followed); }