Skip to content
Snippets Groups Projects
Commit 9fd7b6f1 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #11996 TIME 2:00 added enable/disable routes

parent fbf7197a
No related branches found
No related tags found
No related merge requests found
...@@ -237,6 +237,8 @@ $app->get('/indexingModels/entities', \IndexingModel\controllers\IndexingModelCo ...@@ -237,6 +237,8 @@ $app->get('/indexingModels/entities', \IndexingModel\controllers\IndexingModelCo
$app->get('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':getById'); $app->get('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':getById');
$app->post('/indexingModels', \IndexingModel\controllers\IndexingModelController::class . ':create'); $app->post('/indexingModels', \IndexingModel\controllers\IndexingModelController::class . ':create');
$app->put('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':update'); $app->put('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':update');
$app->put('/indexingModels/{id}/disable', \IndexingModel\controllers\IndexingModelController::class . ':disable');
$app->put('/indexingModels/{id}/enable', \IndexingModel\controllers\IndexingModelController::class . ':enable');
$app->delete('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':delete'); $app->delete('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':delete');
//Jnlp //Jnlp
......
...@@ -32,7 +32,13 @@ class IndexingModelController ...@@ -32,7 +32,13 @@ class IndexingModelController
{ {
public function get(Request $request, Response $response) public function get(Request $request, Response $response)
{ {
$models = IndexingModelModel::get(['where' => ['owner = ? OR private = ?'], 'data' => [$GLOBALS['id'], 'false']]); $where = ['(owner = ? OR private = ?)'];
if (!ServiceModel::hasService(['id' => 'admin_indexing_models', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
$where[] = 'enabled = TRUE';
}
$models = IndexingModelModel::get(['where' => $where, 'data' => [$GLOBALS['id'], 'false']]);
return $response->withJson(['indexingModels' => $models]); return $response->withJson(['indexingModels' => $models]);
} }
...@@ -359,6 +365,56 @@ class IndexingModelController ...@@ -359,6 +365,56 @@ class IndexingModelController
return $response->withStatus(204); return $response->withStatus(204);
} }
public function disable(Request $request, Response $response, array $args) {
if (!ServiceModel::hasService(['id' => 'admin_indexing_models', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
if (!Validator::intVal()->notEmpty()->validate($args['id'])) {
return $response->withStatus(400)->withJson(['errors' => 'Route id is empty or not an integer']);
}
$model = IndexingModelModel::getById(['select' => ['enabled'], 'id' => $args['id']]);
if (empty($model)) {
return $response->withStatus(400)->withJson(['errors' => 'Model not found']);
}
IndexingModelModel::update([
'set' => [
'enabled' => 'false'
],
'where' => ['id = ? or master = ?'],
'data' => [$args['id'], $args['id']]
]);
return $response->withStatus(204);
}
public function enable(Request $request, Response $response, array $args) {
if (!ServiceModel::hasService(['id' => 'admin_indexing_models', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
if (!Validator::intVal()->notEmpty()->validate($args['id'])) {
return $response->withStatus(400)->withJson(['errors' => 'Route id is empty or not an integer']);
}
$model = IndexingModelModel::getById(['select' => ['enabled'], 'id' => $args['id']]);
if (empty($model)) {
return $response->withStatus(400)->withJson(['errors' => 'Model not found']);
}
IndexingModelModel::update([
'set' => [
'enabled' => 'true'
],
'where' => ['id = ? or master = ?'],
'data' => [$args['id'], $args['id']]
]);
return $response->withStatus(204);
}
public function getEntities(Request $request, Response $response, array $aArgs) public function getEntities(Request $request, Response $response, array $aArgs)
{ {
$entitiesTmp = EntityModel::get([ $entitiesTmp = EntityModel::get([
......
...@@ -354,6 +354,97 @@ class IndexingModelControllerTest extends TestCase ...@@ -354,6 +354,97 @@ class IndexingModelControllerTest extends TestCase
$this->assertNotEmpty($responseBody->indexingModels); $this->assertNotEmpty($responseBody->indexingModels);
} }
public function testEnabled() {
$indexingModelController = new \IndexingModel\controllers\IndexingModelController();
// GET BY ID
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$masterId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId2]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
// Disable
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $indexingModelController->disable($request, new \Slim\Http\Response(), ['id' => self::$masterId]);
$this->assertSame(204, $response->getStatusCode());
// GET BY ID
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$masterId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(false, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(false, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId2]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(false, $responseBody->indexingModel->enabled);
// Enable
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $indexingModelController->enable($request, new \Slim\Http\Response(), ['id' => self::$masterId]);
$this->assertSame(204, $response->getStatusCode());
// GET BY ID
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$masterId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
$response = $indexingModelController->getById($request, new \Slim\Http\Response(), ['id' => self::$childId2]);
$this->assertSame(200, $response->getStatusCode());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame(true, $responseBody->indexingModel->enabled);
}
public function testDelete() public function testDelete()
{ {
$indexingModelController = new \IndexingModel\controllers\IndexingModelController(); $indexingModelController = new \IndexingModel\controllers\IndexingModelController();
......
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