From c6678e8e0215bd04247a122dbd6b8b7ba9d88d51 Mon Sep 17 00:00:00 2001 From: Arnaud Fornerot Date: Tue, 25 Oct 2022 15:42:31 +0200 Subject: [PATCH] fix: validator --- src/Entity/Group.php | 3 ++ src/Service/LdapService.php | 32 ++++++++++------- src/Validator/Groupunique.php | 17 +++++++++ src/Validator/GroupuniqueValidator.php | 43 +++++++++++++++++++++++ src/Validator/Niveau01unique.php | 3 ++ src/Validator/Niveau01uniqueValidator.php | 14 ++++++-- src/Validator/Niveau02unique.php | 3 ++ src/Validator/Niveau02uniqueValidator.php | 14 ++++++-- src/Validator/Niveau03unique.php | 17 +++++++++ src/Validator/Niveau03uniqueValidator.php | 43 +++++++++++++++++++++++ src/Validator/Niveau04unique.php | 17 +++++++++ src/Validator/Niveau04uniqueValidator.php | 43 +++++++++++++++++++++++ templates/Niveau03/edit.html.twig | 2 +- templates/Niveau04/edit.html.twig | 2 +- 14 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 src/Validator/Groupunique.php create mode 100644 src/Validator/GroupuniqueValidator.php create mode 100644 src/Validator/Niveau03unique.php create mode 100644 src/Validator/Niveau03uniqueValidator.php create mode 100644 src/Validator/Niveau04unique.php create mode 100644 src/Validator/Niveau04uniqueValidator.php diff --git a/src/Entity/Group.php b/src/Entity/Group.php index e0f9542..f76a812 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Validator; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -25,6 +26,8 @@ class Group private $id; /** + * @Validator\Grouplabel() + * @Validator\Groupunique() * @ORM\Column(type="string", length=250, unique=true) */ private $label; diff --git a/src/Service/LdapService.php b/src/Service/LdapService.php index 66186be..c3cfae2 100644 --- a/src/Service/LdapService.php +++ b/src/Service/LdapService.php @@ -193,22 +193,28 @@ class LdapService { $connection = $this->connect(); if (false == $recursive) { - $removed = ldap_delete($connection, $dn); - if (!$removed) { - $this->ldapError(); - } - } else { - // searching for sub entries - $sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']); - $info = ldap_get_entries($connection, $sr); - for ($i = 0; $i < $info['count']; ++$i) { - $result = $this->deleteByDN($info[$i]['dn'], $recursive); - if (!$result) { - return $result; + $ldapentrys = $this->searchdn($dn); + if (!empty($ldapentrys)) { + $removed = ldap_delete($connection, $dn); + if (!$removed) { + $this->ldapError(); } } + } else { + $ldapentrys = $this->searchdn($dn); + if (!empty($ldapentrys)) { + // searching for sub entries + $sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']); + $info = ldap_get_entries($connection, $sr); + for ($i = 0; $i < $info['count']; ++$i) { + $result = $this->deleteByDN($info[$i]['dn'], $recursive); + if (!$result) { + return $result; + } + } - return ldap_delete($connection, $dn); + return ldap_delete($connection, $dn); + } } } diff --git a/src/Validator/Groupunique.php b/src/Validator/Groupunique.php new file mode 100644 index 0000000..4f9b9aa --- /dev/null +++ b/src/Validator/Groupunique.php @@ -0,0 +1,17 @@ +em = $em; + } + + public function validate($value, Constraint $constraint) + { + $niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau01); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau02); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau03); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau04); + } + } +} diff --git a/src/Validator/Niveau01unique.php b/src/Validator/Niveau01unique.php index 94a1b64..45ca81e 100644 --- a/src/Validator/Niveau01unique.php +++ b/src/Validator/Niveau01unique.php @@ -10,5 +10,8 @@ use Symfony\Component\Validator\Constraint; class Niveau01unique extends Constraint { public $messagegroup = 'Un groupe utilise déjà ce label'; + public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label'; public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label'; + public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label'; + public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label'; } diff --git a/src/Validator/Niveau01uniqueValidator.php b/src/Validator/Niveau01uniqueValidator.php index bcdde00..7ebd1b4 100644 --- a/src/Validator/Niveau01uniqueValidator.php +++ b/src/Validator/Niveau01uniqueValidator.php @@ -25,9 +25,19 @@ class Niveau01uniqueValidator extends ConstraintValidator $this->context->addViolation($constraint->messagegroup); } - $niveau02 = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]); - if ($niveau02) { + $niveau = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]); + if ($niveau) { $this->context->addViolation($constraint->messageniveau02); } + + $niveau = $this->em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau03); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau04); + } } } diff --git a/src/Validator/Niveau02unique.php b/src/Validator/Niveau02unique.php index cd4fb5f..60e5bf2 100644 --- a/src/Validator/Niveau02unique.php +++ b/src/Validator/Niveau02unique.php @@ -11,4 +11,7 @@ class Niveau02unique extends Constraint { public $messagegroup = 'Un groupe utilise déjà ce label'; public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label'; + public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label'; + public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label'; + public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label'; } diff --git a/src/Validator/Niveau02uniqueValidator.php b/src/Validator/Niveau02uniqueValidator.php index 6153b90..1821e05 100644 --- a/src/Validator/Niveau02uniqueValidator.php +++ b/src/Validator/Niveau02uniqueValidator.php @@ -25,9 +25,19 @@ class Niveau02uniqueValidator extends ConstraintValidator $this->context->addViolation($constraint->messagegroup); } - $niveau02 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]); - if ($niveau02) { + $niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]); + if ($niveau) { $this->context->addViolation($constraint->messageniveau01); } + + $niveau = $this->em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau03); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau04); + } } } diff --git a/src/Validator/Niveau03unique.php b/src/Validator/Niveau03unique.php new file mode 100644 index 0000000..7943c26 --- /dev/null +++ b/src/Validator/Niveau03unique.php @@ -0,0 +1,17 @@ +em = $em; + } + + public function validate($value, Constraint $constraint) + { + $group = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $value]); + if ($group) { + $this->context->addViolation($constraint->messagegroup); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau01); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau02); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau04); + } + } +} diff --git a/src/Validator/Niveau04unique.php b/src/Validator/Niveau04unique.php new file mode 100644 index 0000000..bdcf226 --- /dev/null +++ b/src/Validator/Niveau04unique.php @@ -0,0 +1,17 @@ +em = $em; + } + + public function validate($value, Constraint $constraint) + { + $group = $this->em->getRepository("App\Entity\Group")->findOneBy(['label' => $value]); + if ($group) { + $this->context->addViolation($constraint->messagegroup); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau01); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau02); + } + + $niveau = $this->em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $value]); + if ($niveau) { + $this->context->addViolation($constraint->messageniveau04); + } + } +} diff --git a/templates/Niveau03/edit.html.twig b/templates/Niveau03/edit.html.twig index dbca0f5..0c2bc86 100755 --- a/templates/Niveau03/edit.html.twig +++ b/templates/Niveau03/edit.html.twig @@ -66,7 +66,7 @@ {% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
- {{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }} + {{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau03",entityid:niveau03.id})) }}
{% endif %} {{ form_end(form) }} diff --git a/templates/Niveau04/edit.html.twig b/templates/Niveau04/edit.html.twig index f3fcaad..f1f48f1 100755 --- a/templates/Niveau04/edit.html.twig +++ b/templates/Niveau04/edit.html.twig @@ -67,7 +67,7 @@ {% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
- {{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }} + {{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau04",entityid:niveau04.id})) }}
{% endif %} {{ form_end(form) }} -- 2.17.1