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,9 +593,14 @@ class SynchroCommand extends Command
$attrs["cadolesMember"]=array();
foreach($data->getUsers() as $usergroupe) {
array_push($attrs["memberuid"],$usergroupe->getUser()->getUsername());
array_push($attrs["cadolesMember"],$this->ldap->getUserDN($usergroupe->getUser()));
$this->writeln(' > '.$usergroupe->getUser()->getUsername());
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,15 +400,17 @@ class UserController extends Controller
foreach($lstgroups as $idgroup) {
$group=$em->getRepository("CadolesCoreBundle:Group")->find($idgroup);
$key = Uuid::uuid4();
$usergroup= new UserGroup();
$usergroup->setUser($data);
$datagroup = $group;
$usergroup->setGroup($datagroup);
$usergroup->setKeyvalue($key);
$em->persist($usergroup);
$em->flush();
$usergroup=$em->getRepository('CadolesCoreBundle:UserGroup')->findBy(["user"=>$data,"group"=>$group]);
if(!$usergroup) {
$key = Uuid::uuid4();
$usergroup= new UserGroup();
$usergroup->setUser($data);
$datagroup = $group;
$usergroup->setGroup($datagroup);
$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,16 +542,19 @@ class UserController extends Controller
foreach($addgroups as $idgroup) {
$group=$em->getRepository("CadolesCoreBundle:Group")->find($idgroup);
$key = Uuid::uuid4();
$usergroup= new UserGroup();
$usergroup->setUser($data);
$datagroup = $group;
$usergroup->setGroup($datagroup);
$usergroup->setKeyvalue($key);
$em->persist($usergroup);
$em->flush();
$usergroup=$em->getRepository('CadolesCoreBundle:UserGroup')->findBy(["user"=>$data,"group"=>$group]);
if(!$usergroup) {
$key = Uuid::uuid4();
$usergroup= new UserGroup();
$usergroup->setUser($data);
$datagroup = $group;
$usergroup->setGroup($datagroup);
$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();
$websocket = $this->container->get('cadoles.websocket.pushmessage')->send($key->toString(),$id,$idgroup,$message);

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à !")