From 90382c69af5a6c3573396c4cef64da249adadcbd Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 18 Jul 2016 10:42:18 +0200 Subject: [PATCH] Renommage du repo 'association' en 'action_merge' --- config/modules.json | 9 ++++ config/repositories.json | 11 +++- manager/module/machineDefault.php | 40 ++++++++++++++ manager/repo/action.php | 17 ++++++ .../{association.php => action_merge.php} | 54 +++++++++---------- test/automate.php | 3 +- 6 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 manager/repo/action.php rename manager/repo/{association.php => action_merge.php} (77%) diff --git a/config/modules.json b/config/modules.json index a188c9d..ec92faf 100755 --- a/config/modules.json +++ b/config/modules.json @@ -237,6 +237,15 @@ } }, + "init": { + "description": "Données d'initialisation d'une machine.", + "permissions": ["warehouse"], + "parameters": {}, + "output": { + "data": { "description": "Données d'initialisation.", "type": "array" } + } + }, + "create": { "description": "Création d'une nouvelle machine.", "permissions": ["warehouse", "admin"], diff --git a/config/repositories.json b/config/repositories.json index 29cc05f..0b9df17 100755 --- a/config/repositories.json +++ b/config/repositories.json @@ -51,7 +51,7 @@ ], - "association": [ + "action_merge": [ "addPermission", "removePermission", @@ -60,6 +60,15 @@ "getByIdTarget" ], + "action": [ + "getById", + "removePermission", + + "getAll", + "getById", + "getByIdTarget" + ], + "permission": [ "getAll", "getById" diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 3004e48..ec4e2c4 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -353,6 +353,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* SYNCHRONISE UNE MACHINE * * @token Token de synchronisation de la machine diff --git a/manager/repo/action.php b/manager/repo/action.php new file mode 100644 index 0000000..6fed6ca --- /dev/null +++ b/manager/repo/action.php @@ -0,0 +1,17 @@ + diff --git a/manager/repo/association.php b/manager/repo/action_merge.php similarity index 77% rename from manager/repo/association.php rename to manager/repo/action_merge.php index 1775b02..aabef72 100644 --- a/manager/repo/association.php +++ b/manager/repo/action_merge.php @@ -6,21 +6,21 @@ use \manager\ManagerError; use \manager\repo\cluster as clusterRepo; - class association extends parentRepo{ + class action_merge extends parentRepo{ - protected static function table_name(){ static $table_name = 'association'; return $table_name; } + protected static function table_name(){ static $table_name = 'action_merge'; return $table_name; } /* AJOUT D'UNE PERMISSION ENTRE 2 GROUPES (UTIL -> MACHINE) * * @id_target UID d'un groupe MACHINE * @id_source UID d'un groupe UTILISATEUR - * @id_permission UID d'une PERMISSION + * @id_action UID d'une ACTION * * @return error Retourne l'erreur 'ManagerError' associée * */ - public static function addPermission($id_target, $id_source, $id_permission){ + public static function addPermission($id_target, $id_source, $id_action){ /* [1] On vérifie l'existance du groupe 'target' =========================================================*/ @@ -58,14 +58,14 @@ return ManagerError::NoMatchFound; - /* [3] On vérifie l'existance de la permission + /* [3] On vérifie l'existance de l'action =========================================================*/ /* (1) On rédige la requête */ - $permissionCheckR = new Repo('permission/getById', [ $id_permission ]); - $permissionCheck = $permissionCheckR->answer(); + $actionCheckR = new Repo('action/getById', [ $id_action ]); + $actionCheck = $actionCheckR->answer(); /* (2) Si aucun résultat, on retourne une erreur */ - if( $permissionCheck === false ) + if( $actionCheck === false ) return ManagerError::NoMatchFound; @@ -79,21 +79,21 @@ /* (3) Si les données sont identiques pour au moins une entrée, on retourne un succès */ foreach($checkAlready as $s=>$sameTarget) - if( $sameTarget['id_source'] == $id_source && $sameTarget['id_permission'] == $id_permission ) + if( $sameTarget['id_source'] == $id_source && $sameTarget['id_action'] == $id_action ) return ManagerError::Success; } - /* [5] On ajoute la permission + /* [5] On ajoute la action =========================================================*/ /* (1) On effectue l'insertion */ - $insert = Database::getPDO()->prepare("INSERT INTO association(id_association, id_target, id_source, id_permission) - VALUES(DEFAULT, :id_target, :id_source, :id_permission)"); + $insert = Database::getPDO()->prepare("INSERT INTO action_merge(id_action_merge, id_target, id_source, id_action) + VALUES(DEFAULT, :id_target, :id_source, :id_action)"); $inserted = $insert->execute([ ':id_target' => $id_target, ':id_source' => $id_source, - ':id_permission' => $id_permission + ':id_action' => $id_action ]); /* (2) Si erreur SQL, on retourne une erreur */ @@ -116,12 +116,12 @@ * * @id_target UID d'un groupe MACHINE * @id_source UID d'un groupe UTILISATEUR - * @id_permission UID d'une PERMISSION + * @id_action UID d'une PERMISSION * * @return error Retourne l'erreur 'ManagerError' associée * */ - public static function removePermission($id_target, $id_source, $id_permission){ + public static function removePermission($id_target, $id_source, $id_action){ /* [1] On vérifie que l'entrée existe =========================================================*/ @@ -134,8 +134,8 @@ /* (3) Si les données sont identiques pour au moins une entrée, on peut supprimer */ foreach($checkExists as $s=>$sameTarget) - if( $sameTarget['id_source'] == $id_source && $sameTarget['id_permission'] == $id_permission ) - $existingId = $sameTarget['id_association']; + if( $sameTarget['id_source'] == $id_source && $sameTarget['id_action'] == $id_action ) + $existingId = $sameTarget['id_action_merge']; } /* (3) Si on a pas trouvé, on retourne une erreur */ @@ -143,19 +143,19 @@ return ManagerError::NoMatchFound; - /* [2] On supprime la permission + /* [2] On supprime la action =========================================================*/ /* (1) On effectue la suppression */ - $delete = Database::getPDO()->prepare("DELETE FROM association - WHERE id_association = :id_association - AND id_target = :id_target - AND id_source = :id_source - AND id_permission = :id_permission"); + $delete = Database::getPDO()->prepare("DELETE FROM action_merge + WHERE id_action_merge = :id_action_merge + AND id_target = :id_target + AND id_source = :id_source + AND id_action = :id_action"); $deleted = $delete->execute([ - ':id_association' => $existingId, - ':id_target' => $id_target, - ':id_source' => $id_source, - ':id_permission' => $id_permission + ':id_action_merge' => $existingId, + ':id_target' => $id_target, + ':id_source' => $id_source, + ':id_action' => $id_action ]); /* (2) Si erreur SQL, on retourne une erreur */ diff --git a/test/automate.php b/test/automate.php index b96fce7..bb9a4cd 100755 --- a/test/automate.php +++ b/test/automate.php @@ -337,12 +337,13 @@ debug(); - $req = new Repo('association/removePermission', [ + $req = new Repo('action_merge/removePermission', [ 205, 2, 1 ]); + var_dump( $req->error ); var_dump( $req->answer() );