controle d'unicité de rattachement à un groupe (ref #160)

This commit is contained in:
afornerot 2020-06-18 09:57:05 +02:00
parent 9f6024049b
commit fcbf0ab4ad
4 changed files with 33 additions and 22 deletions

View File

@ -46,6 +46,7 @@ class ScriptCommand extends Command
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$script=$this->em->getRepository("CadolesCoreBundle:Script")->findOneBy(["name"=>"visibletrue"]);
if(!$script) {
$this->writelnred("== SCRIPT = visibletrue");

View File

@ -593,10 +593,15 @@ class SynchroCommand extends Command
$attrs["cadolesMember"]=array();
foreach($data->getUsers() as $usergroupe) {
if(!in_array($usergroupe->getUser()->getUsername(), $attrs["memberuid"])) {
array_push($attrs["memberuid"],$usergroupe->getUser()->getUsername());
array_push($attrs["cadolesMember"],$this->ldap->getUserDN($usergroupe->getUser()));
$this->writeln(' > '.$usergroupe->getUser()->getUsername());
}
else {
$this->writelnred(' > EXIST'.$usergroupe->getUser()->getUsername());
}
}
if(!$simulate) $this->ldap->ldapModify($dn, $attrs);
}
}

View File

@ -400,8 +400,9 @@ class UserController extends Controller
foreach($lstgroups as $idgroup) {
$group=$em->getRepository("CadolesCoreBundle:Group")->find($idgroup);
$usergroup=$em->getRepository('CadolesCoreBundle:UserGroup')->findBy(["user"=>$data,"group"=>$group]);
if(!$usergroup) {
$key = Uuid::uuid4();
$usergroup= new UserGroup();
$usergroup->setUser($data);
$datagroup = $group;
@ -409,6 +410,7 @@ class UserController extends Controller
$usergroup->setKeyvalue($key);
$em->persist($usergroup);
$em->flush();
}
// Notification message
$message="Inscription de l'utilisateur<br>".$data->getLastname()." ".$data->getFirstname()."<br>Par ".$this->getUser()->getLastname()." ".$this->getUser()->getFirstname();
@ -540,6 +542,8 @@ class UserController extends Controller
foreach($addgroups as $idgroup) {
$group=$em->getRepository("CadolesCoreBundle:Group")->find($idgroup);
$usergroup=$em->getRepository('CadolesCoreBundle:UserGroup')->findBy(["user"=>$data,"group"=>$group]);
if(!$usergroup) {
$key = Uuid::uuid4();
$usergroup= new UserGroup();
@ -549,6 +553,7 @@ class UserController extends Controller
$usergroup->setKeyvalue($key);
$em->persist($usergroup);
$em->flush();
}
// notification message
$message="Inscription de l'utilisateur<br>".$data->getLastname()." ".$data->getFirstname()."<br>Par ".$this->getUser()->getLastname()." ".$this->getUser()->getFirstname();

View File

@ -9,7 +9,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="usergroupe")
* @ORM\Table(name="usergroupe",uniqueConstraints={@ORM\UniqueConstraint(columns={"user_id", "group_id"})})
* @ORM\HasLifecycleCallbacks()
*
* @UniqueEntity(fields={"user", "group"}, message="Cette liaison existe déjà !")