Renommage du repo 'association' en 'action_merge'

This commit is contained in:
xdrm-brackets 2016-07-18 10:42:18 +02:00
parent 3919ede864
commit 90382c69af
6 changed files with 105 additions and 29 deletions

View File

@ -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<mixed>" }
}
},
"create": {
"description": "Création d'une nouvelle machine.",
"permissions": ["warehouse", "admin"],

View File

@ -51,7 +51,7 @@
],
"association": [
"action_merge": [
"addPermission",
"removePermission",
@ -60,6 +60,15 @@
"getByIdTarget"
],
"action": [
"getById",
"removePermission",
"getAll",
"getById",
"getByIdTarget"
],
"permission": [
"getAll",
"getById"

View File

@ -353,6 +353,46 @@
/* SYNCHRONISE UNE MACHINE
*
* @token<String> Token de synchronisation de la machine

17
manager/repo/action.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace manager\repo;
use \manager\Database;
use \manager\Repo;
use \manager\ManagerError;
use \manager\repo\cluster as clusterRepo;
class action extends parentRepo{
protected static function table_name(){ static $table_name = 'action'; return $table_name; }
}
?>

View File

@ -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<int> UID d'un groupe MACHINE
* @id_source<int> UID d'un groupe UTILISATEUR
* @id_permission<int> UID d'une PERMISSION
* @id_action<int> UID d'une ACTION
*
* @return error<ManagerError> 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<int> UID d'un groupe MACHINE
* @id_source<int> UID d'un groupe UTILISATEUR
* @id_permission<int> UID d'une PERMISSION
* @id_action<int> UID d'une PERMISSION
*
* @return error<ManagerError> 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 */

View File

@ -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() );