Skip to content
Snippets Groups Projects
Verified Commit 417bf5ae authored by Damien's avatar Damien
Browse files

FEAT #13664 TIME 2:20 Alfresco accounts controller

parent dd4942f6
No related branches found
No related tags found
No related merge requests found
...@@ -564,6 +564,8 @@ $app->get('/externalConnectionsEnabled', \SrcCore\controllers\CoreController::cl ...@@ -564,6 +564,8 @@ $app->get('/externalConnectionsEnabled', \SrcCore\controllers\CoreController::cl
$app->get('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':getAccounts'); $app->get('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':getAccounts');
$app->post('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':createAccount'); $app->post('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':createAccount');
$app->get('/alfresco/accounts/{id}', \Alfresco\controllers\AlfrescoController::class . ':getAccountById'); $app->get('/alfresco/accounts/{id}', \Alfresco\controllers\AlfrescoController::class . ':getAccountById');
$app->put('/alfresco/accounts/{id}', \Alfresco\controllers\AlfrescoController::class . ':updateAccount');
$app->delete('/alfresco/accounts/{id}', \Alfresco\controllers\AlfrescoController::class . ':deleteAccount');
$app->get('/alfresco/rootFolders', \Alfresco\controllers\AlfrescoController::class . ':getRootFolders'); $app->get('/alfresco/rootFolders', \Alfresco\controllers\AlfrescoController::class . ':getRootFolders');
$app->get('/alfresco/folders/{id}/children', \Alfresco\controllers\AlfrescoController::class . ':getChildrenFoldersById'); $app->get('/alfresco/folders/{id}/children', \Alfresco\controllers\AlfrescoController::class . ':getChildrenFoldersById');
$app->get('/alfresco/autocomplete/folders', \Alfresco\controllers\AlfrescoController::class . ':getFolders'); $app->get('/alfresco/autocomplete/folders', \Alfresco\controllers\AlfrescoController::class . ':getFolders');
......
...@@ -79,6 +79,7 @@ class AlfrescoController ...@@ -79,6 +79,7 @@ class AlfrescoController
'id' => $alfresco['alfresco']['id'], 'id' => $alfresco['alfresco']['id'],
'label' => $alfresco['alfresco']['label'], 'label' => $alfresco['alfresco']['label'],
'login' => $alfresco['alfresco']['login'], 'login' => $alfresco['alfresco']['login'],
'nodeId' => $alfresco['alfresco']['nodeId'],
'entities' => [] 'entities' => []
]; ];
...@@ -109,6 +110,16 @@ class AlfrescoController ...@@ -109,6 +110,16 @@ class AlfrescoController
return $response->withStatus(400)->withJson(['errors' => 'Body entities is empty or not an array']); return $response->withStatus(400)->withJson(['errors' => 'Body entities is empty or not an array']);
} }
foreach ($body['entities'] as $entity) {
if (!Validator::intVal()->notEmpty()->validate($entity)) {
return $response->withStatus(400)->withJson(['errors' => 'Body entities contains no integer values']);
}
}
$entities = EntityModel::get(['select' => ['id'], 'where' => ['id in (?)'], 'data' => [$body['entities']]]);
if (count($entities) != count($body['entities'])) {
return $response->withStatus(400)->withJson(['errors' => 'Some entities do not exist']);
}
$id = CoreConfigModel::uniqueId(); $id = CoreConfigModel::uniqueId();
$account = [ $account = [
'id' => $id, 'id' => $id,
...@@ -128,6 +139,89 @@ class AlfrescoController ...@@ -128,6 +139,89 @@ class AlfrescoController
return $response->withStatus(204); return $response->withStatus(204);
} }
public function updateAccount(Request $request, Response $response, array $args)
{
// if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_alfresco', 'userId' => $GLOBALS['id']])) {
// return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
// }
$body = $request->getParsedBody();
if (!Validator::stringType()->notEmpty()->validate($body['label'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string']);
} elseif (!Validator::stringType()->notEmpty()->validate($body['login'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body login is empty or not a string']);
} elseif (!Validator::stringType()->notEmpty()->validate($body['nodeId'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body nodeId is empty or not a string']);
} elseif (!Validator::arrayType()->notEmpty()->validate($body['entities'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body entities is empty or not an array']);
}
$accounts = EntityModel::get(['select' => ['external_id', 'id'], 'where' => ["external_id->'alfresco'->>'id' = ?"], 'data' => [$args['id']]]);
if (empty($accounts[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Account not found']);
}
foreach ($body['entities'] as $entity) {
if (!Validator::intVal()->notEmpty()->validate($entity)) {
return $response->withStatus(400)->withJson(['errors' => 'Body entities contains no integer values']);
}
}
$entities = EntityModel::get(['select' => ['id'], 'where' => ['id in (?)'], 'data' => [$body['entities']]]);
if (count($entities) != count($body['entities'])) {
return $response->withStatus(400)->withJson(['errors' => 'Some entities do not exist']);
}
$alfresco = json_decode($accounts[0]['external_id'], true);
$account = [
'id' => $args['id'],
'label' => $body['label'],
'login' => $body['login'],
'password' => empty($body['password']) ? $alfresco['alfresco']['password'] : PasswordModel::encrypt(['password' => $body['password']]),
'nodeId' => $body['nodeId']
];
$account = json_encode($account);
EntityModel::update([
'postSet' => ['external_id' => "jsonb_set(external_id, '{alfresco}', '{$account}')"],
'where' => ['id in (?)'],
'data' => [$body['entities']]
]);
$previousEntities = array_column($accounts, 'id');
$entitiesToRemove = array_diff($previousEntities, $body['entities']);
if (!empty($entitiesToRemove)) {
EntityModel::update([
'postSet' => ['external_id' => "external_id - 'alfresco'"],
'where' => ['id in (?)'],
'data' => [$entitiesToRemove]
]);
}
return $response->withStatus(204);
}
public function deleteAccount(Request $request, Response $response, array $args)
{
// if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_alfresco', 'userId' => $GLOBALS['id']])) {
// return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
// }
$accounts = EntityModel::get(['select' => ['external_id', 'id'], 'where' => ["external_id->'alfresco'->>'id' = ?"], 'data' => [$args['id']]]);
if (empty($accounts[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Account not found']);
}
$entitiesToRemove = array_column($accounts, 'id');
EntityModel::update([
'postSet' => ['external_id' => "external_id - 'alfresco'"],
'where' => ['id in (?)'],
'data' => [$entitiesToRemove]
]);
return $response->withStatus(204);
}
public function getRootFolders(Request $request, Response $response) public function getRootFolders(Request $request, Response $response)
{ {
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/alfrescoConfig.xml']); $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/alfrescoConfig.xml']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment