first commit symfony 6

This commit is contained in:
2022-07-26 16:03:53 +02:00
parent 8181ca1c39
commit df9e7a3e69
35 changed files with 737 additions and 34 deletions

View File

@ -72,7 +72,6 @@ class CronCommand extends Command
$now=new \DateTime();
$cron->setStartexecdate($now);
//$cron->setStatut(1);
$this->em->persist($cron);
$this->em->flush();
// Récupération de la commande
@ -109,7 +108,6 @@ class CronCommand extends Command
// Statut OK/KO
$cron->setStatut(($returnCode==Command::FAILURE?0:1));
$this->em->persist($cron);
$this->em->flush();
}

View File

@ -496,6 +496,11 @@ class SynchroCommand extends Command
$filter="gidnumber=".$group->getId();
$ldapentrys=$this->ldap->search($filter,$attributes,$this->basegroup);
if(empty($ldapentrys)) {
$filter=str_replace("*",$group->getLabel(),$this->filtergroup);
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
}
if(empty($ldapentrys)) {
$this->writeln($group->getLabel()." = SUBMIT");
$this->ldap->addGroup($group);
}
@ -522,6 +527,11 @@ class SynchroCommand extends Command
foreach($niveau02s as $niveau02) {
$filter="gidnumber=".$niveau02->getId();
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau02);
if(empty($ldapentrys)) {
$filter=str_replace("*",$niveau02->getLabel(),$this->filtergroup);
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
}
if(empty($ldapentrys)) {
$this->writeln($niveau02->getLabel()." = SUBMIT");
$this->ldap->addNiveau02($niveau02);
@ -554,6 +564,11 @@ class SynchroCommand extends Command
$filter="gidnumber=".$niveau01->getId();
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
if(empty($ldapentrys)) {
$filter=str_replace("*",$niveau01->getLabel(),$this->filtergroup);
$ldapentrys=$this->ldap->search($filter,$attributes,$this->baseniveau01);
}
if(empty($ldapentrys)) {
$this->writeln($niveau01->getLabel()." = SUBMIT");
$this->ldap->addNiveau01($niveau01);

View File

@ -0,0 +1,59 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Audit as Entity;
use App\Form\AuditType as Form;
class AuditController extends AbstractController
{
private $data="audit";
private $entity="App\Entity\Audit";
private $twig="Audit/";
private $route="app_admin_audit";
public function list($entityname,$access,ManagerRegistry $em): Response
{
$datas = $em->getRepository($this->entity)->findBy(["entityname"=>$entityname]);
return $this->render($this->twig.'list.html.twig',[
$this->data."s" => $datas,
"entityname" => $entityname,
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>true,
]);
}
public function auditrender($entityname,$entityid,$access,ManagerRegistry $em): Response
{
$datas = $em->getRepository($this->entity)->findBy(["entityname"=>$entityname,"entityid"=>$entityid]);
/*
if($entityname=="User") {
$user=$em->getRepository("App\Entity\User")->find($entityid);
if($user) {
foreach($user->getModos() as $usermodo) {
$auditusermods=$em->getRepository($this->entity)->findBy(["entityname"=>"UserModo","entityid"=>$usermodo->getId()]);
foreach($auditusermods as $auditusermod) {
$usermodo=$em->getRepository("App\Entity\UserModo")->find($auditusermod->getEntityid());
$niveau01=$em->getRepository("App\Entity\Niveau01")->find($usermodo->getNiveau01()->getId());
$auditusermod->setDescription($auditusermod->getDescription()." UserModo");
$auditusermod->setDetail([$niveau01->getId()." = ".$niveau01->getLabel()]);
}
$datas=array_merge($datas,$auditusermods);
}
}
}
*/
return $this->render($this->twig.'render.html.twig',[
$this->data."s" => $datas,
]);
}
}

View File

@ -22,6 +22,7 @@ class ConfigController extends AbstractController
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>true,
"access"=>$access,
]);
}

View File

@ -20,12 +20,13 @@ class CronController extends AbstractController
private $twig="Cron/";
private $route="app_admin_cron";
public function list(): Response
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig',[
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>true,
"access"=>$access,
]);
}
@ -104,7 +105,7 @@ class CronController extends AbstractController
return new JsonResponse($output);
}
public function update($id,Request $request,ManagerRegistry $em): Response
public function update($id,$access,Request $request,ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data=$em->getRepository($this->entity)->find($id);
@ -134,7 +135,8 @@ class CronController extends AbstractController
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView()
'form' => $form->createView(),
'access' => $access,
]);
}

View File

@ -19,12 +19,13 @@ class Niveau01Controller extends AbstractController
private $twig="Niveau01/";
private $route="app_admin_niveau01";
public function list(): Response
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig',[
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>true,
"access"=>$access,
]);
}
@ -100,7 +101,7 @@ class Niveau01Controller extends AbstractController
}
public function submit(Request $request,ManagerRegistry $em): Response
public function submit($access,Request $request,ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data = new Entity();
@ -137,10 +138,11 @@ class Niveau01Controller extends AbstractController
"mode"=>"submit",
"form"=>$form->createView(),
$this->data=>$data,
"access"=>$access,
]);
}
public function update($id,Request $request,ManagerRegistry $em): Response
public function update($id,$access,Request $request,ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data=$em->getRepository($this->entity)->find($id);
@ -173,11 +175,12 @@ class Niveau01Controller extends AbstractController
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView()
'form' => $form->createView(),
"access" => $access
]);
}
public function delete($id,Request $request,ManagerRegistry $em): Response
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
{
// Récupération de l'enregistrement courant
$data=$em->getRepository($this->entity)->find($id);

View File

@ -219,7 +219,7 @@ class RegistrationController extends AbstractController
$data->setStatut($idstatut);
// Sur erreur
$this->getErrorForm(null,$form,$request,$data,"submit",$idstatut);
$this->getErrorForm(null,$form,$request,$data,"submit",$idstatut,$em);
// Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) {
@ -710,7 +710,7 @@ class RegistrationController extends AbstractController
throw $this->createAccessDeniedException('Permission denied');
}
protected function getErrorForm($id,$form,$request,$data,$mode,$idstatut) {
protected function getErrorForm($id,$form,$request,$data,$mode,$idstatut,$em) {
if ($form->get('submit')->isClicked() && $mode=="submit") {
// Si validation par administrateur demander une motivation
$appmoderegistration = $this->getParameter('appModeregistration');
@ -718,7 +718,7 @@ class RegistrationController extends AbstractController
// On recherche le domaine du mail dans la liste blanche
$email=explode("@",$data->getEmail());
$domaine=end($email);
$whitelist = $this->getDoctrine()->getManager()->getRepository("App\Entity\Whitelist")->findBy(["label"=>$domaine]);
$whitelist = $em->getManager()->getRepository("App\Entity\Whitelist")->findBy(["label"=>$domaine]);
if(!$whitelist)
$form->addError(new FormError("Attention, le suffixe de votre adresse mail nest pas dans la liste des administrations autorisées, merci de bien vouloir privilégier votre adresse professionnelle si vous en avez une.<br>Si ce nest pas le cas, il faut que vous renseigniez la case motivation de votre demande"));
}

View File

@ -18,12 +18,13 @@ class WhitelistController extends AbstractController
private $twig="Whitelist/";
private $route="app_admin_whitelist";
public function list(): Response
public function list($access): Response
{
return $this->render($this->twig.'list.html.twig',[
"useheader"=>true,
"usemenu"=>false,
"usesidebar"=>true,
"access"=>$access,
]);
}
@ -98,7 +99,7 @@ class WhitelistController extends AbstractController
return new JsonResponse($output);
}
public function submit(Request $request,ManagerRegistry $em): Response
public function submit($access,Request $request,ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data = new Entity();
@ -129,10 +130,11 @@ class WhitelistController extends AbstractController
"mode"=>"submit",
"form"=>$form->createView(),
$this->data=>$data,
"access"=>$access,
]);
}
public function update($id,Request $request,ManagerRegistry $em): Response
public function update($id,$access,Request $request,ManagerRegistry $em): Response
{
// Initialisation de l'enregistrement
$data=$em->getRepository($this->entity)->find($id);
@ -160,11 +162,12 @@ class WhitelistController extends AbstractController
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView()
'form' => $form->createView(),
"access"=>$access,
]);
}
public function delete($id,Request $request,ManagerRegistry $em): Response
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
{
// Récupération de l'enregistrement courant
$data=$em->getRepository($this->entity)->find($id);

132
src/Entity/Audit.php Normal file
View File

@ -0,0 +1,132 @@
<?php
namespace App\Entity;
use App\Repository\AuditRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* Cron
*
* @ORM\Table(name="audit",indexes={@ORM\Index(name="search_idx", columns={"entityname", "entityid", "datesubmit"})})
* @ORM\Entity(repositoryClass="App\Repository\AuditRepository")
*/
class Audit
{ /**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=250, nullable=false)
*/
private $entityname;
/**
* @ORM\Column(type="string", length=250, nullable=false)
*/
private $entityid;
/**
* @ORM\Column(type="datetime")
*/
private $datesubmit;
/**
* @ORM\Column(type="string", length=250, nullable=false)
*/
private $username;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $detail = array();
public function getId(): ?int
{
return $this->id;
}
public function getEntityname(): ?string
{
return $this->entityname;
}
public function setEntityname(string $entityname): self
{
$this->entityname = $entityname;
return $this;
}
public function getEntityid(): ?string
{
return $this->entityid;
}
public function setEntityid(string $entityid): self
{
$this->entityid = $entityid;
return $this;
}
public function getDatesubmit(): ?\DateTimeInterface
{
return $this->datesubmit;
}
public function setDatesubmit(\DateTimeInterface $datesubmit): self
{
$this->datesubmit = $datesubmit;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDetail(): array
{
return $this->detail;
}
public function setDetail(?array $detail): self
{
$this->detail = $detail;
return $this;
}
}

View File

@ -5,15 +5,32 @@ namespace App\EventListener;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Doctrine\ORM\Proxy\Proxy;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Entity\Audit as Audit;
class AllSubscriber implements EventSubscriberInterface
{
private $entity;
private $token;
private $params;
public function __construct(EntityManagerInterface $em, TokenStorageInterface $token,ParameterBagInterface $params)
{
$this->em = $em;
$this->token = $token;
$this->params = $params;
}
public function getSubscribedEvents(): array
{
return [
Events::preRemove,
Events::onFlush,
];
}
@ -25,4 +42,156 @@ class AllSubscriber implements EventSubscriberInterface
if($this->entity->getId()<0)
throw new \Exception("Impossible de supprimer cet enregistrement. C'est un enregistrement système");
}
public function onFlush(OnFlushEventArgs $eventArgs): void
{
$this->entity = $eventArgs->getEntityManager();
if ($this->entity instanceof Audit||!$this->params->get("auditUse")) return;
$this->audit();
}
private function audit() {
$token = $this->token->getToken();
if(!$token)$user="job";
else {
$user=$token->getUser();
if($user!="anon.") $user = $user->getUsername();
else $user="job";
}
$uow = $this->em->getUnitOfWork();
$uow->computeChangeSets();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
$metaCar = $this->em->getClassMetadata(get_class($entity));
$className=str_replace("App\\Entity\\","",$metaCar->getName());
$nameold="";
if($metaCar->hasField("name"))
$nameold=" = ".$entity>getName();
elseif($metaCar->hasField("label"))
$nameold=" = ".$entity->getLabel();
elseif($metaCar->hasField("username"))
$nameold=" = ".$entity->getUsername();
$audit=new Audit();
$audit->setDatesubmit(new \DateTime("now"));
$audit->setEntityname($className);
$audit->setEntityid($entity->getId());
$audit->setUsername($user);
$audit->setDescription("SUBMIT");
$audit->setDetail(["id"=>$entity->getId().$nameold]);
$this->em->persist($audit);
$uow->computeChangeSet($this->em->getClassMetadata(get_class($audit)), $audit);
}
foreach ($uow->getScheduledEntityDeletions() as $entity) {
$metaCar = $this->em->getClassMetadata(get_class($entity));
$className=str_replace("App\\Entity\\","",$metaCar->getName());
$nameold="";
if($metaCar->hasField("name"))
$nameold=" = ".$entity>getName();
elseif($metaCar->hasField("label"))
$nameold=" = ".$entity->getLabel();
elseif($metaCar->hasField("username"))
$nameold=" = ".$entity->getUsername();
$audit=new Audit();
$audit->setDatesubmit(new \DateTime("now"));
$audit->setEntityname($className);
$audit->setEntityid($entity->getId());
$audit->setUsername($user);
$audit->setDescription("DELETE");
$audit->setDetail(["id"=>$entity->getId().$nameold]);
$this->em->persist($audit);
$uow->computeChangeSet($this->em->getClassMetadata(get_class($audit)), $audit);
}
foreach ($uow->getScheduledEntityUpdates() as $entity) {
$changeSet = $uow->getEntityChangeSet($entity);
// Unaudit field
$className = str_replace("App\\Entity\\","",$this->em->getClassMetadata(get_class($entity))->getName());
switch($className) {
case "Audit":
$changeSet=null;
break;
case "User":
unset($changeSet["visitecpt"]);
unset($changeSet["visitedate"]);
unset($changeSet["preference"]);
unset($changeSet["keyvalue"]);
unset($changeSet["keyexpire"]);
unset($changeSet["apikey"]);
unset($changeSet["password"]);
unset($changeSet["passwordplain"]);
unset($changeSet["salt"]);
break;
default:
unset($changeSet["apikey"]);
break;
}
if ($changeSet) {
$mychange=[];
foreach($changeSet as $key => $value) {
// Le champs modifié est-il une entité
$isentity0=($value[0]&&is_object($value[0])&&get_class($value[0])&&get_class($value[0])!="DateTime");
$isentity1=($value[1]&&is_object($value[1])&&get_class($value[1])&&get_class($value[1])!="DateTime");
if($isentity0||$isentity1) {
$nameold="";
if($isentity0) {
$metaCar = $this->em->getClassMetadata(get_class($value[0]));
if($metaCar->hasField("name"))
$nameold=" = ".$value[0]->getName();
elseif($metaCar->hasField("label"))
$nameold=" = ".$value[0]->getLabel();
elseif($metaCar->hasField("username"))
$nameold=" = ".$value[0]->getUsername();
$nameold= $value[0]->getId().$nameold;
}
$namenew="";
if($isentity1) {
$metaCar = $this->em->getClassMetadata(get_class($value[1]));
if($metaCar->hasField("name"))
$namenew=" = ".$value[1]->getName();
elseif($metaCar->hasField("label"))
$namenew=" = ".$value[1]->getLabel();
elseif($metaCar->hasField("username"))
$namenew=" = ".$value[1]->getUsername();
$namenew= $value[1]->getId().$namenew;
}
$mychange[$key]=[$nameold,$namenew];
}
else $mychange[$key]=$value;
}
$audit=new Audit();
$audit->setDatesubmit(new \DateTime("now"));
$audit->setEntityname($className);
$audit->setEntityid($entity->getId());
$audit->setUsername($user);
$audit->setDescription("UPDATE");
$audit->setDetail($mychange);
$this->em->persist($audit);
$uow->computeChangeSet($this->em->getClassMetadata(get_class($audit)), $audit);
}
}
}
}

View File

@ -117,8 +117,10 @@ class GroupSubscriber implements EventSubscriberInterface
// Le propriétaire passe manager
$usergroups=$this->em->getRepository("App\Entity\UserGroup")->findBy(["group"=>$group,"rolegroup"=>"100"]);
foreach($usergroups as $usergroup) {
$usergroup->setRolegroup(90);
$this->em->flush();
if($usergroup->getUser()!=$group->getOwner()) {
$usergroup->setRolegroup(90);
$this->em->flush();
}
}
// Le propriétaire prend son role dans le groupe
@ -129,10 +131,14 @@ class GroupSubscriber implements EventSubscriberInterface
$usergroup->setUser($group->getOwner());
$usergroup->setGroup($group);
$usergroup->setApikey(Uuid::uuid4());
$usergroup->setRolegroup(100);
$this->em->persist($usergroup);
$this->em->flush();
}
elseif($usergroup->getRolegroup()!=100) {
$usergroup->setRolegroup(100);
$this->em->flush();
}
$usergroup->setRolegroup(100);
$this->em->persist($usergroup);
$this->em->flush();
}
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Repository;
use App\Entity\Audit;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class AuditRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Audit::class);
}
public function add(Audit $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Audit $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
}

View File

@ -49,6 +49,7 @@
// Préférence par défaut
$session->set("fgheader", true);
$session->set("fgaudit", false);
// Préférence
if($curentuser!="anon.") {
@ -59,6 +60,12 @@
$fgheader=($preference["fgheader"][0]=="true");
$session->set("fgheader", $fgheader);
}
// Préférence audit
if(array_key_exists("fgaudit",$preference)) {
$fgaudit=($preference["fgaudit"][0]=="true");
$session->set("fgaudit", $fgaudit);
}
}
}