From 500362ea3fd2c9ce16745ad7e636435f61e02ba1 Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 2 Jan 2020 13:57:15 +0100 Subject: [PATCH 1/2] =?UTF-8?q?invitation=20=C3=A0=20un=20groupe=20(fixes?= =?UTF-8?q?=20#67)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreBundle/Command/data/core-init-01.sql | 2 +- .../CoreBundle/Controller/MailController.php | 79 +++++++++++++++++++ .../Controller/RegistrationController.php | 28 ++++++- .../CoreBundle/Entity/Registration.php | 29 +++++++ .../src/Cadoles/CoreBundle/Form/MailType.php | 63 +++++++++++++++ .../CoreBundle/Resources/config/routing.yml | 6 ++ .../Resources/views/Group/users.html.twig | 12 ++- .../Resources/views/Mail/mail.html.twig | 54 +++++++++++++ .../Cadoles/PortalBundle/Entity/Widget.php | 2 +- 9 files changed, 271 insertions(+), 4 deletions(-) create mode 100755 src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/MailController.php create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Form/MailType.php create mode 100644 src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Mail/mail.html.twig diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql index 949a0a76..d1bff3f9 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql @@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES (-100, 'DRAAF', '130007107'); INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES -(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}Kvz21GjhkryG4l7EKniMJzVfwDufa+eI +(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}o85pP7Lzbqw8J8wr8jlgxl8NFvCcJlve ', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple'); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/MailController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/MailController.php new file mode 100755 index 00000000..8ac3c859 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/MailController.php @@ -0,0 +1,79 @@ +getDoctrine()->getManager(); + $group = $em->getRepository("CadolesCoreBundle:Group")->find($id); + if (!$group) { + throw $this->createNotFoundException('Unable to find '.$this->labeldata); + } + + // Création du formulaire + $form = $this->createForm(MailType::class); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sujet + $subject = $this->get('session')->get('appname')." : Invitation au groupe de travail ".$group->getLabel(); + + // Sujet + $url = $this->generateUrl('cadoles_core_registration',[], UrlGeneratorInterface::ABSOLUTE_URL)."?group=".$group->getId(); + $message = "Bonjour,

Vous êtes invité à participer au groupe de travail = ".$group->getLabel()."

"; + $message.= "Pour cela vous devez vous inscrire sur ".$this->get('session')->get('appname')." en suivant le lien suivant
"; + $message.= "$url

"; + $message.= "Une foi le processus d'inscription complété, vous serez automatiquement rattaché à notre groupe de travail

"; + $message.= "Cordialement
"; + $message.= $this->getUser()->getFirstname()." ".$this->getUser()->getLastname(); + + // To close ? + $closed = false; + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $closed = true; + + + $destinataires=$form->get("destinataire")->getData(); + $to=explode(";",$destinataires); + $text=$form->get("message")->getData(); + $subject=$form->get("subject")->getData(); + $template="template"; + $mail_params=array( + "subject" => $subject, + "body_html"=>nl2br($text), + "body_text"=>$text + ); + $from = $this->getUser()->getEmail(); + $fromName = $this->getUser()->getFirstname()." ".$this->getUser()->getLastname(); + $message = $this->container->get('cadoles.core.service.mail'); + $message->sendEmail($template, $mail_params, $to, $from, $fromName); + } + + return $this->render('CadolesCoreBundle:Mail:mail.html.twig',[ + 'useheader' => false, + 'usemenu' => false, + 'usesidebar' => false, + 'closed' => $closed, + 'subject' => $subject, + 'message' => $message, + 'form' => $form->createView() + ]); + } + +} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php index fcad3d7b..515ca626 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php @@ -13,6 +13,7 @@ use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Cadoles\CoreBundle\Entity\User; +use Cadoles\CoreBundle\Entity\Usergroup; use Cadoles\CoreBundle\Entity\Registration; use Cadoles\CoreBundle\Form\RegistrationType; use Cadoles\CoreBundle\Form\UserType; @@ -176,6 +177,8 @@ class RegistrationController extends Controller $moderegistration = $this->getParameter('moderegistration'); $masteridentity = $this->getParameter('masteridentity'); + $groupid = $request->query->get('group'); + if($moderegistration=="none"||$masteridentity!="SQL") throw $this->createNotFoundException('Permission denied'); @@ -200,6 +203,9 @@ class RegistrationController extends Controller $data = $form->getData(); + // On enregistre l'invitation à un groupe dans l'inscription + $data->setGroupid($groupid); + $appname = $this->get('session')->get('appname'); $noreply = $this->getParameter('noreply'); $keyterm = $this->getParameter('keyterm'); @@ -506,11 +512,31 @@ class RegistrationController extends Controller $user->setAuthlevel("simple"); $user->setBelongingpopulation("agent"); - // Sauvegarde $em->persist($user); $em->flush(); + // Si invitation à un groupe : on le rattache directement à ce groupe + $groupid=$data[0]->getGroupid(); + $userid=$user->getId(); + if($groupid) { + $group=$em->getRepository("CadolesCoreBundle:Group")->find($groupid); + if($group) { + $key = Uuid::uuid4(); + $usergroup=new Usergroup; + $user=$em->getRepository("CadolesCoreBundle:User")->find($userid); + $usergroup->setUser($user); + $usergroup->setGroup($group); + $usergroup->setKeyvalue($key); + $em->persist($usergroup); + $em->flush(); + + // Notification message + $message="Inscription de l'utilisateur
".$user->getLastname()." ".$user->getFirstname()."
Inscription via inviation"; + $websocket = $this->container->get('cadoles.websocket.pushmessage')->send($key->toString(),$userid,$groupid,$message); + } + } + $em->remove($data[0]); $em->flush(); } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php index 71dae38c..585473b2 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php @@ -123,6 +123,11 @@ class Registration implements UserInterface, \Serializable */ private $position; + /** + * @ORM\Column(type="integer", length=60, nullable=true) + */ + private $groupid; + /** * @ORM\ManyToOne(targetEntity="Country", inversedBy="registrations") * @ORM\JoinColumn(nullable=true) @@ -709,4 +714,28 @@ class Registration implements UserInterface, \Serializable { return $this->niveau02; } + + /** + * Set groupid + * + * @param integer $groupid + * + * @return Registration + */ + public function setGroupid($groupid) + { + $this->groupid = $groupid; + + return $this; + } + + /** + * Get groupid + * + * @return integer + */ + public function getGroupid() + { + return $this->groupid; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/MailType.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/MailType.php new file mode 100644 index 00000000..2b29c948 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/MailType.php @@ -0,0 +1,63 @@ +add('submit', + SubmitType::class, array( + "label" => "Envoyer l'inviation", + "attr" => array("class" => "btn btn-success") + ) + ); + + $builder->add('destinataire', + TextType::class, array( + "label" =>"Destinataires", + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px"), + "mapped" => false + ) + ); + + $builder->add('subject', + TextType::class, array( + "label" =>"Sujet", + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px"), + "mapped" => false + ) + ); + + $builder + ->add("message",CKEditorType::class,[ + 'config_name' => 'small_config', + 'label' => "Message", + 'mapped'=> false, + 'required' => false, + 'attr' => array("class" => "form-control", "style" => "margin-bottom:15px"), + 'config' => ["height" => "150px",'filebrowserUploadRoute' => 'cadoles_portal_user_pagewidget_upload'] + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + + } +} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 904d8405..f8db5ef1 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -132,6 +132,12 @@ cadoles_core_config: defaults: { _controller: CadolesCoreBundle:Config:home } +#== Mail ================================================================================================================= +cadoles_core_mail_invitationgroup: + path: /user/mail/invitationgroup/{id} + defaults: { _controller: CadolesCoreBundle:Mail:invitationgroup } + + #== Commun Config Commun ================================================================================================= cadoles_core_config_commun: path: /config/commun diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Group/users.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Group/users.html.twig index 544a4e29..c2ff3e51 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Group/users.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Group/users.html.twig @@ -4,6 +4,9 @@

Gestion des Utilisateurs

Groupe = {{ group.label }}

Fermer + {% if moderegistration!="none" and masteridentity=="SQL"%} + Inviter des personnes non inscrites + {%endif%}

@@ -148,5 +151,12 @@ "user": id, } }); - } + } + + function showMail() { + $("#mymodal").find(".modal-title").html("INVITATION"); + var url="{{ path('cadoles_core_mail_invitationgroup',{id:group.id}) }}"; + $("#mymodal").find("#framemodal").attr("src",url); + $("#mymodal").modal().show(); + } {% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Mail/mail.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Mail/mail.html.twig new file mode 100644 index 00000000..07cfd41f --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Mail/mail.html.twig @@ -0,0 +1,54 @@ +{% extends '@CadolesCore/base.html.twig' %} + +{% block pagewrapper %} +{{ form_start(form) }} + {{ form_widget(form.submit) }} Annuler + +

+ + {% if app.session.flashbag.has('error') %} +
+ Erreur
+ {% for flashMessage in app.session.flashbag.get('error') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {% if app.session.flashbag.has('notice') %} +
+ Information
+ {% for flashMessage in app.session.flashbag.get('notice') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {{ form_row(form.destinataire) }} +
+ Séparer les adresses mails par des ; +
+ + {{ form_row(form.subject) }} + {{ form_row(form.message) }} + +{{ form_end(form) }} +{% endblock %} + +{% block localjavascript %} + $(document).ready(function() { + {% if closed %} + closeModal(); + {% else %} + $("#mail_subject").val("{{ subject }}"); + $("#mail_message").val("{{ message | raw }}"); + + $("#mail_destinataire").focus(); + {% endif %} + }); + + function closeModal() { + window.parent.$("#mymodal").modal('hide');; + } + +{% endblock %} \ No newline at end of file diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Widget.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Widget.php index 2edcfe89..e9f5d62c 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Widget.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Widget.php @@ -133,7 +133,7 @@ class Widget * @var ArrayCollection $pagewidgets * @var Order * - * @ORM\OneToMany(targetEntity="Pagewidget", mappedBy="widget", cascade={"persist"}, orphanRemoval=false) + * @ORM\OneToMany(targetEntity="Pagewidget", mappedBy="widget", cascade={"persist"}, orphanRemoval=true) */ private $pagewidgets; From ec17681560019a371309ad4c11e32dc798adc64d Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 2 Jan 2020 14:36:26 +0100 Subject: [PATCH 2/2] rester sur la page sur un F5 (fixes #70) --- .../PortalBundle/Resources/views/Page/pages.html.twig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/pages.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/pages.html.twig index bc0124de..dc88fd38 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/pages.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/pages.html.twig @@ -219,7 +219,6 @@ {% block localjavascript %} var idpage; - $('document').ready(function(){ {% for page in pagesadmin %} {% if page.id==entity.id %} @@ -241,6 +240,7 @@ {% endfor %} {% endfor %} + // Rendre les pages user déplacable $("#pagesuser").sortable({ axis: "x", @@ -369,6 +369,8 @@ // Sauvegarder la page en cours idpage=id; + + // Cacher toutes les pages $(".pageframereload").remove(); $(".pageframe").hide(); @@ -382,6 +384,10 @@ url=url.replace('yy',usage); url=url.replace('zz',groupid); + passurl="{{ path('cadoles_core_home',{id:'xx'}) }}"; + passurl=passurl.replace('xx',id); + history.pushState('data to be passed', 'Title of the page', passurl); + // Si force le rechargement et frame existante on la détruit if(forcereload&&$("#page-"+id).length) $("#page-"+id).remove();