first commit symfony 6
This commit is contained in:
28
src/EventListener/AllSubscriber.php
Normal file
28
src/EventListener/AllSubscriber.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
class AllSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $entity;
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::preRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
|
||||
// Les enregistrements négatifs sont des enregistrements systeme indispensable
|
||||
if($this->entity->getId()<0)
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. C'est un enregistrement système");
|
||||
}
|
||||
}
|
138
src/EventListener/GroupSubscriber.php
Normal file
138
src/EventListener/GroupSubscriber.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Group as Entity;
|
||||
use App\Entity\UserGroup as UserGroup;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Service\LdapService;
|
||||
|
||||
class GroupSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
|
||||
// On s'assure que le propriétaire est bien membre du groupe avec le role manager
|
||||
$this->ctrlOwner();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
|
||||
// On s'assure que le propriétaire est bien membre du groupe avec le role manager
|
||||
$this->ctrlOwner();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
private function nine2ldap() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification group dans annuaire
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesGroup();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("basegroup"));
|
||||
if(empty($ldapentrys)) {
|
||||
$this->ldap->addGroup($this->entity);
|
||||
}
|
||||
elseif($this->ldap->ismodifyGroup($this->entity,$ldapentrys[0])) {
|
||||
$this->ldap->modifyGroup($this->entity,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function nine2ldapremove() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesGroup();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("basegroup"));
|
||||
if(!empty($ldapentrys)) {
|
||||
$this->ldap->deleteGroup($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ctrlOwner() {
|
||||
$group=$this->entity;
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// Le propriétaire prend son role dans le groupe
|
||||
if($group->getOwner()) {
|
||||
$usergroup=$this->em->getRepository("App\Entity\UserGroup")->findOneBy(["group"=>$group,"user"=>$group->getOwner()]);
|
||||
if(!$usergroup) {
|
||||
$usergroup=new UserGroup();
|
||||
$usergroup->setUser($group->getOwner());
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
}
|
||||
$usergroup->setRolegroup(100);
|
||||
$this->em->persist($usergroup);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
118
src/EventListener/Niveau01Subscriber.php
Normal file
118
src/EventListener/Niveau01Subscriber.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Niveau01 as Entity;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
use App\Service\LdapService;
|
||||
|
||||
|
||||
class Niveau01Subscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Impossible de supprimer si présence de niveau02 rattaché
|
||||
if(!$this->entity->getNiveau02s()->isEmpty())
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 02");
|
||||
|
||||
// Impossible de supprimer si présence de registration rattaché
|
||||
if(!$this->entity->getRegistrations()->isEmpty())
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. Il est lié à des inscriptions");
|
||||
|
||||
// Impossible de supprimer si présence de user rattaché
|
||||
if(!$this->entity->getUsers()->isEmpty())
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs");
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
|
||||
private function nine2ldap() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesNiveau01();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseniveau01"));
|
||||
if(empty($ldapentrys)) {
|
||||
$this->ldap->addNiveau01($this->entity);
|
||||
}
|
||||
elseif($this->ldap->ismodifyNiveau01($this->entity,$ldapentrys[0])) {
|
||||
$this->ldap->modifyNiveau01($this->entity,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesNiveau01();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseniveau01"));
|
||||
if(!empty($ldapentrys)) {
|
||||
$this->ldap->deleteNiveau01($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
112
src/EventListener/Niveau02Subscriber.php
Normal file
112
src/EventListener/Niveau02Subscriber.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Niveau02 as Entity;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
use App\Service\LdapService;
|
||||
|
||||
class Niveau02Subscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Impossible de supprimer si présence de registration rattaché
|
||||
if(!$this->entity->getRegistrations()->isEmpty())
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. Il est lié à des inscriptions");
|
||||
|
||||
// Impossible de supprimer si présence de user rattaché
|
||||
if(!$this->entity->getUsers()->isEmpty())
|
||||
throw new \Exception("Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs");
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;;
|
||||
}
|
||||
|
||||
private function nine2ldap() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesNiveau02();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseniveau02"));
|
||||
if(empty($ldapentrys)) {
|
||||
$this->ldap->addNiveau02($this->entity);
|
||||
}
|
||||
elseif($this->ldap->ismodifyNiveau02($this->entity,$ldapentrys[0])) {
|
||||
$this->ldap->modifyNiveau02($this->entity,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
$filter="gidnumber=".$this->entity->getId();
|
||||
$attributes=$this->ldap->listAttributesNiveau02();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseniveau02"));
|
||||
if(!empty($ldapentrys)) {
|
||||
$this->ldap->deleteNiveau02($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
src/EventListener/UserGroupSubscriber.php
Normal file
67
src/EventListener/UserGroupSubscriber.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\UserGroup as Entity;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
use App\Service\LdapService;
|
||||
|
||||
class UserGroupSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
private function nine2ldap() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$this->ldap->addUserGroup($this->entity);
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
$this->ldap->delUserGroup($this->entity);
|
||||
}
|
||||
}
|
||||
}
|
126
src/EventListener/UserSubscriber.php
Normal file
126
src/EventListener/UserSubscriber.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\User as Entity;
|
||||
use App\Entity\UserGroup as UserGroup;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Service\LdapService;
|
||||
|
||||
class UserSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $entity;
|
||||
private $ldap;
|
||||
|
||||
public function __construct(EntityManagerInterface $em,LdapService $ldap)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ldap = $ldap;
|
||||
}
|
||||
|
||||
|
||||
public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::preUpdate,
|
||||
Events::postUpdate,
|
||||
Events::preRemove,
|
||||
Events::postRemove,
|
||||
];
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
|
||||
// Recherche du group tout le monde
|
||||
$group=$this->em->getRepository("App\Entity\Group")->find(-1);
|
||||
$usergroup=new UserGroup();
|
||||
$usergroup->setUser($this->entity);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
$usergroup->setRolegroup(0);
|
||||
|
||||
$this->em->persist($usergroup);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function preUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldap();
|
||||
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;
|
||||
|
||||
// Synchronisation nine2ldap
|
||||
$this->nine2ldapremove();
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->entity = $args->getObject();
|
||||
if (!$this->entity instanceof Entity) return;;
|
||||
}
|
||||
|
||||
private function nine2ldap() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
// On s'assure que la structure organisationnelle est présente
|
||||
$this->ldap->addOrganisations();
|
||||
|
||||
// Ajout / Modification dans annuaire
|
||||
$filter=str_replace("*",$this->entity->getUsername(),$this->ldap->getParameter("filteruser"));
|
||||
$attributes=$this->ldap->listAttributesNiveau02();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseuser"));
|
||||
if(empty($ldapentrys)) {
|
||||
$this->ldap->addUser($this->entity);
|
||||
}
|
||||
elseif($this->ldap->ismodifyUser($this->entity,$ldapentrys[0])) {
|
||||
$this->ldap->modifyUser($this->entity,$ldapentrys[0]["cn"]);
|
||||
}
|
||||
|
||||
// Mise à jour des niveaux du user
|
||||
$this->ldap->updateNiveauUser($this->entity);
|
||||
}
|
||||
}
|
||||
|
||||
private function nine2ldapremove() {
|
||||
if($this->ldap->isNine2Ldap()) {
|
||||
$filter=str_replace("*",$this->entity->getUsername(),$this->ldap->getParameter("filteruser"));
|
||||
$attributes=$this->ldap->listAttributesNiveau02();
|
||||
$ldapentrys=$this->ldap->search($filter,$attributes,$this->ldap->getParameter("baseuser"));
|
||||
if(!empty($ldapentrys)) {
|
||||
$this->ldap->deleteUser($this->entity);
|
||||
}
|
||||
|
||||
// Mise à jour des niveaux du user en forçant le détachement
|
||||
$this->ldap->updateNiveauUser($this->entity,true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user