Skip to content
Snippets Groups Projects
Verified Commit 2ea567c7 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #10733 0:30 wip update groups

parent 89cfe774
No related branches found
No related tags found
No related merge requests found
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
"warnPrivateKey": "This cause security issues", "warnPrivateKey": "This cause security issues",
"ok": "Ok", "ok": "Ok",
"groupAdded" : "Group added", "groupAdded" : "Group added",
"groupdeleted" : "Group deleted" "groupdeleted" : "Group deleted",
"groupUpdated" : "Group updated"
} }
} }
...@@ -190,7 +190,8 @@ ...@@ -190,7 +190,8 @@
"warnPrivateKey": "Cela compromet la sécurité de l'application.", "warnPrivateKey": "Cela compromet la sécurité de l'application.",
"ok": "J'ai compris", "ok": "J'ai compris",
"groupAdded" : "Groupe ajouté", "groupAdded" : "Groupe ajouté",
"groupdeleted" : "Groupe supprimé" "groupdeleted" : "Groupe supprimé",
"groupUpdated" : "Groupe mis à jour"
} }
} }
...@@ -85,6 +85,7 @@ $app->post('/groups', \Group\controllers\GroupController::class . ':create'); ...@@ -85,6 +85,7 @@ $app->post('/groups', \Group\controllers\GroupController::class . ':create');
$app->get('/groups', \Group\controllers\GroupController::class . ':get'); $app->get('/groups', \Group\controllers\GroupController::class . ':get');
$app->get('/groups/{id}', \Group\controllers\GroupController::class . ':getById'); $app->get('/groups/{id}', \Group\controllers\GroupController::class . ':getById');
$app->delete('/groups/{id}', \Group\controllers\GroupController::class . ':delete'); $app->delete('/groups/{id}', \Group\controllers\GroupController::class . ':delete');
$app->put('/groups/{id}', \Group\controllers\GroupController::class . ':update');
//Users //Users
$app->post('/users', \User\controllers\UserController::class . ':create'); $app->post('/users', \User\controllers\UserController::class . ':create');
......
...@@ -63,6 +63,42 @@ class GroupController ...@@ -63,6 +63,42 @@ class GroupController
return $response->withJson(['id' => $id]); return $response->withJson(['id' => $id]);
} }
public function update(Request $request, Response $response, $aArgs)
{
if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_groups'])) {
return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']);
}
$body = $request->getParsedBody();
$group = GroupModel::getById(['id' => $aArgs['id']]);
if (empty($group)) {
return $response->withStatus(400)->withJson(['errors' => 'Group not found']);
}
if (empty($body)) {
return $response->withStatus(400)->withJson(['errors' => 'Body is not set or empty']);
} elseif (!Validator::stringType()->notEmpty()->length(1, 128)->validate($body['label'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body label is empty or not a string or longer than 128 caracteres']);
}
GroupModel::update([
'set' => ['label' => $body['label']],
'where' => ['id = ?'],
'data' => [$aArgs['id']]
]);
HistoryController::add([
'code' => 'OK',
'objectType' => 'groups',
'objectId' => $aArgs['id'],
'type' => 'UPDATE',
'message' => "{groupUpdated} : {$body['label']}"
]);
return $response->withStatus(204);
}
public function delete(Request $request, Response $response, $aArgs) public function delete(Request $request, Response $response, $aArgs)
{ {
if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_groups'])) { if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_groups'])) {
......
...@@ -72,6 +72,21 @@ class GroupModel ...@@ -72,6 +72,21 @@ class GroupModel
return $nextSequenceId; return $nextSequenceId;
} }
public static function update(array $args)
{
ValidatorModel::notEmpty($args, ['set', 'where', 'data']);
ValidatorModel::arrayType($args, ['set', 'where', 'data']);
DatabaseModel::update([
'table' => 'groups',
'set' => $args['set'],
'where' => $args['where'],
'data' => $args['data']
]);
return true;
}
public static function delete(array $args) public static function delete(array $args)
{ {
ValidatorModel::notEmpty($args, ['where', 'data']); ValidatorModel::notEmpty($args, ['where', 'data']);
......
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