From 18963d115b4fa6e27ab2518fe3a6ddf37e4cc465 Mon Sep 17 00:00:00 2001 From: afornerot Date: Fri, 9 Oct 2020 15:43:50 +0200 Subject: [PATCH] =?UTF-8?q?feature=20profil=20de=20mod=C3=A9ration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreBundle/Command/InitDataCommand.php | 83 +++- .../Controller/ConfigController.php | 45 --- .../Controller/PermmodoprofilController.php | 357 ++++++++++++++++++ .../CoreBundle/Controller/UserController.php | 11 + .../Cadoles/CoreBundle/Entity/PermModo.php | 32 +- .../CoreBundle/Entity/PermModoProfil.php | 164 ++++++++ .../src/Cadoles/CoreBundle/Entity/User.php | 30 ++ .../EventListener/sessionListener.php | 21 +- .../CoreBundle/Form/PermmodoprofilType.php | 52 +++ .../src/Cadoles/CoreBundle/Form/UserType.php | 11 + .../CoreBundle/Resources/config/routing.yml | 37 +- .../public/themes/acpoitiers/icart.png | Bin 8936 -> 8936 bytes .../public/themes/acpoitiers/look.png | Bin 23458 -> 23458 bytes .../Resources/public/themes/transnum/look.png | Bin 27748 -> 27748 bytes .../public/themes/transnum/transnum-logo.png | Bin 27748 -> 27748 bytes .../views/Permmodoprofil/edit.html.twig | 46 +++ .../views/Permmodoprofil/list.html.twig | 42 +++ .../views/Permmodoprofil/permmodo.html.twig | 66 ++++ .../Resources/views/User/edit.html.twig | 5 +- tmpl/ninegate-init-01.sql | 31 +- 20 files changed, 936 insertions(+), 97 deletions(-) create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/PermmodoprofilController.php create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModoProfil.php create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Form/PermmodoprofilType.php create mode 100755 src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/edit.html.twig create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/list.html.twig create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/permmodo.html.twig diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/InitDataCommand.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/InitDataCommand.php index cfe337ac..78be591b 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/InitDataCommand.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/InitDataCommand.php @@ -5,14 +5,14 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpKernel\KernelInterface; -use Doctrine\DBAL\Connection as DBALConnection; -use Doctrine\ORM\EntityManager; use Ramsey\Uuid\Uuid; -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Id\AssignedGenerator; use Cadoles\CoreBundle\Entity\Group; use Cadoles\CoreBundle\Entity\UserGroup; +use Cadoles\CoreBundle\Entity\PermModoProfil; +use Cadoles\CoreBundle\Entity\PermModo; class InitDataCommand extends ContainerAwareCommand { @@ -164,6 +164,68 @@ class InitDataCommand extends ContainerAwareCommand } } + // Génération du profils de permissions modérateurs + $metadata = $em->getClassMetaData('CadolesCoreBundle:PermModoProfil'); + $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); + $metadata->setIdGenerator(new AssignedGenerator()); + + $entityprofil = $em->getRepository('CadolesCoreBundle:PermModoProfil')->find(-100); + if(!$entityprofil) { + $entityprofil = new PermModoProfil(); + $entityprofil->setId(-100); + $entityprofil->setName("Global"); + $em->persist($entityprofil); + $em->flush(); + } + + // Affecter les permissions modérateurs sans profils sur le profils par défaut + $entitys = $em->getRepository('CadolesCoreBundle:PermModo')->findBy(["permmodoprofil"=>null]); + foreach($entitys as $entity) { + $entity->setPermmodoprofil($entityprofil); + $em->persist($entity); + $em->flush(); + } + + // Affecter le profil modérateur par défaut aux modérateurs qui n'en ont pas + $users = $em->getRepository('CadolesCoreBundle:User')->findBy(["role"=>"ROLE_MODO","permmodoprofil"=>null]); + foreach($users as $user) { + $user->setPermmodoprofil($entityprofil); + $em->persist($user); + $em->flush(); + } + + // Initialiser l'ensemble des profils modérateurs + $entityprofils = $em->getRepository('CadolesCoreBundle:PermModoProfil')->findAll(); + foreach($entityprofils as $profil) { + $this->addModeration($profil,'cadoles_core_config_commun',0); + $this->addModeration($profil,'cadoles_core_config_theme',0); + $this->addModeration($profil,'cadoles_core_config_datauser',0); + $this->addModeration($profil,'cadoles_core_config_datausers',0); + $this->addModeration($profil,'cadoles_core_config_whitelist',0); + $this->addModeration($profil,'cadoles_core_config_niveau01',1); + $this->addModeration($profil,'cadoles_core_config_niveau02',1); + $this->addModeration($profil,'cadoles_core_config_group',1); + $this->addModeration($profil,'cadoles_core_config_registration',1); + $this->addModeration($profil,'cadoles_core_config_user',1); + $this->addModeration($profil,'cadoles_portal_config_pagetemplate',1); + $this->addModeration($profil,'cadoles_portal_config_page',1); + $this->addModeration($profil,'cadoles_portal_config_item',1); + $this->addModeration($profil,'cadoles_portal_config_alert',1); + $this->addModeration($profil,'cadoles_portal_config_calendar',1); + $this->addModeration($profil,'cadoles_portal_config_blog',1); + $this->addModeration($profil,'cadoles_portal_config_project',1); + $this->addModeration($profil,'cadoles_portal_config_flux',1); + $this->addModeration($profil,'cadoles_portal_config_notice',1); + $this->addModeration($profil,'cadoles_portal_config_icon',1); + $this->addModeration($profil,'cadoles_portal_config_synclimesurvey',0); + $this->addModeration($profil,'cadoles_portal_config_syncmoodle',0); + $this->addModeration($profil,'cadoles_portal_config_syncwordpress',0); + $this->addModeration($profil,'cadoles_core_config_statistic',1); + $this->addModeration($profil,'cadoles_core_config_mailing',1); + $this->addModeration($profil,'cadoles_core_config_importuser',0); + $this->addModeration($profil,'cadoles_cron_config',0); + $this->addModeration($profil,'cadoles_cron_config_log',0); + } $output->writeln(''); } @@ -173,4 +235,17 @@ class InitDataCommand extends ContainerAwareCommand $rootdir = rtrim(getcwd(), '/'); return $rootdir . '/' . trim($extra['symfony-app-dir'], '/'); } + + protected function addModeration($profil,$route,$visible) { + $em = $this->getContainer()->get('doctrine')->getEntityManager(); + $entity=$em->getRepository('CadolesCoreBundle:PermModo')->findOneBy(["route"=>$route,"permmodoprofil"=>$profil]); + if(!$entity) { + $entity=new PermModo(); + $entity->setRoute($route); + $entity->setVisible($visible); + $entity->setPermmodoprofil($profil); + $em->persist($entity); + $em->flush(); + } + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/ConfigController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/ConfigController.php index c4c5cf2e..60f2d02f 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/ConfigController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/ConfigController.php @@ -141,51 +141,6 @@ class ConfigController extends Controller return $config; } - public function permmodoAction() - { - $em = $this->getDoctrine()->getManager(); - - $sidebars=$this->get('session')->get('sidebar'); - - $perms=[]; - foreach($sidebars as $sidebar) { - foreach($sidebar["childs"] as $child) { - $permmod=$em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(["route"=>$child["path"]]); - if($permmod) { - array_push($perms,['id' => $permmod->getId(), 'label'=>$sidebar['label'].' >> '.$child['label'],'visible'=>$permmod->getVisible()]); - } - } - } - - return $this->render('CadolesCoreBundle:Config:permmodo.html.twig', [ - 'useheader' => true, - 'usemenu' => false, - 'usesidebar' => true, - 'permmodos' => $perms - ]); - } - - public function permmodoupdateAction(Request $request) - { - // S'assurer que c'est un appel ajax - if (!$request->isXmlHttpRequest()) return new JsonResponse(array('message' => 'Interdit'), 400); - - $output=array(); - $id = $request->request->get('id'); - - $em = $this->getDoctrine()->getManager(); - $permmodo = $this->getDoctrine()->getRepository("CadolesCoreBundle:PermModo")->find($id); - if (!$permmodo) throw $this->createNotFoundException('Unable to find entity.'); - - $permmodo->setVisible(!$permmodo->getVisible()); - $em->persist($permmodo); - $em->flush(); - - $response = new Response(json_encode($output)); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } - public function datauserdefaultAction(Request $request) { $em = $this->getDoctrine()->getManager(); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/PermmodoprofilController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/PermmodoprofilController.php new file mode 100644 index 00000000..8915e428 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/PermmodoprofilController.php @@ -0,0 +1,357 @@ +render('CadolesCoreBundle:Permmodoprofil:list.html.twig',[ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + ]); + } + + public function ajaxlistAction(Request $request) + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) { + return new JsonResponse(array('message' => 'Interdit'), 400); + } + + $em = $this->getDoctrine()->getManager(); + + $start=$request->query->get('start'); + $length= $request->query->get('length'); + $search= $request->query->get('search'); + $draw= $request->query->get('draw'); + $order= $request->query->get('order'); + + // Nombre total d'enregistrement + $total = $em->createQueryBuilder()->select('COUNT(table)')->from($this->labelentity,'table')->getQuery()->getSingleScalarResult(); + + // Nombre d'enregistrement filtré + if($search["value"]=="") + $totalf = $total; + else { + $qb = $em->createQueryBuilder() + ->select('COUNT(table)') + ->from($this->labelentity,'table') + ->where('table.name LIKE :value') + ->setParameter("value", "%".$search["value"]."%"); + $totalf = $qb->getQuery()->getSingleScalarResult(); + } + + // Construction du tableau de retour + $output = array( + 'draw' => $draw, + 'recordsFiltered' => $totalf, + 'recordsTotal' => $total, + 'data' => array(), + ); + + // Parcours des Enregistrement + $qb = $em->createQueryBuilder(); + $qb->select('table')->from($this->labelentity,'table'); + + if($search["value"]!="") { + $qb ->andwhere('table.name LIKE :value') + ->setParameter("value", "%".$search["value"]."%"); + } + switch($order[0]["column"]) { + case 1 : + $qb->orderBy('table.name',$order[0]["dir"]); + break; + } + + $datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult(); + + foreach($datas as $data) { + $action ="$data->getId()))."'>"; + if($data->getId()>0) $action.="$data->getId()))."'>"; + $action.="$data->getId()))."'>"; + + array_push($output["data"],array($action,$data->getName())); + } + + // Retour + return new Response(json_encode($output), 200); + } + + public function submitAction(Request $request) + { + // Initialisation de l'enregistrement + $data = new PermModoProfil(); + + // Création du formulaire + $form = $this->createForm(PermmodoprofilType::class,$data,array( + "mode" => "submit", + )); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm(null,$form,$request,$data,"submit"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $em = $this->getDoctrine()->getManager(); + + // Sauvegarde + $em->persist($data); + $em->flush(); + + // Init permission + $this->initPermModo($data); + + // Retour à la liste + return $this->redirectToRoute($this->labelroute); + } + + // Affichage du formulaire + return $this->render('CadolesCoreBundle:Permmodoprofil:edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + $this->labeldata => $data, + 'mode' => 'submit', + 'form' => $form->createView() + ]); + } + + public function updateAction($id,Request $request) + { + $em = $this->getDoctrine()->getManager(); + + // Récupération de l'enregistrement courant + $data=$this->getData($id); + + // Création du formulaire + $form = $this->createForm(PermmodoprofilType::class,$data,array( + "mode" => "update" + )); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm($id,$form,$request,$data,"update"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + + // Sauvegarde + $em->persist($data); + $em->flush(); + + // Init permission + $this->initPermModo($data); + + // Retour à la liste + return $this->redirectToRoute($this->labelroute); + } + + + // Affichage du formulaire + return $this->render('CadolesCoreBundle:Permmodoprofil:edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + $this->labeldata => $data, + 'mode' => 'update', + 'form' => $form->createView() + ]); + } + + public function deleteAction($id,Request $request) + { + // Récupération de l'enregistrement courant + $data=$this->getData($id); + + // Création du formulaire + $form = $this->createForm(PermmodoprofilType::class,$data,array( + "mode" =>"delete", + )); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm($id,$form,$request,$data,"delete"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($data); + $em->flush(); + + return $this->redirectToRoute($this->labelroute); + } + + // Affichage du formulaire + return $this->render('CadolesCoreBundle:Permmodoprofil:edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + $this->labeldata => $data, + 'mode' => 'delete', + 'form' => $form->createView() + ]); + } + + public function permmodoAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $sidebars=$this->get('session')->get('sidebar'); + + $perms=[]; + foreach($sidebars as $sidebar) { + foreach($sidebar["childs"] as $child) { + $permmod=$em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(["route"=>$child["path"],"permmodoprofil"=>$id]); + if($permmod) { + array_push($perms,['id' => $permmod->getId(), 'label'=>$sidebar['label'].' >> '.$child['label'],'visible'=>$permmod->getVisible()]); + } + } + } + + return $this->render('CadolesCoreBundle:Permmodoprofil:permmodo.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + 'profil' => $this->getData($id), + 'permmodos' => $perms + ]); + } + + public function permmodoupdateAction(Request $request) + { + // S'assurer que c'est un appel ajax + if (!$request->isXmlHttpRequest()) return new JsonResponse(array('message' => 'Interdit'), 400); + + $output=array(); + $id = $request->request->get('id'); + + $em = $this->getDoctrine()->getManager(); + $permmodo = $this->getDoctrine()->getRepository("CadolesCoreBundle:PermModo")->find($id); + if (!$permmodo) throw $this->createNotFoundException('Unable to find entity.'); + + $permmodo->setVisible(!$permmodo->getVisible()); + $em->persist($permmodo); + $em->flush(); + + $response = new Response(json_encode($output)); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + protected function getDatas() + { + $em = $this->getDoctrine()->getManager(); + $datas = $em->getRepository($this->labelentity)->findAll(); + return $datas; + } + + protected function getData($id) + { + $em = $this->getDoctrine()->getManager(); + $data = $em->getRepository($this->labelentity)->find($id); + + if (!$data) { + throw $this->createNotFoundException('Unable to find '.$this->labeldata); + } + + return $data; + } + + protected function getErrorForm($id,$form,$request,$data,$mode) { + if ($form->get('submit')->isClicked()&&$mode=="delete") { + // On s'assure que le profil n'est pas rattaché à des utilisateurs + if($data->getUsers()->count() > 0) { + $form->addError(new FormError('Un utilisateur utilise ce profil de modération : suppression impossible')); + } + } + + if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) { + } + + if ($form->get('submit')->isClicked() && !$form->isValid()) { + $this->get('session')->getFlashBag()->clear(); + $validator = $this->get('validator'); + $errors = $validator->validate($data); + foreach( $errors as $error ) { + $request->getSession()->getFlashBag()->add("error", $error->getMessage()); + } + + $errors = $form->getErrors(); + foreach( $errors as $error ) { + $request->getSession()->getFlashBag()->add("error", $error->getMessage()); + } + } + } + + private function initPermModo($profil) { + $this->addModeration($profil,'cadoles_core_config_commun',0); + $this->addModeration($profil,'cadoles_core_config_theme',0); + $this->addModeration($profil,'cadoles_core_config_datauser',0); + $this->addModeration($profil,'cadoles_core_config_datausers',0); + $this->addModeration($profil,'cadoles_core_config_whitelist',0); + $this->addModeration($profil,'cadoles_core_config_niveau01',1); + $this->addModeration($profil,'cadoles_core_config_niveau02',1); + $this->addModeration($profil,'cadoles_core_config_group',1); + $this->addModeration($profil,'cadoles_core_config_registration',1); + $this->addModeration($profil,'cadoles_core_config_user',1); + $this->addModeration($profil,'cadoles_portal_config_pagetemplate',1); + $this->addModeration($profil,'cadoles_portal_config_page',1); + $this->addModeration($profil,'cadoles_portal_config_item',1); + $this->addModeration($profil,'cadoles_portal_config_alert',1); + $this->addModeration($profil,'cadoles_portal_config_calendar',1); + $this->addModeration($profil,'cadoles_portal_config_blog',1); + $this->addModeration($profil,'cadoles_portal_config_project',1); + $this->addModeration($profil,'cadoles_portal_config_flux',1); + $this->addModeration($profil,'cadoles_portal_config_notice',1); + $this->addModeration($profil,'cadoles_portal_config_icon',1); + $this->addModeration($profil,'cadoles_portal_config_synclimesurvey',0); + $this->addModeration($profil,'cadoles_portal_config_syncmoodle',0); + $this->addModeration($profil,'cadoles_portal_config_syncwordpress',0); + $this->addModeration($profil,'cadoles_core_config_statistic',1); + $this->addModeration($profil,'cadoles_core_config_mailing',1); + $this->addModeration($profil,'cadoles_core_config_importuser',0); + $this->addModeration($profil,'cadoles_cron_config',0); + $this->addModeration($profil,'cadoles_cron_config_log',0); + } + + private function addModeration($profil,$route,$visible) { + $em = $this->getDoctrine()->getManager(); + $entity=$em->getRepository('CadolesCoreBundle:PermModo')->findOneBy(["route"=>$route,"permmodoprofil"=>$profil]); + if(!$entity) { + $entity=new PermModo(); + $entity->setRoute($route); + $entity->setVisible($visible); + $entity->setPermmodoprofil($profil); + $em->persist($entity); + $em->flush(); + } + } + +} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php index 0ef7626b..af26b137 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php @@ -389,6 +389,9 @@ class UserController extends Controller $lstgroups=array_filter(explode(",",$form->get("linkgroups")->getData())); $lstmodos=array_filter(explode(",",$form->get("linkmodos")->getData())); + // Si non modérateur vider le profil de modération + if($data->getRole()!="ROLE_MODO") $data->setPermmodoprofil(null); + // Sauvegarde $em->persist($data); $em->flush(); @@ -527,6 +530,9 @@ class UserController extends Controller $data->setPassword($data->getPassword()); } + // Si non modérateur vider le profil de modération + if($data->getRole()!="ROLE_MODO") $data->setPermmodoprofil(null); + // Sauvegarde $em->persist($data); $em->flush(); @@ -1414,6 +1420,11 @@ class UserController extends Controller $form->addError(new FormError('Une inscription utilise déjà ce login ou cet email')); } + // On s'assure que les modérateurs aient un profil de modération + if($data->getRole()=="ROLE_MODO"&&!$data->getPermmodoprofil()) { + $form->addError(new FormError('Vous devez préciser un profil de modération')); + } + // Si niveau01 commence par autre = niveau01other obligatoire $niveau01=strtolower($data->getNiveau01()->getLabel()); if(stripos($niveau01,"autre")===0) { diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModo.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModo.php index 49f1568d..17e03f29 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModo.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModo.php @@ -23,7 +23,7 @@ class PermModo private $id; /** - * @ORM\Column(type="string", length=50, unique=true) + * @ORM\Column(type="string", length=50) */ private $route; @@ -32,6 +32,11 @@ class PermModo */ private $visible; + /** + * @ORM\ManyToOne(targetEntity="PermModoProfil", inversedBy="permmodos") + * @ORM\JoinColumn(nullable=true) + */ + private $permmodoprofil; /** * Get id @@ -90,4 +95,29 @@ class PermModo { return $this->visible; } + + + /** + * Set permmodoprofil + * + * @param \Cadoles\CoreBundle\Entity\PermModoProfil $permmodoprofil + * + * @return PermModo + */ + public function setPermmodoprofil(\Cadoles\CoreBundle\Entity\PermModoProfil $permmodoprofil = null) + { + $this->permmodoprofil = $permmodoprofil; + + return $this; + } + + /** + * Get permmodoprofil + * + * @return \Cadoles\CoreBundle\Entity\PermModoProfil + */ + public function getPermmodoprofil() + { + return $this->permmodoprofil; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModoProfil.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModoProfil.php new file mode 100644 index 00000000..4dd17b91 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/PermModoProfil.php @@ -0,0 +1,164 @@ +permmodos = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set id. + * + * @param string $id + * + * @return PermModoProfil + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Set name. + * + * @param string $name + * + * @return PermModoProfil + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Add permmodo. + * + * @param \Cadoles\CoreBundle\Entity\PermModo $permmodo + * + * @return PermModoProfil + */ + public function addPermmodo(\Cadoles\CoreBundle\Entity\PermModo $permmodo) + { + $this->permmodos[] = $permmodo; + + return $this; + } + + /** + * Remove permmodo. + * + * @param \Cadoles\CoreBundle\Entity\PermModo $permmodo + * + * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. + */ + public function removePermmodo(\Cadoles\CoreBundle\Entity\PermModo $permmodo) + { + return $this->permmodos->removeElement($permmodo); + } + + /** + * Get permmodos. + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getPermmodos() + { + return $this->permmodos; + } + + /** + * Add user + * + * @param \Cadoles\CoreBundle\Entity\User $user + * + * @return PermModoProfil + */ + public function addUser(\Cadoles\CoreBundle\Entity\User $user) + { + $this->users[] = $user; + + return $this; + } + + /** + * Remove user + * + * @param \Cadoles\CoreBundle\Entity\User $user + */ + public function removeUser(\Cadoles\CoreBundle\Entity\User $user) + { + $this->users->removeElement($user); + } + + /** + * Get users + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getUsers() + { + return $this->users; + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php index 477a12bd..4662a674 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -188,6 +188,12 @@ class User implements UserInterface, \Serializable */ private $preference; + /** + * @ORM\ManyToOne(targetEntity="PermModoProfil", inversedBy="users") + * @ORM\JoinColumn(nullable=true) + */ + private $permmodoprofil; + /** * @ORM\ManyToOne(targetEntity="Country", inversedBy="users") * @ORM\JoinColumn(nullable=true) @@ -1981,4 +1987,28 @@ class User implements UserInterface, \Serializable { return $this->preference; } + + /** + * Set permmodoprofil + * + * @param \Cadoles\CoreBundle\Entity\PermModoProfil $permmodoprofil + * + * @return User + */ + public function setPermmodoprofil(\Cadoles\CoreBundle\Entity\PermModoProfil $permmodoprofil = null) + { + $this->permmodoprofil = $permmodoprofil; + + return $this; + } + + /** + * Get permmodoprofil + * + * @return \Cadoles\CoreBundle\Entity\PermModoProfil + */ + public function getPermmodoprofil() + { + return $this->permmodoprofil; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/sessionListener.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/sessionListener.php index a65fc2f3..6a682b0b 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/sessionListener.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/sessionListener.php @@ -21,7 +21,7 @@ $this->token_storage = $token_storage; } - public function haveRole($roles,$tohave,$route) { + public function haveRole($curentuser,$roles,$tohave,$route) { $haverole=false; if($roles=="") { if(empty($tohave)) $haverole=true; @@ -35,7 +35,7 @@ if($route!=null) { if($haverole&&in_array("ROLE_MODO",$roles)) { - $permmodo=$this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(["route"=>$route,"visible"=>true]); + $permmodo=$this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(["route"=>$route,"visible"=>true,"permmodoprofil"=>$curentuser->getPermmodoprofil()]); if(!$permmodo) $haverole=false; } } @@ -120,7 +120,9 @@ if(in_array("ROLE_MODO",$roles)) { $request = $event->getRequest(); $route = $request->attributes->get('_route'); - if($route!="cadoles_core_config"&&stripos($route,"_config")!==false) { + if($route!="cadoles_core_config"&&stripos($route,"_config")!==false&&stripos($route,"cadoles_core_config_file")===false) { + $permmodoprofil=$curentuser->getPermmodoprofil(); + if(stripos($route,"cadoles_core_config_logo")!==false) $route="cadoles_portal_config_page"; if(stripos($route,"cadoles_core_config_header")!==false) $route="cadoles_portal_config_page"; @@ -133,6 +135,9 @@ if(stripos($route,"cadoles_portal_config_itemcategory")!==false) $route="cadoles_portal_config_item"; if(stripos($route,"cadoles_portal_config_alertcategory")!==false) $route="cadoles_portal_config_alert"; if(stripos($route,"cadoles_portal_config_calendarevent")!==false) $route="cadoles_portal_config_calendar"; + if(stripos($route,"cadoles_portal_config_blogarticle")!==false) $route="cadoles_portal_config_blog"; + if(stripos($route,"cadoles_portal_config_blogcomment")!==false) $route="cadoles_portal_config_blog"; + if(stripos($route,"cadoles_portal_config_projecttask")!==false) $route="cadoles_portal_config_project"; if(stripos($route,"cadoles_cron_config")!==false) $route="cadoles_cron_config"; $tbroute=explode("_",$route); @@ -140,8 +145,8 @@ $route.=(isset($tbroute[1])?"_".$tbroute[1]:""); $route.=(isset($tbroute[2])?"_".$tbroute[2]:""); $route.=(isset($tbroute[3])?"_".$tbroute[3]:""); - - $permmodo = $this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(['route'=> $route, "visible"=>true]); + + $permmodo = $this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(['permmodoprofil'=>$permmodoprofil,'route'=> $route, "visible"=>true]); if(!$permmodo) die('Permission denied'); } } @@ -149,7 +154,7 @@ $sidebar=array(); $nvs1 = $this->em->getRepository("CadolesCoreBundle:Sidebar")->findBy(array('parent'=> NULL), array('roworder' => 'ASC')); foreach($nvs1 as $nv1) { - if($this->haveRole($roles,$nv1->getPermission(),$nv1->getPath())) { + if($this->haveRole($curentuser,$roles,$nv1->getPermission(),$nv1->getPath())) { $sidebar[$nv1->getRoworder()] = array( "fonticon" => $nv1->getFonticon(), "label" => $nv1->getLabel(), @@ -180,7 +185,7 @@ foreach($nv1->getChilds() as $nv2) { - if($this->haveRole($roles,$nv2->getPermission(),$nv2->getPath())) { + if($this->haveRole($curentuser,$roles,$nv2->getPermission(),$nv2->getPath())) { $sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()] = array ( "fonticon" => $nv2->getFonticon(), "label" => $nv2->getLabel(), @@ -215,7 +220,7 @@ } foreach($nv2->getChilds() as $nv3) { - if($this->haveRole($roles,$nv3->getPermission(),$nv3->getPath())) { + if($this->haveRole($curentuser,$roles,$nv3->getPermission(),$nv3->getPath())) { $sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()] = array ( "fonticon" => $nv3->getFonticon(), "label" => $nv3->getLabel(), diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/PermmodoprofilType.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/PermmodoprofilType.php new file mode 100644 index 00000000..cdf7116f --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/PermmodoprofilType.php @@ -0,0 +1,52 @@ +add('submit', + SubmitType::class, array( + "label" => ($options["mode"]=="delete"?"Confirmer la Suppression":"Valider"), + "attr" => ($options["mode"]=="delete"?array("class" => "btn btn-danger"):array("class" => "btn btn-success")) + ) + ); + + $builder->add('name', + TextType::class, array( + "label" =>"Label", + "disabled" => ($options["mode"]=="delete"?true:false), + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px") + ) + ); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Cadoles\CoreBundle\Entity\PermModoProfil', + 'mode' => "string", + 'labelsiren' => "string", + 'masteridentity' => "string" + )); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php index 0f7e42f1..0f64d4aa 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php @@ -75,6 +75,17 @@ class UserType extends AbstractType "attr" => array("class" => "form-control", "style" => "margin-bottom:15px;$readonly","onfocus" => $onfocus, "onchange" => $onchange), "required" => true, "choices" => $choices)); + + $builder->add('permmodoprofil', + EntityType::class,[ + "class" => "CadolesCoreBundle:PermModoProfil", + "label" => "Profil de Modération", + "choice_label" => "name", + 'disabled' => ($options["mode"]=="delete"?true:false), + "required" => false, + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px;$readonly","onfocus" => $onfocus, "onchange" => $onchange), + ] + ); } $perm=$options["perm"]; diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 12a2855f..391787a4 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -178,14 +178,6 @@ cadoles_core_config_header: path: /config/commun/header defaults: { _controller: CadolesCoreBundle:Config:header } -cadoles_core_config_permmodo: - path: /config/commun/permmodo - defaults: { _controller: CadolesCoreBundle:Config:permmodo } - -cadoles_core_config_permmodo_update: - path: /config/commun/permmodo/update - defaults: { _controller: CadolesCoreBundle:Config:permmodoupdate } - cadoles_core_config_datauser: path: /config/commun/datauser defaults: { _controller: CadolesCoreBundle:Config:datauser } @@ -323,6 +315,35 @@ cadoles_core_user_preference: defaults: { _controller: CadolesCoreBundle:User:preference } +#== Permmodoprofil ======================================================================================================== +cadoles_core_config_permmodoprofil: + path: /config/permmodoprofil + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:list } + +cadoles_core_config_permmodoprofil_submit: + path: /config/permmodoprofil/submit + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:submit } + +cadoles_core_config_permmodoprofil_update: + path: /config/permmodoprofil/update/{id} + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:update } + +cadoles_core_config_permmodoprofil_delete: + path: /config/permmodoprofil/delete/{id} + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:delete } + +cadoles_core_config_permmodoprofil_ajax_list: + path: /config/permmodoprofil/ajax/list + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:ajaxlist } + +cadoles_core_config_permmodoprofil_permmodo: + path: /config/permmodoprofil/permmodo/{id} + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:permmodo } + +cadoles_core_config_permmodo_update: + path: /config/permmodo/update + defaults: { _controller: CadolesCoreBundle:Permmodoprofil:permmodoupdate } + #== Niveau01 ============================================================================================================= cadoles_core_config_niveau01: path: /config/niveau01 diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/acpoitiers/icart.png b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/acpoitiers/icart.png index 5af8fee5fd74fc60230351dd47633d8c5669fc3a..aa4e1cec3f1a8e32cdd69e85ee29905139d56b4a 100644 GIT binary patch delta 22 ecmaFi`oeX?BSuaxc1}SyW!}8D&952%DgXdrLI?-| delta 22 ecmaFi`oeX?BSub679JJ8JC?@RH@{~5s{jCLd delta 24 gcmZ3qopI52#tpJ^oSZB?Cgvyqt?b*ZCRbw%0B&js+W-In diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/transnum/look.png b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/transnum/look.png index d2eb2a79275f96204d636fb1f7a6a87cb4d1cb1d..5fec8029f17dc261d527e3bd00f8e6b192060f43 100644 GIT binary patch delta 24 gcmaEIgYn4?#tm0ZIl0(51=*B&^V&AwGi@^i0Da^M6#xJL delta 24 gcmaEIgYn4?#tm0ZIoYK-B(2od?ycB-&$P`90EOBL5C8xG diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/transnum/transnum-logo.png b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/themes/transnum/transnum-logo.png index d2eb2a79275f96204d636fb1f7a6a87cb4d1cb1d..5fec8029f17dc261d527e3bd00f8e6b192060f43 100644 GIT binary patch delta 24 gcmaEIgYn4?#tm0ZIl0(51=*B&^V&AwGi@^i0Da^M6#xJL delta 24 gcmaEIgYn4?#tm0ZIoYK-B(2od?ycB-&$P`90EOBL5C8xG diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/edit.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/edit.html.twig new file mode 100755 index 00000000..c8155f81 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/edit.html.twig @@ -0,0 +1,46 @@ +{% extends '@CadolesCore/base.html.twig' %} + +{% block pagewrapper %} +{{ form_start(form) }} +

+ {% if mode=="update" %} + Modification Profil de Modération + {% elseif mode=="submit" %} + Création Profil de Modération + {% elseif mode=="delete" %} + Suppression Profil de Modération + {% endif %} +

+ + {{ form_widget(form.submit) }} Annuler + +

+ + {% if app.session.flashbag.has('error') %} +
+ Erreur
+ {% for flashMessage in app.session.flashbag.get('error') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {% if app.session.flashbag.has('notice') %} +
+ Information
+ {% for flashMessage in app.session.flashbag.get('notice') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} +
+
+ Informations +
+ +
+ {{ form_row(form.name) }} +
+
+{{ form_end(form) }} +{% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/list.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/list.html.twig new file mode 100644 index 00000000..6f48b0ec --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/list.html.twig @@ -0,0 +1,42 @@ +{% extends '@CadolesCore/base.html.twig' %} + +{% block pagewrapper %} +

Gestion des Profils de Modération

+ + {% if is_granted('ROLE_ADMIN') %} +

Ajouter

+ {% endif %} + +
+
+ Liste des Profils de Modération} +
+ +
+
+ + + + + + + +
ActionLabel
+
+
+
+{% endblock %} + +{% block localjavascript %} + $(document).ready(function() { + $('#dataTables').DataTable({ + columnDefs: [ { "targets": 'no-sort', "orderable": false } ], + responsive: true, + iDisplayLength: 100, + order: [[ 1, "asc" ]], + processing: true, + serverSide: true, + ajax: "{{ path('cadoles_core_config_permmodoprofil_ajax_list') }}", + }); + }); +{% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/permmodo.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/permmodo.html.twig new file mode 100644 index 00000000..bc86ffc3 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Permmodoprofil/permmodo.html.twig @@ -0,0 +1,66 @@ +{% extends '@CadolesCore/base.html.twig' %} + +{% block pagewrapper %} +
+

Modération du Profil = {{ profil.name }}

+ +
+
+ Permissions Modérateur +
+ +
+
+ + + + + + + + + + {% for permmodo in permmodos %} + + + + + {% endfor %} +
ActionPermission
{{ permmodo.label}} + {% set checked="" %} + {% if permmodo.visible %} {% set checked="checked" %} {%endif %} + + +
+
+
+
+
+{% endblock %} + +{% block localjavascript %} + function showInfo(id) { + $("#modalinfo #modalinfotext").html($("#"+id).attr("data").replace(/\n/g, "
")); + } + + + $(document).ready(function() { + $('#dataTables').DataTable({ + responsive: true, + }); + + $(".switch").bootstrapSwitch(); + }); + + function switchModo(id) { + $.ajax({ + method: "POST", + url: "{{ path('cadoles_core_config_permmodo_update') }}", + data: { + "id": id, + "profil": {{profil.id}} + } + }); + } + +{% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig index c7f078d4..c81036aa 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig @@ -88,7 +88,8 @@ {% if form.role is defined %} {{ form_label(form.role) }} - {{ form_widget(form.role) }} + {{ form_widget(form.role) }} +
{{ form_row(form.permmodoprofil) }}
{% endif %} @@ -460,9 +461,11 @@ if($("#user_role").val()=="ROLE_MODO" ) { $("#panelmodos").show(); + $("#blockpermmodoprofil").show(); } else { $("#panelmodos").hide(); + $("#blockpermmodoprofil").hide(); } niveau01=$("#user_niveau01 option:selected").text().toLowerCase(); diff --git a/tmpl/ninegate-init-01.sql b/tmpl/ninegate-init-01.sql index 9348f5f2..f444de52 100644 --- a/tmpl/ninegate-init-01.sql +++ b/tmpl/ninegate-init-01.sql @@ -27,7 +27,7 @@ INSERT IGNORE INTO `sidebar` (`id`, `parent_id`, `roworder`, `label`, `path`, `f (1000, NULL, 1000, 'CONFIGURATION', NULL, 'fa fa-cog', 'ROLE_ADMIN,ROLE_MODO', ''), (1010, 1000, 1010, 'Générale', 'cadoles_core_config_commun', 'fa fa-table', 'ROLE_ADMIN,ROLE_MODO', ''), (1020, 1000, 1020, 'Thème', 'cadoles_core_config_theme', 'fa fa-paint-brush', 'ROLE_ADMIN,ROLE_MODO', ''), -(1030, 1000, 1030, 'Modération', 'cadoles_core_config_permmodo', 'fa fa-balance-scale', 'ROLE_ADMIN', ''), +(1030, 1000, 1030, 'Modération', 'cadoles_core_config_permmodoprofil', 'fa fa-balance-scale', 'ROLE_ADMIN', ''), (1040, 1000, 1040, 'Fiche Utilisateur', 'cadoles_core_config_datauser', 'fa fa-cog', 'ROLE_ADMIN,ROLE_MODO', ''), (1050, 1000, 1050, 'Liste Utilisateurs', 'cadoles_core_config_datausers', 'fa fa-cog', 'ROLE_ADMIN,ROLE_MODO', ''), @@ -122,32 +122,3 @@ INSERT IGNORE INTO `config` (`order`, `visible`, `changeable`, `required`, `type ('500', 1, 1, 1, 'permgroup', 'permgroup', 'ROLE_ANIM', '', 'Determine quel rôle aura la permission de créer des groupes de travail'); -INSERT IGNORE permmodo (`route`, `visible`) VALUES -('cadoles_core_config_commun',0), -('cadoles_core_config_theme',0), -('cadoles_core_config_datauser',0), -('cadoles_core_config_datausers',0), -('cadoles_core_config_whitelist',0), -('cadoles_core_config_niveau01',1), -('cadoles_core_config_niveau02',1), -('cadoles_core_config_group',1), -('cadoles_core_config_registration',1), -('cadoles_core_config_user',1), -('cadoles_portal_config_pagetemplate',1), -('cadoles_portal_config_page',1), -('cadoles_portal_config_item',1), -('cadoles_portal_config_alert',1), -('cadoles_portal_config_calendar',1), -('cadoles_portal_config_blog',1), -('cadoles_portal_config_project',1), -('cadoles_portal_config_flux',1), -('cadoles_portal_config_notice',1), -('cadoles_portal_config_icon',1), -('cadoles_portal_config_synclimesurvey',0), -('cadoles_portal_config_syncmoodle',0), -('cadoles_portal_config_syncwordpress',0), -('cadoles_core_config_statistic',1), -('cadoles_core_config_mailing',1), -('cadoles_core_config_importuser',0), -('cadoles_cron_config',0), -('cadoles_cron_config_log',0);