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

FEAT #13664 TIME 1:50 Get Alfresco accounts + create

parent fbbe102a
No related branches found
No related tags found
No related merge requests found
......@@ -562,6 +562,8 @@ $app->get('/externalConnectionsEnabled', \SrcCore\controllers\CoreController::cl
//Alfresco
$app->get('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':getAccounts');
$app->post('/alfresco/accounts', \Alfresco\controllers\AlfrescoController::class . ':createAccount');
$app->get('/alfresco/accounts/{id}', \Alfresco\controllers\AlfrescoController::class . ':getAccountById');
$app->get('/alfresco/rootFolders', \Alfresco\controllers\AlfrescoController::class . ':getRootFolders');
$app->get('/alfresco/folders/{id}/children', \Alfresco\controllers\AlfrescoController::class . ':getChildrenFoldersById');
$app->get('/alfresco/autocomplete/folders', \Alfresco\controllers\AlfrescoController::class . ':getFolders');
......
......@@ -112,21 +112,17 @@ abstract class EntityModelAbstract
return true;
}
public static function update(array $aArgs)
public static function update(array $args)
{
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
ValidatorModel::stringType($aArgs['set'], [
'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3',
'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id',
'ldap_id', 'transferring_agency', 'archival_agreement', 'archival_agency', 'entity_full_name'
]);
ValidatorModel::notEmpty($args, ['where', 'data']);
ValidatorModel::arrayType($args, ['set', 'postSet', 'where', 'data']);
DatabaseModel::update([
'table' => 'entities',
'set' => $aArgs['set'],
'where' => $aArgs['where'],
'data' => $aArgs['data']
'table' => 'entities',
'set' => $args['set'],
'postSet' => $args['postSet'],
'where' => $args['where'],
'data' => $args['data']
]);
return true;
......
......@@ -37,24 +37,97 @@ class AlfrescoController
// return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
// }
$entities = EntityModel::get(['select' => ['external_id'], 'where' => ["external_id->>'alfresco' is not null"]]);
$entities = EntityModel::get(['select' => ['external_id', 'short_label'], 'where' => ["external_id->>'alfresco' is not null"]]);
$accounts = [];
$alreadyAdded = [];
foreach ($entities as $entity) {
$alfresco = json_decode($entity['external_id'], true);
if (!in_array($alfresco['alfresco']['login'], $alreadyAdded)) {
if (!in_array($alfresco['alfresco']['id'], $alreadyAdded)) {
$accounts[] = [
'label' => $alfresco['alfresco']['label'],
'login' => $alfresco['alfresco']['login']
'id' => $alfresco['alfresco']['id'],
'label' => $alfresco['alfresco']['label'],
'login' => $alfresco['alfresco']['login'],
'entitiesLabel' => [$entity['short_label']]
];
$alreadyAdded[] = $alfresco['alfresco']['login'];
$alreadyAdded[] = $alfresco['alfresco']['id'];
} else {
foreach ($accounts as $key => $value) {
if ($value['id'] == $alfresco['alfresco']['id']) {
$accounts[$key]['entitiesLabel'][] = $entity['short_label'];
}
}
}
}
return $response->withJson(['accounts' => $accounts]);
}
public function getAccountById(Request $request, Response $response, array $args)
{
// if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_alfresco', 'userId' => $GLOBALS['id']])) {
// return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
// }
$entities = EntityModel::get(['select' => ['external_id', 'id'], 'where' => ["external_id->'alfresco'->>'id' = ?"], 'data' => [$args['id']]]);
if (empty($entities[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Account not found']);
}
$alfresco = json_decode($entities[0]['external_id'], true);
$account = [
'id' => $alfresco['alfresco']['id'],
'label' => $alfresco['alfresco']['label'],
'login' => $alfresco['alfresco']['login'],
'entities' => []
];
foreach ($entities as $entity) {
$account['entities'][] = $entity['id'];
}
return $response->withJson($account);
}
public function createAccount(Request $request, Response $response)
{
// 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['password'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body password 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']);
}
$id = CoreConfigModel::uniqueId();
$account = [
'id' => $id,
'label' => $body['label'],
'login' => $body['login'],
'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']]
]);
return $response->withStatus(204);
}
public function getRootFolders(Request $request, Response $response)
{
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/alfrescoConfig.xml']);
......
......@@ -45,7 +45,7 @@ class PriorityController
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$data = $request->getParams();
$data = $request->getParsedBody();
$check = Validator::stringType()->notEmpty()->validate($data['label']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['color']);
$check = $check && (Validator::intVal()->notEmpty()->validate($data['delays']) || $data['delays'] == 0);
......
......@@ -1673,7 +1673,7 @@ export const LANG_FR = {
"accountSuspended": "Votre compte utilisateur a été suspendu",
"accountLocked": "Nombre de tentatives de connexion dépassée. Réessayez dans",
"modelUsedByResources": "Le modèle est utilisé par des courriers, vous ne pouvez pas le supprimer.",
"mustChangePassword": "Vous êtes invité à changer votre mot de passe.",
"mustChangePassword": "Vous êtes invités à changer votre mot de passe.",
"linkedResources": "Pièces jointes (courriers liés)",
"accessNotFound": "Accès introuvable",
"moreOneCustom": "Cette url ne correspond à aucune instance configurée, veuillez vérifier l'adresse.",
......
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