fix: validator
Cadoles/nineskeletor/pipeline/pr-master There was a failure building this commit Details
Cadoles/nineskeletor/pipeline/head There was a failure building this commit Details

This commit is contained in:
Arnaud Fornerot 2022-10-25 15:42:31 +02:00
parent 19fa75e2eb
commit c6678e8e02
14 changed files with 234 additions and 19 deletions

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Groupunique 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';
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Validator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class GroupuniqueValidator extends ConstraintValidator
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->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);
}
}
}

View File

@ -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';
}

View File

@ -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);
}
}
}

View File

@ -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';
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Niveau03unique 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';
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Validator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class Niveau03uniqueValidator extends ConstraintValidator
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->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);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Niveau04unique 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';
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Validator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class Niveau04uniqueValidator extends ConstraintValidator
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->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);
}
}
}

View File

@ -66,7 +66,7 @@
{% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
<div class="float-end" style="width:700px;max-width:100%">
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }}
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau03",entityid:niveau03.id})) }}
</div>
{% endif %}
{{ form_end(form) }}

View File

@ -67,7 +67,7 @@
{% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
<div class="float-end" style="width:700px;max-width:100%">
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }}
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau04",entityid:niveau04.id})) }}
</div>
{% endif %}
{{ form_end(form) }}