feature profil de modération

This commit is contained in:
afornerot 2020-10-09 15:43:50 +02:00
parent bd547d9a21
commit 18963d115b
20 changed files with 936 additions and 97 deletions

View File

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

View File

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

View File

@ -0,0 +1,357 @@
<?php
namespace Cadoles\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\FormError;
use Cadoles\CoreBundle\Entity\PermModoProfil;
use Cadoles\CoreBundle\Entity\PermModo;
use Cadoles\CoreBundle\Form\PermmodoprofilType;
class PermmodoprofilController extends Controller
{
private $labelroute = 'cadoles_core_config_permmodoprofil';
private $labelentity = 'CadolesCoreBundle:PermModoProfil';
private $labeldata = 'permmodoprofil';
private $labeldatas = 'permmodoprofils';
public function listAction()
{
return $this->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 ="<a href='".$this->generateUrl('cadoles_core_config_permmodoprofil_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw'></i></a>";
if($data->getId()>0) $action.="<a href='".$this->generateUrl('cadoles_core_config_permmodoprofil_delete', array('id'=>$data->getId()))."'><i class='fa fa-trash fa-fw'></i></a>";
$action.="<a href='".$this->generateUrl('cadoles_core_config_permmodoprofil_permmodo', array('id'=>$data->getId()))."'><i class='fas fa-check-square fa-fw'></i></a>";
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();
}
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -0,0 +1,164 @@
<?php
namespace Cadoles\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="permmodoprofil")
*
*/
class PermModoProfil
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=50, unique=true)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity="PermModo", mappedBy="permmodoprofil", cascade={"persist"}, orphanRemoval=true)
*/
private $permmodos;
/**
* @ORM\OneToMany(targetEntity="User", mappedBy="permmodoprofil")
*/
private $users;
/**
* Constructor
*/
public function __construct()
{
$this->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;
}
}

View File

@ -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;
}
}

View File

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

View File

@ -0,0 +1,52 @@
<?php
namespace Cadoles\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManager;
class PermmodoprofilType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->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"
));
}
}

View File

@ -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"];

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,46 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
{{ form_start(form) }}
<h1 class="page-header">
{% 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 %}
</h1>
{{ form_widget(form.submit) }} <a class="btn btn-default" href={{ path('cadoles_core_config_permmodoprofil') }}>Annuler</a>
<br><br>
{% if app.session.flashbag.has('error') %}
<div class='alert alert-danger' style='margin: 5px 0px'>
<strong>Erreur</strong><br>
{% for flashMessage in app.session.flashbag.get('error') %}
{{ flashMessage }}<br>
{% endfor %}
</div>
{% endif %}
{% if app.session.flashbag.has('notice') %}
<div class='alert alert-info' style='margin: 5px 0px'>
<strong>Information</strong><br>
{% for flashMessage in app.session.flashbag.get('notice') %}
{{ flashMessage }}<br>
{% endfor %}
</div>
{% endif %}
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-pencil fa-fw"></i> Informations
</div>
<div class="panel-body">
{{ form_row(form.name) }}
</div>
</div>
{{ form_end(form) }}
{% endblock %}

View File

@ -0,0 +1,42 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
<h1 class="page-header">Gestion des Profils de Modération </h1>
{% if is_granted('ROLE_ADMIN') %}
<p><a class="btn btn-success" href={{ path('cadoles_core_config_permmodoprofil_submit') }}>Ajouter</a></p>
{% endif %}
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-table fa-fw"></i> Liste des Profils de Modération}
</div>
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables" style="width:100%">
<thead>
<tr>
<th width="70px" class="no-sort">Action</th>
<th>Label</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
{% 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 %}

View File

@ -0,0 +1,66 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
<form>
<h1 class="page-header">Modération du Profil = {{ profil.name }}</h1>
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-table fa-fw"></i> Permissions Modérateur
</div>
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables" style="width:100%">
<thead>
<tr>
<th >Action</th>
<th width="150px">Permission</th>
</tr>
</thead>
{% for permmodo in permmodos %}
<tr>
<td>{{ permmodo.label}}</td>
<td>
{% set checked="" %}
{% if permmodo.visible %} {% set checked="checked" %} {%endif %}
<input type="checkbox" class="switch" onChange="switchModo({{ permmodo.id }});" {{ checked }}>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
</form>
{% endblock %}
{% block localjavascript %}
function showInfo(id) {
$("#modalinfo #modalinfotext").html($("#"+id).attr("data").replace(/\n/g, "<br />"));
}
$(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 %}

View File

@ -88,7 +88,8 @@
{% if form.role is defined %}
{{ form_label(form.role) }}
{{ form_widget(form.role) }}
{{ form_widget(form.role) }}
<div id='blockpermmodoprofil'>{{ form_row(form.permmodoprofil) }}</div>
{% endif %}
</div>
</div>
@ -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();

View File

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