diff --git a/rest/index.php b/rest/index.php index f8db28406b7169605150e6a82907d0921348998c..d921b0c5561a0ef78316f08862ba9b9ea26693ed 100755 --- a/rest/index.php +++ b/rest/index.php @@ -372,7 +372,6 @@ $app->get('/categories', \Resource\controllers\ResController::class . ':getCateg $app->get('/resources/{resId}/users/{userId}/isDestinationChanging', \Action\controllers\PreProcessActionController::class . ':isDestinationChanging'); $app->get('/resources/{resId}/users/{userId}/groups/{groupId}/baskets/{basketId}/processingData', \Resource\controllers\ResController::class . ':getProcessingData'); $app->post('/resources/exportData', \Resource\controllers\ResourceDataExportController::class . ':generateFile'); -$app->put('/resources/{resId}/integrations', \Resource\controllers\ResController::class . ':setInIntegrations'); //ResourcesList $app->get('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}', \Resource\controllers\ResourceListController::class . ':get'); @@ -385,6 +384,7 @@ $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/su $app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}', \Resource\controllers\ResourceListController::class . ':setAction'); $app->get('/resourcesList/exportTemplate', \Resource\controllers\ExportController::class . ':getExportTemplates'); $app->get('/resourcesList/summarySheets', \Resource\controllers\SummarySheetController::class . ':createListWithAll'); +$app->put('/resourcesList/integrations', \Resource\controllers\ResController::class . ':setInIntegrations'); $app->post('/acknowledgementReceipt', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':createPaperAcknowledgement'); //PreProcess $app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/checkAcknowledgementReceipt', \Action\controllers\PreProcessActionController::class . ':checkAcknowledgementReceipt'); diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 66e15fdaa71540e350859164a976209065535339..b0225c6f3f2b872fd11ef324b18068fca5431016 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -679,41 +679,51 @@ class ResController extends ResourceControlController return $response->withJson(['success' => 'success']); } - public static function setInIntegrations(Request $request, Response $response, array $args) + public static function setInIntegrations(Request $request, Response $response) { - if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - $body = $request->getParsedBody(); - if (empty($body['integrations'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body param integrations is missing']); + if (empty($body['resources']) || !Validator::arrayType()->validate($body['resources'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body param resources is missing']); } - - $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['integrations']]); - $integrations = json_decode($resource['integrations'], true); - - if (Validator::boolType()->validate($body['integrations']['inSignatureBook'])) { - $integrations['inSignatureBook'] = $body['integrations']['inSignatureBook']; - } else { - $integrations['inSignatureBook'] = $integrations['inSignatureBook'] ?? false; + if (!ResController::hasRightByResId(['resId' => $body['resources'], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } - if (Validator::boolType()->validate($body['integrations']['inShipping'])) { - $integrations['inShipping'] = $body['integrations']['inShipping']; - } else { - $integrations['inShipping'] = $integrations['inShipping'] ?? false; + if (empty($body['integrations']) || !Validator::arrayType()->validate($body['integrations'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body param integrations is missing or not an array']); } - ResModel::update([ - 'set' => [ - 'integrations' => json_encode($integrations) - ], - 'where' => ['res_id = ?'], - 'data' => [$args['resId']] + $resources = ResModel::get([ + 'select' => ['res_id', 'integrations'], + 'where' => ['res_id in (?)'], + 'data' => [$body['resources']] ]); + foreach ($resources as $resource) { + $integrations = json_decode($resource['integrations'], true); + + if (Validator::boolType()->validate($body['integrations']['inSignatureBook'])) { + $integrations['inSignatureBook'] = $body['integrations']['inSignatureBook']; + } else { + $integrations['inSignatureBook'] = $integrations['inSignatureBook'] ?? false; + } + + if (Validator::boolType()->validate($body['integrations']['inShipping'])) { + $integrations['inShipping'] = $body['integrations']['inShipping']; + } else { + $integrations['inShipping'] = $integrations['inShipping'] ?? false; + } + + ResModel::update([ + 'set' => [ + 'integrations' => json_encode($integrations) + ], + 'where' => ['res_id = ?'], + 'data' => [$resource['res_id']] + ]); + } + return $response->withStatus(204); }