Création et 1re implémentation des repositories 'association' et 'permission' pour la gestion des permissions des groupes d'utilisateurs sur les groupes de machines + Màj du repo 'parentRepo' pour à partir d'un nom du type 'getByMyNewWord' il trouve 'my_new_word' en nom de colonne
This commit is contained in:
parent
0261fb7aa1
commit
2bb68b7d0a
|
@ -51,6 +51,21 @@
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
"association": [
|
||||||
|
"addPermission",
|
||||||
|
"removePermission",
|
||||||
|
|
||||||
|
"getAll",
|
||||||
|
"getById",
|
||||||
|
"getByIdTarget"
|
||||||
|
],
|
||||||
|
|
||||||
|
"permission": [
|
||||||
|
"getAll",
|
||||||
|
"getById"
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
"warehouse": [
|
"warehouse": [
|
||||||
"create",
|
"create",
|
||||||
"edit",
|
"edit",
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace manager\repo;
|
||||||
|
use \manager\Database;
|
||||||
|
use \manager\Repo;
|
||||||
|
use \manager\ManagerError;
|
||||||
|
use \manager\repo\cluster as clusterRepo;
|
||||||
|
|
||||||
|
class association extends parentRepo{
|
||||||
|
|
||||||
|
protected static function table_name(){ static $table_name = 'association'; 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
|
||||||
|
*
|
||||||
|
* @return error<ManagerError> Retourne l'erreur 'ManagerError' associée
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function addPermission($id_target, $id_source, $id_permission){
|
||||||
|
|
||||||
|
/* [1] On vérifie l'existance du groupe 'target'
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) On rédige la requête */
|
||||||
|
$targetCheckR = new Repo('cluster/getById', [
|
||||||
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
|
$id_target
|
||||||
|
]);
|
||||||
|
$targetCheck = $targetCheckR->answer();
|
||||||
|
|
||||||
|
/* (2) Si aucun résultat, on retourne une erreur */
|
||||||
|
if( $targetCheck === false )
|
||||||
|
return ManagerError::NoMatchFound;
|
||||||
|
|
||||||
|
/* (3) Si il s'agit bien d'un groupe de machines */
|
||||||
|
if( $targetCheck['class'] != clusterRepo::MACHINE_CLASS )
|
||||||
|
return ManagerError::NoMatchFound;
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] On vérifie l'existance du groupe 'source'
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) On rédige la requête */
|
||||||
|
$sourceCheckR = new Repo('cluster/getById', [
|
||||||
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
|
$id_source
|
||||||
|
]);
|
||||||
|
$sourceCheck = $sourceCheckR->answer();
|
||||||
|
|
||||||
|
/* (2) Si aucun résultat, on retourne une erreur */
|
||||||
|
if( $sourceCheck === false )
|
||||||
|
return ManagerError::NoMatchFound;
|
||||||
|
|
||||||
|
/* (3) Si il s'agit bien d'un groupe d'utilisateurs */
|
||||||
|
if( $sourceCheck['class'] != clusterRepo::USER_CLASS )
|
||||||
|
return ManagerError::NoMatchFound;
|
||||||
|
|
||||||
|
|
||||||
|
/* [3] On vérifie l'existance de la permission
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) On rédige la requête */
|
||||||
|
$permissionCheckR = new Repo('permission/getById', [ $id_permission ]);
|
||||||
|
$permissionCheck = $permissionCheckR->answer();
|
||||||
|
|
||||||
|
/* (2) Si aucun résultat, on retourne une erreur */
|
||||||
|
if( $permissionCheck === false )
|
||||||
|
return ManagerError::NoMatchFound;
|
||||||
|
|
||||||
|
|
||||||
|
/* [4] On vérifie que l'entrée n'existe pas déja
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) On effectue la requête */
|
||||||
|
$checkAlready = self::getByIdTarget($id_target);
|
||||||
|
|
||||||
|
/* (2) Si on a un résultat, on continue la vérification */
|
||||||
|
if( is_array($checkAlready) && count($checkAlready) > 0 ){
|
||||||
|
|
||||||
|
/* (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 )
|
||||||
|
return ManagerError::Success;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [5] On ajoute la permission
|
||||||
|
=========================================================*/
|
||||||
|
/* (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)");
|
||||||
|
$inserted = $insert->execute([
|
||||||
|
':id_target' => $id_target,
|
||||||
|
':id_source' => $id_source,
|
||||||
|
':id_permission' => $id_permission
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* (2) Si erreur SQL, on retourne une erreur */
|
||||||
|
if( !$inserted )
|
||||||
|
return ManagerError::RepoError;
|
||||||
|
|
||||||
|
|
||||||
|
return ManagerError::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
|
@ -48,7 +48,18 @@
|
||||||
|
|
||||||
/* [3] On vérifie que la valeur après 'get' est dans $table_columns
|
/* [3] On vérifie que la valeur après 'get' est dans $table_columns
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$columnName = strtolower($matches[1]);
|
$columnName = '';
|
||||||
|
|
||||||
|
for( $l = 0 ; $l < strlen($matches[1]) ; $l++ ){
|
||||||
|
$letter = $matches[1][$l];
|
||||||
|
|
||||||
|
// Si la lettre est en majuscule mais que c'est pas la première
|
||||||
|
if( strtoupper($letter) == $letter && $l > 0 )
|
||||||
|
$columnName .= '_';
|
||||||
|
|
||||||
|
$columnName .= strtolower($letter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$getAll = count($matches) > 2; // Si 'getAll'
|
$getAll = count($matches) > 2; // Si 'getAll'
|
||||||
$getById = $columnName == 'id';
|
$getById = $columnName == 'id';
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace manager\repo;
|
||||||
|
use \manager\Database;
|
||||||
|
use \manager\ManagerError;
|
||||||
|
use \manager\repo\cluster as clusterRepo;
|
||||||
|
|
||||||
|
class permission extends parentRepo{
|
||||||
|
|
||||||
|
protected static function table_name(){ static $table_name = 'permission'; return $table_name; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
|
@ -330,8 +330,13 @@
|
||||||
}//createWarehouse();
|
}//createWarehouse();
|
||||||
|
|
||||||
debug();
|
debug();
|
||||||
$myView = new View('group.view', []);
|
$req = new Repo('association/addPermission', [
|
||||||
$myView->view();
|
205,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
|
||||||
|
var_dump( $req->answer() );
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -194,6 +194,6 @@
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
echo "<section data-sublink='permissions'>";
|
echo "<section data-sublink='permissions'>";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo '</section>';
|
echo '</section>';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')},create:{text:'#CONTAINER > section[data-sublink="create"] ',element:document.querySelector('#CONTAINER > section[data-sublink="create"]')},remove:{text:'#CONTAINER > section[data-sublink="remove"] ',element:document.querySelector('#CONTAINER > section[data-sublink="remove"]')},
|
var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')},create:{text:'#CONTAINER > section[data-sublink="create"] ',element:document.querySelector('#CONTAINER > section[data-sublink="create"]')},remove:{text:'#CONTAINER > section[data-sublink="remove"] ',element:document.querySelector('#CONTAINER > section[data-sublink="remove"]')},
|
||||||
edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')},filter:{text:'#CONTAINER > section[data-sublink="filter"] ',element:document.querySelector('#CONTAINER > section[data-sublink="filter"]')}};
|
edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')},filter:{text:'#CONTAINER > section[data-sublink="filter"] ',element:document.querySelector('#CONTAINER > section[data-sublink="filter"]')},permissions:{text:'#CONTAINER > section[data-sublink="permissions"] ',element:document.querySelector('#CONTAINER > section[data-sublink="permissions"]')}};
|
||||||
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-member[data-cluster][data-member]"),add:document.querySelectorAll(section.view.text+
|
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-member[data-cluster][data-member]"),add:document.querySelectorAll(section.view.text+
|
||||||
".add-member[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.clusters.length;c++)a.push(b.clusters[c].id_cluster);b=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<b.length;c++)-1<a.indexOf(b[c].id)?b[c].remClass("hidden"):b[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
".add-member[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.clusters.length;c++)a.push(b.clusters[c].id_cluster);b=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<b.length;c++)-1<a.indexOf(b[c].id)?b[c].remClass("hidden"):b[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
||||||
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b=a.target.parentNode.parentNode.parentNode.children[0].value,
|
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b=a.target.parentNode.parentNode.parentNode.children[0].value,
|
||||||
|
|
|
@ -24,6 +24,11 @@ var section = {
|
||||||
filter: {
|
filter: {
|
||||||
text: '#CONTAINER > section[data-sublink="filter"] ',
|
text: '#CONTAINER > section[data-sublink="filter"] ',
|
||||||
element: document.querySelector('#CONTAINER > section[data-sublink="filter"]')
|
element: document.querySelector('#CONTAINER > section[data-sublink="filter"]')
|
||||||
|
},
|
||||||
|
|
||||||
|
permissions: {
|
||||||
|
text: '#CONTAINER > section[data-sublink="permissions"] ',
|
||||||
|
element: document.querySelector('#CONTAINER > section[data-sublink="permissions"]')
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue