Verified Commit f4ee8799 authored by Damien's avatar Damien

FEAT #10828 TIME 1:00 Get documents from Maarch Parapheur

parent 3f2ab3ef
......@@ -192,6 +192,7 @@ $app->get('/header', \SrcCore\controllers\CoreController::class . ':getHeader');
//Home
$app->get('/home', \Home\controllers\HomeController::class . ':get');
$app->get('/home/lastRessources', \Home\controllers\HomeController::class . ':getLastRessources');
$app->get('/home/maarchParapheurDocuments', \Home\controllers\HomeController::class . ':getMaarchParapheurDocuments');
//Jnlp
$app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp');
......@@ -271,7 +272,6 @@ $app->get('/natures', \Resource\controllers\ResController::class . ':getNatures'
$app->get('/resources/{resId}/isAllowed', \Resource\controllers\ResController::class . ':isAllowedForCurrentUser');
$app->post('/resources/checkFileUpload', \Resource\controllers\StoreController::class . ':checkFileUpload');
//ResourcesList
$app->get('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}', \Resource\controllers\ResourceListController::class . ':get');
$app->get('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions', \Resource\controllers\ResourceListController::class . ':getActions');
......
......@@ -20,6 +20,8 @@ use Group\models\GroupModel;
use Resource\models\ResModel;
use Slim\Http\Request;
use Slim\Http\Response;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\CurlModel;
use User\models\UserModel;
use Parameter\models\ParameterModel;
......@@ -84,10 +86,24 @@ class HomeController
$assignedBaskets[$key]['ownerLogin'] = UserModel::getById(['id' => $assignedBasket['owner_user_id'], 'select' => ['user_id']])['user_id'];
}
$isMaarchParapheurConnected = false;
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']);
if (!empty($loadedXml)) {
foreach ($loadedXml->signatoryBook as $value) {
if ($value->id == "maarchParapheur") {
if (!empty($value->url) && !empty($value->userId) && !empty($value->password)) {
$isMaarchParapheurConnected = true;
}
break;
}
}
}
return $response->withJson([
'regroupedBaskets' => $regroupedBaskets,
'assignedBaskets' => $assignedBaskets,
'homeMessage' => $homeMessage,
'regroupedBaskets' => $regroupedBaskets,
'assignedBaskets' => $assignedBaskets,
'homeMessage' => $homeMessage,
'isMaarchParapheurConnected' => $isMaarchParapheurConnected
]);
}
......@@ -114,4 +130,57 @@ class HomeController
'lastResources' => $lastResources,
]);
}
public function getMaarchParapheurDocuments(Request $request, Response $response)
{
$user = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['external_id']]);
$externalId = json_decode($user['external_id'], true);
if (empty($externalId['maarchParapheur'])) {
return $response->withStatus(400)->withJson(['errors' => 'User is not linked to Maarch Parapheur']);
}
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']);
if (empty($loadedXml)) {
return $response->withStatus(400)->withJson(['errors' => 'SignatoryBooks configuration file missing']);
}
$url = '';
$userId = '';
$password = '';
foreach ($loadedXml->signatoryBook as $value) {
if ($value->id == "maarchParapheur") {
$url = $value->url;
$userId = $value->userId;
$password = $value->password;
break;
}
}
if (empty($url)) {
return $response->withStatus(400)->withJson(['errors' => 'Maarch Parapheur configuration missing']);
}
$curlResponse = CurlModel::execSimple([
'url' => rtrim($url, '/') . '/rest/documents',
'basicAuth' => ['user' => $userId, 'password' => $password],
'headers' => ['content-type:application/json'],
'method' => 'GET',
'queryParams' => ['userId' => $externalId['maarchParapheur'], 'limit' => 10]
]);
if ($curlResponse['code'] != '200') {
if (!empty($curlResponse['response']['errors'])) {
$errors = $curlResponse['response']['errors'];
} else {
$errors = $curlResponse['errors'];
}
if (empty($errors)) {
$errors = 'An error occured. Please check your configuration file.';
}
return $response->withStatus(400)->withJson(['errors' => $errors]);
}
return $response->withJson($curlResponse['response']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment