notification et permission chg proprio groupe (ref #146)
This commit is contained in:
parent
977705c5fe
commit
0de395baee
|
@ -179,7 +179,9 @@ class GroupController extends Controller
|
|||
}
|
||||
else {
|
||||
$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
|
||||
if($fgproprio) {
|
||||
|
@ -570,7 +572,7 @@ class GroupController extends Controller
|
|||
"body_text"=>$text
|
||||
);
|
||||
$to = $user->getEmail();
|
||||
$from = $this->getParameter('noreply');;
|
||||
$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);
|
||||
|
@ -750,7 +752,7 @@ class GroupController extends Controller
|
|||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit",$access);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
|
@ -804,6 +806,8 @@ class GroupController extends Controller
|
|||
// Récupération de l'enregistrement courant
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$this->getData($id);
|
||||
$oldowner=$data->getOwner();
|
||||
|
||||
$this->canOwner($data,$access);
|
||||
|
||||
// Création du formulaire
|
||||
|
@ -822,7 +826,7 @@ class GroupController extends Controller
|
|||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
$this->getErrorForm($id,$form,$request,$data,"update",$access);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
|
@ -850,6 +854,23 @@ class GroupController extends Controller
|
|||
// Sinon on les génère
|
||||
$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
|
||||
return $this->redirectToRoute("cadoles_core_".$access."_group");
|
||||
}
|
||||
|
@ -901,7 +922,7 @@ class GroupController extends Controller
|
|||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"delete");
|
||||
$this->getErrorForm($id,$form,$request,$data,"delete",$access);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
|
@ -1163,6 +1184,11 @@ class GroupController extends Controller
|
|||
}
|
||||
$pages=$group->getPages();
|
||||
$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
|
||||
if($group->getCalendars()->isEmpty()) {
|
||||
|
@ -1179,6 +1205,14 @@ class GroupController extends Controller
|
|||
$em->persist($calendar);
|
||||
$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
|
||||
if($group->getBlogs()->isEmpty()) {
|
||||
|
@ -1191,6 +1225,14 @@ class GroupController extends Controller
|
|||
$em->persist($blog);
|
||||
$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
|
||||
if($group->getProjects()->isEmpty()) {
|
||||
|
@ -1203,6 +1245,14 @@ class GroupController extends Controller
|
|||
$em->persist($project);
|
||||
$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;
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode,$access) {
|
||||
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"));
|
||||
}
|
||||
|
||||
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()) {
|
||||
$this->get('session')->getFlashBag()->clear();
|
||||
$validator = $this->get('validator');
|
||||
|
|
|
@ -58,26 +58,28 @@ class GroupType extends AbstractType
|
|||
"attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false))
|
||||
]);
|
||||
|
||||
$builder->add('owner',
|
||||
Select2EntityType::class, array(
|
||||
'label' => "Propriétaire",
|
||||
'disabled' => ($options["mode"]=="delete"?true:false),
|
||||
"required" => false,
|
||||
'multiple' => false,
|
||||
'remote_route' => 'cadoles_core_config_user_ajax_selectlist',
|
||||
'class' => 'Cadoles\coreBundle\Entity\User',
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'username',
|
||||
'minimum_input_length' => 2,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000, // if 'cache' is true
|
||||
'language' => 'fr',
|
||||
'placeholder' => 'Selectionner un propriétaire',
|
||||
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
|
||||
));
|
||||
if($options["access"]=="config" || $options["mode"] == "update") {
|
||||
$builder->add('owner',
|
||||
Select2EntityType::class, array(
|
||||
'label' => "Propriétaire",
|
||||
'disabled' => ($options["mode"]=="delete"?true:false),
|
||||
"required" => false,
|
||||
'multiple' => false,
|
||||
'remote_route' => 'cadoles_core_'.$options["access"].'_user_ajax_selectlist',
|
||||
'class' => 'Cadoles\coreBundle\Entity\User',
|
||||
'primary_key' => 'id',
|
||||
'text_property' => 'username',
|
||||
'minimum_input_length' => 2,
|
||||
'page_limit' => 10,
|
||||
'allow_clear' => true,
|
||||
'delay' => 250,
|
||||
'cache' => false,
|
||||
'cache_timeout' => 60000, // if 'cache' is true
|
||||
'language' => 'fr',
|
||||
'placeholder' => 'Selectionner un propriétaire',
|
||||
'attr' => array("class" => "form-control", "style" => "margin-bottom:15px")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if($options["access"]=="config") {
|
||||
|
|
|
@ -286,6 +286,10 @@ cadoles_core_user_user_ajax_list:
|
|||
path: /user/user/ajax/list
|
||||
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:
|
||||
path: /user/users
|
||||
defaults: { _controller: CadolesCoreBundle:User:list, access: user }
|
||||
|
|
Loading…
Reference in New Issue