From df9e7a3e695056d408295b8eabafad1f32c26f0e Mon Sep 17 00:00:00 2001
From: Arnaud Fornerot
{%if access=="admin" %}
-
Si ce n’est pas le cas, il faut que vous renseigniez la case motivation de votre demande"));
}
diff --git a/src/Controller/WhitelistController.php b/src/Controller/WhitelistController.php
index cb73aff..735419b 100644
--- a/src/Controller/WhitelistController.php
+++ b/src/Controller/WhitelistController.php
@@ -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);
diff --git a/src/Entity/Audit.php b/src/Entity/Audit.php
new file mode 100644
index 0000000..1f79860
--- /dev/null
+++ b/src/Entity/Audit.php
@@ -0,0 +1,132 @@
+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;
+ }
+
+}
+
diff --git a/src/EventListener/AllSubscriber.php b/src/EventListener/AllSubscriber.php
index c07479f..67f30e1 100644
--- a/src/EventListener/AllSubscriber.php
+++ b/src/EventListener/AllSubscriber.php
@@ -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);
+ }
+ }
+ }
+
+
}
diff --git a/src/EventListener/GroupSubscriber.php b/src/EventListener/GroupSubscriber.php
index c36aaeb..45594dc 100644
--- a/src/EventListener/GroupSubscriber.php
+++ b/src/EventListener/GroupSubscriber.php
@@ -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();
}
}
}
diff --git a/src/Repository/AuditRepository.php b/src/Repository/AuditRepository.php
new file mode 100644
index 0000000..c58b15d
--- /dev/null
+++ b/src/Repository/AuditRepository.php
@@ -0,0 +1,33 @@
+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();
+ }
+ }
+}
diff --git a/src/Service/AppSession.php b/src/Service/AppSession.php
index 0bcf9f6..795f222 100644
--- a/src/Service/AppSession.php
+++ b/src/Service/AppSession.php
@@ -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);
+ }
}
}
diff --git a/templates/Audit/list.html.twig b/templates/Audit/list.html.twig
new file mode 100644
index 0000000..ad0d0cb
--- /dev/null
+++ b/templates/Audit/list.html.twig
@@ -0,0 +1,66 @@
+{% extends "base.html.twig" %}
+
+{% block body %}
+
+AUDIT {{ entityname }}
+
+
+
+
+
+
+
+
+
+
+ {% for audit in audits|reverse %}
+ Date
+ Par
+ Action
+ Id
+ Détail
+
+
+ {% endfor %}
+
+ {{audit.datesubmit|date("d/m/Y H:i")}}
+ {{audit.username}}
+ {{audit.description}}
+ {{audit.entityid}}
+
+
+ {% for key, detail in audit.detail %}
+ {% if audit.description=="UPDATE" %}
+ {{key}} =
+ de {%if detail[0] is empty%}null {%else%}{{detail[0]|join(', ')}}{%endif%}
+ à {%if detail[1] is empty%}null {%else%} {{detail[1]|join(', ')}}{%endif%}
+
+ {% else %}
+ id {{detail}}
+ {% endif %}
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+
+ {% for audit in audits|reverse %}
+ Date
+ Par
+ Action
+ Détail
+
+
+ {% endfor %}
+
+ {{audit.datesubmit|date("d/m/Y H:i")}}
+ {{audit.username}}
+ {{audit.description}}
+
+
+ {% for key, detail in audit.detail %}
+ {% if audit.description=="UPDATE" %}
+ {{key}} =
+ de {%if detail[0] is empty%}null {%else%}{{detail[0]|join(', ')}}{%endif%}
+ à {%if detail[1] is empty%}null {%else%} {{detail[1]|join(', ')}}{%endif%}
+
+ {% else %}
+ id {{detail}}
+ {% endif %}
+ {% endfor %}
+
+
+
+{% endif %}
CRON JOBS
+ {% if auditUse and (access=="admin" or access=="audit") %}
+ Audit
+
+ {% endif %}
Gestion des Groupes
+
+ Ajouter + {% if auditUse and (access=="admin" or access=="audit") %} + Audit + {% endif %} +
+ Ajouter + {% if auditUse and (access=="admin" or access=="audit") %} + Audit + {% endif %} +