reglage conflit

This commit is contained in:
Arnaud Fornerot 2020-02-26 10:31:49 +01:00
commit e2da7e081f
14 changed files with 270 additions and 30 deletions

View File

@ -21,6 +21,9 @@ class SecurityController extends Controller
public function loginAction(Request $request) public function loginAction(Request $request)
{ {
// Récupération de la cible de navigation
$redirect = $request->get("redirect");
// Masteridentity // Masteridentity
$masteridentity=$this->getParameter("masteridentity"); $masteridentity=$this->getParameter("masteridentity");
@ -153,8 +156,10 @@ class SecurityController extends Controller
$dispatcher = new EventDispatcher(); $dispatcher = new EventDispatcher();
$dispatcher->dispatch("security.interactive_login", $event); $dispatcher->dispatch("security.interactive_login", $event);
if($redirect)
return $this->redirect($this->generateUrl('cadoles_core_home')); return $this->redirect($redirect);
else
return $this->redirect($this->generateUrl('cadoles_core_home'));
} }
public function logoutAction() { public function logoutAction() {

View File

@ -224,6 +224,9 @@ class OnlyCommand extends Command
if(!$group) { if(!$group) {
$namegroup=$onlygroup->id." - ".$onlygroup->title; $namegroup=$onlygroup->id." - ".$onlygroup->title;
// On enlève les caractères interdis
$namegroup=preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $namegroup);
// Ce nom de groupe existe-t-il déjà si oui erreur // Ce nom de groupe existe-t-il déjà si oui erreur
$group=$this->em->getRepository("CadolesCoreBundle:Group")->findBy(["label"=>$namegroup]); $group=$this->em->getRepository("CadolesCoreBundle:Group")->findBy(["label"=>$namegroup]);
if($group) if($group)

View File

@ -110,6 +110,17 @@ class PurgeFileCommand extends Command
} }
} }
$fs = new Filesystem();
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
foreach($users as $user) {
if(!$fs->exists($directory."/".$user->getAvatar())) {
$this->writeln($user->getUsername());
$user->setAvatar("noavatar.png");
$this->em->persist($user);
$this->em->flush();
}
}
// /web/uploads/header // /web/uploads/header
$this->writelnred(''); $this->writelnred('');
$this->writelnred('== Directory = Header'); $this->writelnred('== Directory = Header');

View File

@ -0,0 +1,84 @@
<?php
namespace Cadoles\CoreBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Cadoles\CoreBundle\Entity\User;
global $bdd01;
global $config;
class ScriptCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
protected function configure()
{
$this
->setName('Core:Script')
->setDescription('Lauch Script')
->setHelp('Execeute some script : visibletrue / ')
->addArgument('scriptname', InputArgument::OPTIONAL, 'scriptname')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
$this->output = $output;
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$this->writelnred('');
$this->writelnred('== Core:Script');
$this->writelnred('==========================================================================================================');
$scriptname = $input->getArgument('scriptname');
$this->writeln($scriptname);
switch($scriptname) {
case "visibletrue": $this->visibletrue(); break;
}
$this->writeln('');
return 1;
}
private function visibletrue() {
$users = $this->em->getRepository('CadolesCoreBundle:User')->findAll();
foreach($users as $user) {
if(!$user->getVisible()) {
$this->writeln($user->getUsername());
$user->setVisible(true);
$this->em->persist($user);
$this->em->flush();
}
}
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'Interne', 'SIREN'); (-100, 'Interne', 'SIREN');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}BkFFVAICIt3FUlHQLN1FsNWUtsPnLFRs (-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}oBuVhAUjam9tCeMBwS0xBsAM2PdHZLW3
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple'); ', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

View File

@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Cadoles\CoreBundle\Entity\Group; use Cadoles\CoreBundle\Entity\Group;
use Cadoles\CoreBundle\Entity\Usergroup; use Cadoles\CoreBundle\Entity\Usergroup;
@ -524,11 +525,15 @@ class GroupController extends Controller
// Notification mail auprès de la personne inscrite // Notification mail auprès de la personne inscrite
if($group->getFgcanshare()) { if($group->getFgcanshare()) {
$text="Vous venez d'être inscrit dans le groupe de travail : ".$group->getLabel(); $idpage =$group->getPages()->first()->getId();
$url = $this->generateUrl('cadoles_core_home', ["id"=>$idpage], UrlGeneratorInterface::ABSOLUTE_URL);
$texthtml="Vous venez d'être inscrit dans le groupe de travail : ".$group->getLabel()."<br>Suivez le lien suivant pour y accéder = <a href='$url'>$url</a>";
$text="Vous venez d'être inscrit dans le groupe de travail : ".$group->getLabel()."<br>Suivez le lien suivant pour y accéder = $url";
$template="template"; $template="template";
$mail_params=array( $mail_params=array(
"subject" => $this->get('session')->get('appname')." : Inscription au groupe de travail : ".$group->getLabel()."\n\n".$group->getDescription(), "subject" => $this->get('session')->get('appname')." : Inscription au groupe de travail : ".$group->getLabel()."\n\n".$group->getDescription(),
"body_html"=>nl2br($text), "body_html"=>$texthtml,
"body_text"=>$text "body_text"=>$text
); );
$to = $user->getEmail(); $to = $user->getEmail();
@ -987,6 +992,7 @@ class GroupController extends Controller
} }
} }
protected function getDatas() protected function getDatas()
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();

View File

@ -285,12 +285,12 @@ class RegistrationController extends Controller
foreach($emailmodos as $emailmodo) { foreach($emailmodos as $emailmodo) {
array_push($to,$emailmodo["email"]); array_push($to,$emailmodo["email"]);
} }
$text="Un utilisateur dont le mail nest pas en liste blanche souhaite sinscrire au ".$appname.".\nMerci dapprouver son inscription pour finaliser celle-ci."; $url = $this->generateUrl('cadoles_core_config_registration', '', UrlGeneratorInterface::ABSOLUTE_URL);
$mail_params=array( $mail_params=array(
"subject" => $appname." : Inscription à valider", "subject" => $appname." : Inscription à valider",
"body_html"=>nl2br($text), "body_html"=>"Un utilisateur dont le mail nest pas en liste blanche souhaite sinscrire au ".$appname.".\nMerci dapprouver son inscription pour finaliser celle-ci.<br><br>Veuillez vérifier cette inscription à cette adresse:<br><a href='$url'>$url</a>",
"body_text"=>$text "body_text"=>"Un utilisateur dont le mail nest pas en liste blanche souhaite sinscrire au ".$appname.".\nMerci dapprouver son inscription pour finaliser celle-ci.\n\nVeuillez vérifier cette inscription à cette adresse:\n$url"
); );
$message = $this->container->get('cadoles.core.service.mail'); $message = $this->container->get('cadoles.core.service.mail');

View File

@ -16,6 +16,9 @@ use Symfony\Component\Console\Output\OutputInterface;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Cadoles\CoreBundle\Entity\User; use Cadoles\CoreBundle\Entity\User;
use Cadoles\CoreBundle\Entity\UserGroup; use Cadoles\CoreBundle\Entity\UserGroup;
@ -765,6 +768,77 @@ class UserController extends Controller
]); ]);
} }
public function exportuserAction(Request $request) {
$em = $this->getDoctrine()->getManager();
$dir = $this->get('kernel')->getRootDir() . '/../uploads/export/';
$file = "export.csv";
$fs = new Filesystem();
$fs->mkdir($dir);
$csvh = fopen($dir.$file, 'w');
$d = ';'; // this is the default but i like to be explicit
$e = '"'; // this is the default but i like to be explicit
// Entête de colonne
$data=["id","Login","Nom","Prénom","Email","Téléphone",$this->getParameter("labelniveau01"),$this->getParameter("labelniveau02"),"Métier","Fonction","Nom Usage","Autres Prénom","Sexe","Adresse","Date Naissance","Pays Naissance","Ville Naissance"];
fputcsv($csvh, $data, $d, $e);
// Liste des utilisateurs en fonction du role de l'utilisateur en cours
if($this->isGranted('ROLE_ADMIN')) {
$users=$em->getRepository($this->labelentity)->findAll();
}
elseif($this->isGranted('ROLE_MODO')) {
$qb = $em->createQueryBuilder();
$users = $qb->select('user')
->from($this->labelentity,'user')
->from('CadolesCoreBundle:Niveau01','niveau01')
->from('CadolesCoreBundle:UserModo', 'usermodo')
->where('user.niveau01=niveau01.id')
->andwhere("usermodo.niveau01 = user.niveau01")
->andWhere("usermodo.user = :userid")
->setParameter("userid", $this->getUser()->getId())
->getQuery()
->getResult();
}
foreach($users as $user) {
$groups="";
foreach($user->getGroups() as $group) {
$groups.=$group->getGroup()->getLabel()." ";
}
$data = [
"id"=>$user->getId(),
"username"=>$user->getUsername(),
"name"=>$user->getLastname(),
"firstname"=>$user->getFirstname(),
"email"=>$user->getEmail(),
"phone"=>$user->getTelephonenumber(),
"niveau01"=>$user->getNiveau01()->getLabel(),
"niveau02"=>($user->getNiveau02()?$user->getNiveau02()->getLabel():""),
"job"=>$user->getJob(),
"position"=>$user->getPosition(),
"usualname"=>$user->getUsualname(),
"givensname"=>$user->getGivensname(),
"gender"=>$user->getGender(),
"postaladress"=>$user->getPostaladress(),
"birthdate"=>($user->getBirthdate()?$user->getBirthdate()->format("d/m/Y"):""),
"birthcountry"=>($user->getBirthcountry()?$user->getBirthcountry()->getLabel():""),
"birthplace"=>($user->getBirthplace()?$user->getBirthplace()->getLabel():""),
];
fputcsv($csvh, $data, $d, $e);
}
fclose($csvh);
$response = new BinaryFileResponse($dir.$file);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
}
public function importuserAction(Request $request) { public function importuserAction(Request $request) {
if($this->GetParameter("masteridentity")!="SQL") if($this->GetParameter("masteridentity")!="SQL")
throw $this->createNotFoundException('Permission denied'); throw $this->createNotFoundException('Permission denied');

View File

@ -266,6 +266,10 @@ cadoles_core_config_importuser_filectrl:
path: /config/importuserfilectrl path: /config/importuserfilectrl
defaults: { _controller: CadolesCoreBundle:User:importuserfilectrl } defaults: { _controller: CadolesCoreBundle:User:importuserfilectrl }
cadoles_core_config_user_export:
path: /config/exportuser
defaults: { _controller: CadolesCoreBundle:User:exportuser }
#-- Access user #-- Access user
cadoles_core_user: cadoles_core_user:
path: /user path: /user

View File

@ -51,10 +51,21 @@
{% endblock %} {% endblock %}
{% block localjavascript %} {% block localjavascript %}
$('document').ready(function(){ $('document').ready(function(){
setTimeout(function(){ setTimeout(function(){
//parent.location.reload(); //parent.location.reload();
parent.location.href = "{{ path("cadoles_core_home") }}"; {% if redirectto is defined %}
console.log("{{ redirectto }}");
console.log("{{ mode_auth }}");
{% if mode_auth == "CAS" %}
parent.location.href = "{{ path("cas_sp.login", {redirect:redirectto}) }}";
{% else %}
parent.location.href = "{{ path("cadoles_core_home") }}";
{% endif %}
{% else %}
//parent.location.href = "{{ path("cadoles_core_home") }}";
{% endif %}
}, 2000); }, 2000);
}); });
{% endblock %} {% endblock %}

View File

@ -9,6 +9,7 @@ td { font-size: 10px; }
<h1 class="page-header">Gestion des Utilisateurs</h1> <h1 class="page-header">Gestion des Utilisateurs</h1>
{% if masteridentity=="SQL" %} {% if masteridentity=="SQL" %}
<a class="btn btn-success" href={{ path('cadoles_core_config_user_submit') }}>Ajouter</a> <a class="btn btn-success" href={{ path('cadoles_core_config_user_submit') }}>Ajouter</a>
<a class="btn btn-success" href={{ path('cadoles_core_config_user_export') }}>Exporter CSV</a>
<br><br> <br><br>
{% elseif masteridentity=="LDAP" %} {% elseif masteridentity=="LDAP" %}
<a class="btn btn-success" href={{ path('cadoles_core_config_user_sync') }}>Synchroniser avec Annuaire</a> <a class="btn btn-success" href={{ path('cadoles_core_config_user_sync') }}>Synchroniser avec Annuaire</a>

View File

@ -1258,7 +1258,7 @@ class PagewidgetController extends Controller
return $this->render($this->labelentity.':viewflux.html.twig', [ return $this->render($this->labelentity.':viewflux.html.twig', [
'entity' => $entity, 'entity' => $entity,
'canupdate' => $canupdate, 'canupdate' => $canupdate,
//'fluxs' => $fluxsordered, 'fluxs' => ["id"=>0],
'access' => $access, 'access' => $access,
'feeds' => $feeds, 'feeds' => $feeds,
'modelist' => $modelist, 'modelist' => $modelist,
@ -1865,6 +1865,10 @@ class PagewidgetController extends Controller
} }
} }
// Trier les item par title
$title = array_column($items, 'title');
array_multisort($title, SORT_ASC, $items);
// Render // Render
return $this->render($this->labelentity.':viewappexternal.html.twig', [ return $this->render($this->labelentity.':viewappexternal.html.twig', [
'entity' => $entity, 'entity' => $entity,

View File

@ -21,7 +21,8 @@ class DefaultController extends BaseController
return $this->render('CadolesCoreBundle:Core:reconnect.html.twig', [ return $this->render('CadolesCoreBundle:Core:reconnect.html.twig', [
'useheader' => true, 'useheader' => true,
'usemenu' => false, 'usemenu' => false,
'usesidebar' => false, 'usesidebar' => false,
'redirectto' => $this->get('session')->get("_security.main.target_path")
]); ]);
} }
@ -45,6 +46,7 @@ class DefaultController extends BaseController
public function loginAction(Request $request) public function loginAction(Request $request)
{ {
$idpEntityId = $request->get('idp'); $idpEntityId = $request->get('idp');
if (null === $idpEntityId) { if (null === $idpEntityId) {
return $this->redirect($this->generateUrl($this->container->getParameter('lightsaml_sp.route.discovery'))); return $this->redirect($this->generateUrl($this->container->getParameter('lightsaml_sp.route.discovery')));
} }

View File

@ -46,10 +46,48 @@ class CountMessageCommand extends Command
$this->appname = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"appname"])->getValue(); $this->appname = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"appname"])->getValue();
$this->url= "https://".$this->container->getParameter('weburl')."/".$this->container->getParameter('alias'); $this->url= "https://".$this->container->getParameter('weburl')."/".$this->container->getParameter('alias');
$now=new \DateTime('now');
$now->modify("-1 day");
// Pour chaque groupe purger l'ensemble des message > 100
$groups=$this->em->getRepository("CadolesCoreBundle:Group")->findAll();
foreach($groups as $group) {
// On garde les 100 premiers
$qb = $this->em->createQueryBuilder();
$messagestokeep = $qb
->select('m.id')
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->setParameter('group', $group)
->orderBy('m.id','DESC')
->setMaxResults(100)
->getQuery()->getArrayResult();
// Sur l'ensemble des messages
$qb = $this->em->createQueryBuilder();
$messages = $qb
->select('m')
->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group')
->setParameter('group', $group)
->getQuery()->getResult();
foreach($messages as $message) {
// S'il ne fait pas parties des 100 premiers on le supprime
if(!in_array(["id"=>$message->getId()],$messagestokeep)) {
$this->writeln("PURGE ".$message->getId());
$this->em->remove($message);
$this->em->flush();
}
}
}
// Pour chaque utilisateur // Pour chaque utilisateur
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll(); $users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
foreach($users as $user) { foreach($users as $user) {
$cptnotread=0; $cptnotread=0;
$body="";
// Pour chaque group de l'utilisateur // Pour chaque group de l'utilisateur
foreach($user->getGroups() as $usergroup) { foreach($user->getGroups() as $usergroup) {
@ -57,25 +95,22 @@ class CountMessageCommand extends Command
$group=$usergroup->getGroup(); $group=$usergroup->getGroup();
if($group->getFgcanshare()) { if($group->getFgcanshare()) {
$qb = $this->em->createQueryBuilder(); $qb = $this->em->createQueryBuilder();
$tm = $qb ->select($qb->expr()->count('m.id')) $messages = $qb
->select('m')
->from('CadolesWebsocketBundle:Message', 'm') ->from('CadolesWebsocketBundle:Message', 'm')
->where('m.group = :group') ->where('m.group = :group')
->andWhere('m.user != :user') ->andWhere('m.user != :user')
->andWhere('m.submitdate >= :date')
->setParameter('group', $group) ->setParameter('group', $group)
->setParameter('user', $user) ->setParameter('user', $user)
->getQuery()->getSingleScalarResult(); ->setParameter('date',$now)
->getQuery()->getResult();
$qb = $this->em->createQueryBuilder(); foreach($messages as $message) {
$tr = $qb ->select($qb->expr()->count('m.id')) if(!$message->getReaders() || !$message->getReaders()->contains($user)) {
->from('CadolesWebsocketBundle:Message', 'm') $cptnotread++;
->where('m.group = :group') $body.="<hr><b>".$message->getGroup()->getLabel()."</b><br>".$message->getUser()->getLastname()." ".$message->getUser()->getFirstname()."<br><br>".$message->getTopic();
->andWhere('m.user != :user') }
->andWhere(':user MEMBER OF m.readers') }
->setParameter('group', $group)
->setParameter('user', $user)
->getQuery()->getSingleScalarResult();
if($tm-$tr>0) $cptnotread+=($tm-$tr);
} }
} }
@ -87,13 +122,13 @@ class CountMessageCommand extends Command
$mail_params=array( $mail_params=array(
"subject" => $this->appname." : Messages non lus", "subject" => $this->appname." : Messages non lus",
"body_html"=>"<p>Vous avez ".$cptnotread." messages non lus sur ".$this->appname."</p><p>Vous pouvez les consulter sur <a href='".$this->url."'>".$this->url."</a></p>", "body_html"=>"<p>Vous avez ".$cptnotread." messages non lus sur ".$this->appname."</p><p>Vous pouvez les consulter sur <a href='".$this->url."'>".$this->url."</a></p>".$body,
"body_text"=>"Vous avez ".$cptnotread." messages non lus sur ".$this->appname."\nVous pouvez les consulter sur ".$this->url, "body_text"=>"Vous avez ".$cptnotread." messages non lus sur ".$this->appname."\nVous pouvez les consulter sur ".$this->url.$body,
); );
$message = $this->container->get('cadoles.core.service.mail'); $message = $this->container->get('cadoles.core.service.mail');
$message->sendEmail($template, $mail_params, $user->getEmail(), $this->noreply, $this->appname); $message->sendEmail($template, $mail_params, $user->getEmail(), $this->noreply, $this->appname);
} }
} }
$this->writeln(''); $this->writeln('');
return 1; return 1;