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

FEAT #56 Enable and disable entity

parent 7eb7aeb1
No related branches found
No related tags found
No related merge requests found
...@@ -210,6 +210,7 @@ $app->get('/entities', \Entity\controllers\EntityController::class . ':get'); ...@@ -210,6 +210,7 @@ $app->get('/entities', \Entity\controllers\EntityController::class . ':get');
$app->delete('/entities/{id}', \Entity\controllers\EntityController::class . ':delete'); $app->delete('/entities/{id}', \Entity\controllers\EntityController::class . ':delete');
$app->get('/entities/{id}/details', \Entity\controllers\EntityController::class . ':getDetailledById'); $app->get('/entities/{id}/details', \Entity\controllers\EntityController::class . ':getDetailledById');
$app->put('/entities/{id}/reassign/{newEntityId}', \Entity\controllers\EntityController::class . ':reassignEntity'); $app->put('/entities/{id}/reassign/{newEntityId}', \Entity\controllers\EntityController::class . ':reassignEntity');
$app->put('/entities/{id}/status', \Entity\controllers\EntityController::class . ':updateStatus');
//Parameters //Parameters
$app->get('/parameters', \Parameter\controllers\ParameterController::class . ':get'); $app->get('/parameters', \Parameter\controllers\ParameterController::class . ':get');
......
...@@ -153,6 +153,13 @@ class EntityController ...@@ -153,6 +153,13 @@ class EntityController
return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); return $response->withStatus(400)->withJson(['errors' => 'Entity not found']);
} }
$aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]);
foreach ($aEntities as $aEntity) {
if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) {
return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']);
}
}
$data = $request->getParams(); $data = $request->getParams();
$check = Validator::stringType()->notEmpty()->validate($data['entity_label']); $check = Validator::stringType()->notEmpty()->validate($data['entity_label']);
...@@ -304,4 +311,48 @@ class EntityController ...@@ -304,4 +311,48 @@ class EntityController
return $response->withJson(['entities' => $entities]); return $response->withJson(['entities' => $entities]);
} }
public function updateStatus(Request $request, Response $response, array $aArgs)
{
if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]);
if (empty($entity)) {
return $response->withStatus(400)->withJson(['errors' => 'Entity not found']);
}
$aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]);
foreach ($aEntities as $aEntity) {
if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) {
return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']);
}
}
$data = $request->getParams();
$check = Validator::stringType()->notEmpty()->validate($data['method']);
if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
if ($data['method'] == 'disable') {
$status = 'N';
} else {
$status = 'Y';
}
$fatherAndSons = EntityModel::getEntityChildren(['entityId' => $aArgs['id']]);
EntityModel::update(['set' => ['enabled' => $status], 'where' => ['entity_id in (?)'], 'data' => [$fatherAndSons]]);
HistoryController::add([
'tableName' => 'entities',
'recordId' => $aArgs['id'],
'eventType' => 'UP',
'info' => _ENTITY_MODIFICATION . " : {$aArgs['id']}",
'moduleId' => 'entity',
'eventId' => 'entityModification',
]);
return $response->withJson(['success' => 'success']);
}
} }
...@@ -92,7 +92,7 @@ class EntityModelAbstract ...@@ -92,7 +92,7 @@ class EntityModelAbstract
ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']);
ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']);
DatabaseModel::delete([ DatabaseModel::update([
'table' => 'entities', 'table' => 'entities',
'set' => $aArgs['set'], 'set' => $aArgs['set'],
'where' => $aArgs['where'], 'where' => $aArgs['where'],
......
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