notification et permission chg proprio groupe (ref #146)

This commit is contained in:
afornerot 2020-06-22 13:21:47 +02:00
parent 977705c5fe
commit 0de395baee
3 changed files with 88 additions and 28 deletions

View File

@ -179,7 +179,9 @@ class GroupController extends Controller
} }
else { else {
$fgproprio=($user==$data->getOwner()); $fgproprio=($user==$data->getOwner());
$fgmanager=$this->getDoctrine()->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$data])->getFgmanager(); $fgmanager=false;
$usergroup=$this->getDoctrine()->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$data]);
if($usergroup) $fgmanager=$usergroup->getFgmanager();
// Modification possible uniquement si l'utilisateur est propriétaire du groupe // Modification possible uniquement si l'utilisateur est propriétaire du groupe
if($fgproprio) { if($fgproprio) {
@ -570,7 +572,7 @@ class GroupController extends Controller
"body_text"=>$text "body_text"=>$text
); );
$to = $user->getEmail(); $to = $user->getEmail();
$from = $this->getParameter('noreply');; $from = $this->getParameter('noreply');
$fromName = $this->get('session')->get('appname'); $fromName = $this->get('session')->get('appname');
$message = $this->container->get('cadoles.core.service.mail'); $message = $this->container->get('cadoles.core.service.mail');
$message->sendEmail($template, $mail_params, $to, $from, $fromName); $message->sendEmail($template, $mail_params, $to, $from, $fromName);
@ -750,7 +752,7 @@ class GroupController extends Controller
$form->handleRequest($request); $form->handleRequest($request);
// Sur erreur // Sur erreur
$this->getErrorForm(null,$form,$request,$data,"submit"); $this->getErrorForm(null,$form,$request,$data,"submit",$access);
// Sur validation // Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) { if ($form->get('submit')->isClicked() && $form->isValid()) {
@ -804,6 +806,8 @@ class GroupController extends Controller
// Récupération de l'enregistrement courant // Récupération de l'enregistrement courant
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$data=$this->getData($id); $data=$this->getData($id);
$oldowner=$data->getOwner();
$this->canOwner($data,$access); $this->canOwner($data,$access);
// Création du formulaire // Création du formulaire
@ -822,7 +826,7 @@ class GroupController extends Controller
$form->handleRequest($request); $form->handleRequest($request);
// Sur erreur // Sur erreur
$this->getErrorForm($id,$form,$request,$data,"update"); $this->getErrorForm($id,$form,$request,$data,"update",$access);
// Sur validation // Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) { if ($form->get('submit')->isClicked() && $form->isValid()) {
@ -850,6 +854,23 @@ class GroupController extends Controller
// Sinon on les génère // Sinon on les génère
$this->ctrlFgcanshare($data,$access); $this->ctrlFgcanshare($data,$access);
// Si le propriétaire change de main on prévient le nouveau propriétaire
if($data->getOwner()&&$data->getOwner()!=$oldowner) {
// Email à destination de l'inscript pour le prévenir qu'un administrateur doit valider
$text="On vient de vous tranférer la propriété du groupe ".$data->getLabel();
$template="template";
$mail_params=array(
"subject" => $this->get('session')->get('appname')." : Transfert de groupe",
"body_html"=>nl2br($text),
"body_text"=>$text
);
$to = $data->getOwner()->getEmail();
$from = $this->getParameter('noreply');
$fromName = $this->get('session')->get('appname');
$message = $this->container->get('cadoles.core.service.mail');
$message->sendEmail($template, $mail_params, $to, $from, $fromName);
}
// Retour à la liste // Retour à la liste
return $this->redirectToRoute("cadoles_core_".$access."_group"); return $this->redirectToRoute("cadoles_core_".$access."_group");
} }
@ -901,7 +922,7 @@ class GroupController extends Controller
$form->handleRequest($request); $form->handleRequest($request);
// Sur erreur // Sur erreur
$this->getErrorForm($id,$form,$request,$data,"delete"); $this->getErrorForm($id,$form,$request,$data,"delete",$access);
// Sur validation // Sur validation
if ($form->get('submit')->isClicked() && $form->isValid()) { if ($form->get('submit')->isClicked() && $form->isValid()) {
@ -1163,6 +1184,11 @@ class GroupController extends Controller
} }
$pages=$group->getPages(); $pages=$group->getPages();
$this->idpage=$pages[0]->getId(); $this->idpage=$pages[0]->getId();
if($pages[0]->getName()!=$group->getLabel()) {
$pages[0]->setName($group->getLabel());
$em->persist($pages[0]);
$em->flush();
}
// On regarde s'il a au moins un calendrier // On regarde s'il a au moins un calendrier
if($group->getCalendars()->isEmpty()) { if($group->getCalendars()->isEmpty()) {
@ -1179,6 +1205,14 @@ class GroupController extends Controller
$em->persist($calendar); $em->persist($calendar);
$em->flush(); $em->flush();
} }
else {
$calendars=$group->getCalendars();
if($calendars[0]->getName()!=$group->getLabel()) {
$calendars[0]->setName($group->getLabel());
$em->persist($calendars[0]);
$em->flush();
}
}
// On regarde s'il a au moins un blog // On regarde s'il a au moins un blog
if($group->getBlogs()->isEmpty()) { if($group->getBlogs()->isEmpty()) {
@ -1190,7 +1224,15 @@ class GroupController extends Controller
$em->persist($blog); $em->persist($blog);
$em->flush(); $em->flush();
} }
else {
$blogs=$group->getBlogs();
if($blogs[0]->getName()!=$group->getLabel()) {
$blogs[0]->setName($group->getLabel());
$em->persist($blogs[0]);
$em->flush();
}
}
// On regarde s'il a au moins un project // On regarde s'il a au moins un project
if($group->getProjects()->isEmpty()) { if($group->getProjects()->isEmpty()) {
@ -1202,7 +1244,15 @@ class GroupController extends Controller
$em->persist($project); $em->persist($project);
$em->flush(); $em->flush();
} }
else {
$projects=$group->getProjects();
if($projects[0]->getName()!=$group->getLabel()) {
$projects[0]->setName($group->getLabel());
$em->persist($projects[0]);
$em->flush();
}
}
} }
} }
@ -1239,7 +1289,7 @@ class GroupController extends Controller
else return true; else return true;
} }
protected function getErrorForm($id,$form,$request,$data,$mode) { protected function getErrorForm($id,$form,$request,$data,$mode,$access) {
if ($form->get('submit')->isClicked()&&$mode=="delete") { if ($form->get('submit')->isClicked()&&$mode=="delete") {
} }
@ -1262,6 +1312,10 @@ class GroupController extends Controller
$form->addError(new FormError("Un groupe de travail doit avoir un modèle de page d'accueil")); $form->addError(new FormError("Un groupe de travail doit avoir un modèle de page d'accueil"));
} }
if ($form->get('submit')->isClicked() && $mode=="update" && $access=="user") {
if(!$data->getOwner()) $form->addError(new FormError('Le propriétaire du groupe est obligatoire'));
}
if ($form->get('submit')->isClicked() && !$form->isValid()) { if ($form->get('submit')->isClicked() && !$form->isValid()) {
$this->get('session')->getFlashBag()->clear(); $this->get('session')->getFlashBag()->clear();
$validator = $this->get('validator'); $validator = $this->get('validator');

View File

@ -58,26 +58,28 @@ class GroupType extends AbstractType
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false)) "attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false))
]); ]);
$builder->add('owner', if($options["access"]=="config" || $options["mode"] == "update") {
Select2EntityType::class, array( $builder->add('owner',
'label' => "Propriétaire", Select2EntityType::class, array(
'disabled' => ($options["mode"]=="delete"?true:false), 'label' => "Propriétaire",
"required" => false, 'disabled' => ($options["mode"]=="delete"?true:false),
'multiple' => false, "required" => false,
'remote_route' => 'cadoles_core_config_user_ajax_selectlist', 'multiple' => false,
'class' => 'Cadoles\coreBundle\Entity\User', 'remote_route' => 'cadoles_core_'.$options["access"].'_user_ajax_selectlist',
'primary_key' => 'id', 'class' => 'Cadoles\coreBundle\Entity\User',
'text_property' => 'username', 'primary_key' => 'id',
'minimum_input_length' => 2, 'text_property' => 'username',
'page_limit' => 10, 'minimum_input_length' => 2,
'allow_clear' => true, 'page_limit' => 10,
'delay' => 250, 'allow_clear' => true,
'cache' => false, 'delay' => 250,
'cache_timeout' => 60000, // if 'cache' is true 'cache' => false,
'language' => 'fr', 'cache_timeout' => 60000, // if 'cache' is true
'placeholder' => 'Selectionner un propriétaire', 'language' => 'fr',
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px") 'placeholder' => 'Selectionner un propriétaire',
)); 'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
));
}
} }
if($options["access"]=="config") { if($options["access"]=="config") {

View File

@ -286,6 +286,10 @@ cadoles_core_user_user_ajax_list:
path: /user/user/ajax/list path: /user/user/ajax/list
defaults: { _controller: CadolesCoreBundle:User:ajaxlist, access: user } defaults: { _controller: CadolesCoreBundle:User:ajaxlist, access: user }
cadoles_core_user_user_ajax_selectlist:
path: /user/user/ajax/selectlist
defaults: { _controller: CadolesCoreBundle:User:selectlist, access: user }
cadoles_core_user_users: cadoles_core_user_users:
path: /user/users path: /user/users
defaults: { _controller: CadolesCoreBundle:User:list, access: user } defaults: { _controller: CadolesCoreBundle:User:list, access: user }