From 658095f1e6463f2c0653fb96bf3de8ee01fb0532 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Fri, 24 Apr 2020 15:20:31 +0200 Subject: [PATCH] FEAT #13664 TIME 0:50 Alfresco config controller --- rest/index.php | 2 + .../models/ConfigurationModel.php | 40 ++++++++++++------ .../controllers/AlfrescoController.php | 41 +++++++++++++++++++ .../template/models/TemplateModelAbstract.php | 26 ++++++------ 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/rest/index.php b/rest/index.php index f934fd38fef..42bfda5e2b9 100755 --- a/rest/index.php +++ b/rest/index.php @@ -561,6 +561,8 @@ $app->get('/externalSummary/{resId}', \ExternalSummary\controllers\SummaryContro $app->get('/externalConnectionsEnabled', \SrcCore\controllers\CoreController::class . ':externalConnectionsEnabled'); //Alfresco +$app->get('/alfresco/configuration', \Alfresco\controllers\AlfrescoController::class . ':getConfiguration'); +$app->put('/alfresco/configuration', \Alfresco\controllers\AlfrescoController::class . ':updateConfiguration'); $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'); diff --git a/src/app/configuration/models/ConfigurationModel.php b/src/app/configuration/models/ConfigurationModel.php index f7d7ec12d9d..c13070d83a9 100755 --- a/src/app/configuration/models/ConfigurationModel.php +++ b/src/app/configuration/models/ConfigurationModel.php @@ -19,17 +19,17 @@ use SrcCore\models\ValidatorModel; class ConfigurationModel { - public static function getByService(array $aArgs) + public static function getByService(array $args) { - ValidatorModel::notEmpty($aArgs, ['service']); - ValidatorModel::stringType($aArgs, ['service']); - ValidatorModel::arrayType($aArgs, ['select']); + ValidatorModel::notEmpty($args, ['service']); + ValidatorModel::stringType($args, ['service']); + ValidatorModel::arrayType($args, ['select']); $configuration = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'select' => empty($args['select']) ? ['*'] : $args['select'], 'table' => ['configurations'], 'where' => ['service = ?'], - 'data' => [$aArgs['service']], + 'data' => [$args['service']], ]); if (empty($configuration[0])) { @@ -39,16 +39,32 @@ class ConfigurationModel return $configuration[0]; } - public static function update(array $aArgs) + public static function create(array $args) { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); + ValidatorModel::notEmpty($args, ['service', 'value']); + ValidatorModel::stringType($args, ['service', 'value']); + + DatabaseModel::insert([ + 'table' => 'configurations', + 'columnsValues' => [ + 'service' => $args['service'], + 'value' => $args['value'] + ] + ]); + + return true; + } + + public static function update(array $args) + { + ValidatorModel::notEmpty($args, ['set', 'where', 'data']); + ValidatorModel::arrayType($args, ['set', 'where', 'data']); DatabaseModel::update([ 'table' => 'configurations', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] + 'set' => $args['set'], + 'where' => $args['where'], + 'data' => $args['data'] ]); return true; diff --git a/src/app/external/alfresco/controllers/AlfrescoController.php b/src/app/external/alfresco/controllers/AlfrescoController.php index d7978d58931..2a02546fb8b 100644 --- a/src/app/external/alfresco/controllers/AlfrescoController.php +++ b/src/app/external/alfresco/controllers/AlfrescoController.php @@ -15,6 +15,7 @@ namespace Alfresco\controllers; use Attachment\models\AttachmentModel; +use Configuration\models\ConfigurationModel; use Convert\controllers\ConvertPdfController; use Docserver\models\DocserverModel; use Entity\models\EntityModel; @@ -31,6 +32,46 @@ use User\models\UserModel; class AlfrescoController { + public function getConfiguration(Request $request, Response $response) + { + // if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_alfresco', 'userId' => $GLOBALS['id']])) { +// return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); +// } + + $configuration = ConfigurationModel::getByService(['service' => 'admin_alfresco']); + if (empty($configuration)) { + return $response->withJson(['configuration' => null]); + } + + $configuration['value'] = json_decode($configuration['value'], true); + + return $response->withJson(['configuration' => ['uri' => $configuration['value']['uri']]]); + } + + public function updateConfiguration(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['uri'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body uri is empty or not a string']); + } + + $value = json_encode(['uri' => $body['uri']]); + + $configuration = ConfigurationModel::getByService(['service' => 'admin_alfresco']); + if (empty($configuration)) { + ConfigurationModel::create(['service' => 'admin_alfresco', 'value' => $value]); + } else { + ConfigurationModel::update(['set' => ['value' => $value], 'where' => ['service = ?'], 'data' => ['admin_alfresco']]); + } + + return $response->withStatus(204); + } + public function getAccounts(Request $request, Response $response) { // if (!PrivilegeController::hasPrivilege(['privilegeId' => 'admin_alfresco', 'userId' => $GLOBALS['id']])) { diff --git a/src/app/template/models/TemplateModelAbstract.php b/src/app/template/models/TemplateModelAbstract.php index 6f7c5f5fd31..7780d2cfab6 100755 --- a/src/app/template/models/TemplateModelAbstract.php +++ b/src/app/template/models/TemplateModelAbstract.php @@ -86,10 +86,10 @@ abstract class TemplateModelAbstract return $aTemplate; } - public static function create(array $aArgs) + public static function create(array $args) { - ValidatorModel::notEmpty($aArgs, ['template_label']); - ValidatorModel::stringType($aArgs, ['template_label']); + ValidatorModel::notEmpty($args, ['template_label']); + ValidatorModel::stringType($args, ['template_label']); $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'templates_seq']); @@ -97,16 +97,16 @@ abstract class TemplateModelAbstract 'table' => 'templates', 'columnsValues' => [ 'template_id' => $nextSequenceId, - 'template_label' => $aArgs['template_label'], - 'template_comment' => $aArgs['template_comment'], - 'template_content' => $aArgs['template_content'], - 'template_type' => $aArgs['template_type'], - 'template_style' => $aArgs['template_style'], - 'template_datasource' => $aArgs['template_datasource'], - 'template_target' => $aArgs['template_target'], - 'template_attachment_type' => $aArgs['template_attachment_type'], - 'template_path' => $aArgs['template_path'], - 'template_file_name' => $aArgs['template_file_name'], + 'template_label' => $args['template_label'], + 'template_comment' => $args['template_comment'], + 'template_content' => $args['template_content'], + 'template_type' => $args['template_type'], + 'template_style' => $args['template_style'], + 'template_datasource' => $args['template_datasource'], + 'template_target' => $args['template_target'], + 'template_attachment_type' => $args['template_attachment_type'], + 'template_path' => $args['template_path'], + 'template_file_name' => $args['template_file_name'], ] ]); -- GitLab