diff --git a/README.md b/README.md index 3fdb6b9..2101ddd 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,11 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE Date: 21/05/2019 -Version: 2.12.18 +Version: 2.12.19 Author: EP Commentaire: Bugfix affichage boutons vue matériel (parfois 2e ligne chevauchait 1ère ligne) - Simplification des vues (toujours en cours) + (Enorme) Simplification des vues (toujours en cours) IMPORTANT : @@ -95,7 +95,9 @@ La liste ci-dessous n'est plus à jour, elle est désormais en ligne ici : https ----------------------------------------------------------------------------------------------------------- -21/05/2019 Version: 2.12.18 (EP) +21/05/2019 Version: 2.12.18-19 (EP) + Bugfix affichage boutons vue matériel (parfois 2e ligne chevauchait 1ère ligne) + (Enorme) Simplification des vues (toujours en cours) 17/05/2019 Version: 2.12.15-17 (EP) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 4f94956..e556ba2 100755 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -617,6 +617,7 @@ class AppController extends Controller $role = $this->getUserRole(); $profile = self::PROFILES["$role"]; + // Set General CONSTANTS for all CONTROLLERS // (Before, they used to be in beforeFilter()) @@ -628,8 +629,16 @@ class AppController extends Controller // (c'est à dire s'il n'est pas dans la table "utilisateurs") $this->priviledgedUser = $this->getTablePriviledgedUserFromCurrentSessionUserIfExists(); + $this->USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER); + $this->USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN); + $this->USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS); + $this->USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN); + $this->USER_IS_RESPONSABLE_OR_MORE = ($profile >= self::PROFILE_RESPONSABLE); $this->USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE); $this->USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN); + $this->USER_IS_ADMINPLUS_OR_MORE = ($profile >= self::PROFILE_ADMINPLUS); + + // - Misc constants $this->idGmNa = TableRegistry::getTableLocator()->get('GroupesMetiers')->find() ->where([ @@ -643,13 +652,21 @@ class AppController extends Controller ->first()['id']; // Now, set these constants for all VIEWS + $this->set('role', $role); + $this->set('profile', $profile); $this->set('username', $this->userName); $this->set('priviledgedUser', $this->priviledgedUser); $this->set('idGmNa', $this->idGmNa); $this->set('idGtNa', $this->idGtNa); + $this->set('USER_IS_UTILISATEUR', $this->USER_IS_UTILISATEUR); + $this->set('USER_IS_ADMIN', $this->USER_IS_ADMIN); + $this->set('USER_IS_ADMINPLUS', $this->USER_IS_ADMINPLUS); + $this->set('USER_IS_SUPERADMIN', $this->USER_IS_SUPERADMIN); + $this->set('USER_IS_RESPONSABLE_OR_MORE', $this->USER_IS_RESPONSABLE_OR_MORE); $this->set('USER_IS_RESPONSABLE', $this->USER_IS_RESPONSABLE); + //$this->set(compact('USER_IS_ADMIN_OR_MORE')); $this->set('USER_IS_ADMIN_OR_MORE', $this->USER_IS_ADMIN_OR_MORE); - + $this->set('USER_IS_ADMINPLUS_OR_MORE', $this->USER_IS_ADMINPLUS_OR_MORE); $configuration = $this->confLabinvent; if ($configuration->mode_install) @@ -702,9 +719,10 @@ class AppController extends Controller ])) $this->set('_serialize', true); - // moved to beforeFilter() + // (EP 21/5/19) moved to beforeFilter() //$this->set('username', $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]); + // TODO: (EP) A quoi ça sert ??? $configuration = $this->confLabinvent; $this->set('configuration', $configuration); $this->request->getSession()->write("authType", $configuration->ldap_authenticationType); @@ -722,26 +740,29 @@ class AppController extends Controller * $role = 'Utilisateur'; */ // Role = 'Utilisateur', 'Responsable", ... + // (EP 21/5/19) moved to beforeFilter() + /* $role = $this->getUserRole(); $this->set('role', $role); + */ // Profile = PROFILE_USER (=1), PROFILE_RESPONSABLE (=2), ... // $profile = $this->allProfiles["$role"]; + // (EP 21/5/19) moved to beforeFilter() + /* $profile = self::PROFILES["$role"]; $this->set('profile', $profile); + */ + // (EP 21/5/19) moved to beforeFilter() + /* $USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER); - - $USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN); $USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS); $USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN); $USER_IS_RESPONSABLE_OR_MORE = ($profile >= self::PROFILE_RESPONSABLE); - - // moved to beforeFilter() - //$USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE); - //$USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN); - + $USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE); + $USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN); $USER_IS_ADMINPLUS_OR_MORE = ($profile >= self::PROFILE_ADMINPLUS); $this->set('USER_IS_UTILISATEUR', $USER_IS_UTILISATEUR); @@ -749,13 +770,12 @@ class AppController extends Controller $this->set('USER_IS_ADMINPLUS', $USER_IS_ADMINPLUS); $this->set('USER_IS_SUPERADMIN', $USER_IS_SUPERADMIN); $this->set('USER_IS_RESPONSABLE_OR_MORE', $USER_IS_RESPONSABLE_OR_MORE); - // moved to beforeFilter() - //$this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE); - //$this->set(compact('USER_IS_ADMIN_OR_MORE')); + $this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE); + $this->set(compact('USER_IS_ADMIN_OR_MORE')); $this->set('USER_IS_ADMINPLUS_OR_MORE', $USER_IS_ADMINPLUS_OR_MORE); - // moved to beforeFilter() - //$this->set('priviledgedUser', $priviledgedUser); + $this->set('priviledgedUser', $priviledgedUser); + */ /* * @todo EP 08/2017 Nouvelle organisation des ACL avec $easyACL @@ -857,28 +877,6 @@ class AppController extends Controller ] ); }; - /* - $echoActionButton = function($html, $icon_class, $title, $action, $id, $controller='', $tip='', $confirmMessage='', $moreButtonStyle='', $mat=NULL, $photo=NULL) { - if ($controller=='') $controller='materiels'; - echo $html->link( - __(" $title"), - [ - 'controller' => $controller, - 'action' => $action, - $id, - $mat, - $photo - ], - [ - 'title' => $tip, - 'escape' => false, - 'onclick' => 'return true;', - 'style' => 'margin-right: 10px'.$moreButtonStyle, - 'confirm' => $confirmMessage - ] - ); - }; - */ $this->set(compact('echoActionButton')); } // beforeRender() diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index f2b8c05..ab5f069 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -793,25 +793,51 @@ class MaterielsController extends AppController $IS_TOBEARCHIVED = ($materiel->status == 'TOBEARCHIVED'); $IS_ARCHIVED = ($materiel->status == 'ARCHIVED'); - // NEW TODO: + + // Current user is creator or owner of current materiel $USER_IS_CREATOR_OR_OWNER = in_array($this->userName, [ $materiel->nom_createur, $materiel->nom_responsable ]); + $this->set(compact('USER_IS_CREATOR_OR_OWNER')); + + // Current user is same group as current materiel $USER_IS_SAME_GROUP = ( ( isset($this->priviledgedUser->groupes_metier_id) && $this->priviledgedUser->groupes_metier_id != $this->idGmNa && $materiel->groupes_metier_id == $this->priviledgedUser->groupes_metier_id ) || ( isset($this->priviledgedUser->groupe_thematique_id) && $this->priviledgedUser->groupe_thematique_id != $this->idGtNa && $materiel->groupes_thematique_id == $this->priviledgedUser->groupe_thematique_id ) ); - $CAN_EDIT = $IS_CREATED && ( + $this->set(compact('USER_IS_SAME_GROUP')); + + + $CAN_ATTACH_A_DOC = $this->USER_IS_ADMIN_OR_MORE || $USER_IS_CREATOR_OR_OWNER - || - ( $this->USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP ) - ); + || + ($this->USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP); + $this->set(compact('CAN_ATTACH_A_DOC')); + + $CAN_MANAGE_SUIVIS = $CAN_ATTACH_A_DOC; + $this->set(compact('CAN_MANAGE_SUIVIS')); + + $CAN_MANAGE_EMPRUNTS = $CAN_ATTACH_A_DOC; + $this->set(compact('CAN_MANAGE_EMPRUNTS')); + + $CAN_MANAGE_FILES = $CAN_ATTACH_A_DOC; + $this->set(compact('CAN_MANAGE_FILES')); + + $CAN_EDIT = $IS_CREATED && $CAN_ATTACH_A_DOC; $this->set(compact('CAN_EDIT')); - // END TODO + + $CAN_COPY = $CAN_EDIT; + $this->set(compact('CAN_COPY')); + + $configuration = $this->confLabinvent; + $CAN_PRINT_LABEL = $IS_VALIDATED && $configuration->hasPrinter && $this->USER_IS_ADMIN_OR_MORE; + $this->set(compact('CAN_PRINT_LABEL')); + + // $status = $this->allStatus[$materiel->status]; $status = self::allStatus[$materiel->status]; diff --git a/src/Template/Materiels/view.ctp b/src/Template/Materiels/view.ctp index 6ba3515..6fc189a 100755 --- a/src/Template/Materiels/view.ctp +++ b/src/Template/Materiels/view.ctp @@ -3,18 +3,27 @@ use Cake\I18n\Time; use Cake\I18n\Date; use Cake\ORM\TableRegistry; -// (EP 18/5/19) Elements set by Controller for this view: +// (EP 18/5/19) +// --- Elements set by Controller for this view --- + // - Constants : //$CAN_EDIT = $CAN_EDIT; $PDF_ENGINE = $PDF_ENGINE; + // - User status: $username = $username; $priviledgedUser = $priviledgedUser; $USER_IS_UTILISATEUR = $USER_IS_UTILISATEUR; $USER_IS_RESPONSABLE = $USER_IS_RESPONSABLE; +$USER_IS_RESPONSABLE_OR_MORE = $USER_IS_RESPONSABLE_OR_MORE; $USER_IS_ADMIN = $USER_IS_ADMIN; $USER_IS_ADMIN_OR_MORE = $USER_IS_ADMIN_OR_MORE; +$USER_IS_ADMINPLUS = $USER_IS_ADMINPLUS; +$USER_IS_ADMINPLUS_OR_MORE = $USER_IS_ADMINPLUS_OR_MORE; $USER_IS_SUPERADMIN = $USER_IS_SUPERADMIN; +$USER_IS_CREATOR_OR_OWNER = $USER_IS_CREATOR_OR_OWNER; +$USER_IS_SAME_GROUP = $USER_IS_SAME_GROUP; + // - Materiel status: $idGmNa = $idGmNa; $idGtNa = $idGtNa; @@ -22,11 +31,19 @@ $IS_CREATED = $IS_CREATED; $IS_VALIDATED = $IS_VALIDATED; $IS_TOBEARCHIVED = $IS_TOBEARCHIVED; $IS_ARCHIVED = $IS_ARCHIVED; + // - User capabilities on materiel: $CAN_EDIT = $CAN_EDIT; +$CAN_ATTACH_A_DOC = $CAN_ATTACH_A_DOC; +$CAN_COPY = $CAN_COPY; +$CAN_PRINT_LABEL = $CAN_PRINT_LABEL; +$CAN_MANAGE_SUIVIS = $CAN_MANAGE_SUIVIS; +$CAN_MANAGE_EMPRUNTS = $CAN_MANAGE_EMPRUNTS; +$CAN_MANAGE_FILES = $CAN_MANAGE_FILES; // Autres // TODO: yena plein d'autres // ... + // - Fonctions : $displayElement = $displayElement; $dateProchainControleVerif = $dateProchainControleVerif; @@ -123,6 +140,7 @@ function $echoActionButton($html, $icon_class, $title, $action, $id, $tip='', $c // debug("user=".$priviledgedUser); // debug("user name = ".$username); +/* $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [ $materiel->nom_createur, $materiel->nom_responsable @@ -134,13 +152,15 @@ $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER = $USER_IS_RESPONSABLE && in_array($us ]); $USER_IS_RESPONSABLE_AND_SAME_GROUP = $USER_IS_RESPONSABLE && ((isset($priviledgedUser->groupes_metier_id) && $priviledgedUser->groupes_metier_id != $idGmNa && $materiel->groupes_metier_id == $priviledgedUser->groupes_metier_id) || (isset($priviledgedUser->groupe_thematique_id) && $priviledgedUser->groupe_thematique_id != $idGtNa && $materiel->groupes_thematique_id == $priviledgedUser->groupe_thematique_id)); - +*/ // TODO: to be set by controller -//$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER); +/* +$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER); $CAN_ATTACH_A_DOC = $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER; $CAN_COPY = $IS_CREATED and ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER); $CAN_PRINT_LABEL = $IS_VALIDATED && $configuration->hasPrinter && $USER_IS_ADMIN_OR_MORE; +*/ ?> @@ -289,7 +309,7 @@ $CAN_PRINT_LABEL = $IS_VALIDATED && $configuration->hasPrinter && $USER_IS_ADMIN $moreButtonStyle = '; margin-top:10px; display:inline-block'; $moreButtonStyleRed = $moreButtonStyle . '; color:red'; // BOUTON de changement de statut : Valider, Invalider, Demander archivage, ou Archiver - if ($USER_IS_ADMIN_OR_MORE || $USER_IS_RESPONSABLE_AND_SAME_GROUP) { + if ($USER_IS_ADMIN_OR_MORE || ($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP)) { // CREATED if ($IS_CREATED) // Bouton VALIDER @@ -512,7 +532,14 @@ if ($USER_IS_ADMIN_OR_MORE) {