From 511e1241d221d6f386e6e5b101baf33a383cc40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Nenad=C3=A1l?= Date: Thu, 8 Dec 2016 16:06:19 +0100 Subject: [PATCH] BAP-12183: Incorrect showing of Emails in Activities tree (#5059) * BAP-12183: Incorrect showing of Emails in Activities tree * BAP-12183: Incorrect showing of Emails in Activities tree --- .../EmailBundle/Controller/EmailController.php | 14 ++++++++++---- src/Oro/Bundle/EmailBundle/Mailer/Processor.php | 11 +++++++++-- .../Resources/views/Email/dialog/view.html.twig | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Oro/Bundle/EmailBundle/Controller/EmailController.php b/src/Oro/Bundle/EmailBundle/Controller/EmailController.php index 5f6f5b71e91..9ae58f7893d 100644 --- a/src/Oro/Bundle/EmailBundle/Controller/EmailController.php +++ b/src/Oro/Bundle/EmailBundle/Controller/EmailController.php @@ -189,10 +189,16 @@ public function viewThreadAction(Email $entity) */ public function threadWidgetAction(Email $entity) { - $emails = $this->get('oro_email.email.thread.provider')->getThreadEmails( - $this->get('doctrine')->getManager(), - $entity - ); + $emails = []; + if ($this->getRequest()->get('showSingleEmail', false)) { + $emails[] = $entity; + } else { + $emails = $this->get('oro_email.email.thread.provider')->getThreadEmails( + $this->get('doctrine')->getManager(), + $entity + ); + } + $emails = array_filter($emails, function ($email) { return $this->get('security.context')->isGranted('VIEW', $email); }); diff --git a/src/Oro/Bundle/EmailBundle/Mailer/Processor.php b/src/Oro/Bundle/EmailBundle/Mailer/Processor.php index 84ec332ef6b..c5115128a37 100644 --- a/src/Oro/Bundle/EmailBundle/Mailer/Processor.php +++ b/src/Oro/Bundle/EmailBundle/Mailer/Processor.php @@ -210,10 +210,17 @@ public function processSend($message, $emailOrigin) $this->mailer->prepareSmtpTransport($emailOrigin); } } - + $messageId = $message->getId(); if (!$this->mailer->send($message)) { throw new \Swift_SwiftException('An email was not delivered.'); } + + /** + * We expect message->getId() to be id of the sent message later, + * but sending of the message generates new id after it's sent + * (https://github.com/swiftmailer/swiftmailer/issues/335) + */ + $message->setId($messageId); } /** @@ -468,7 +475,7 @@ protected function prepareMessage(EmailModel $model, $parentMessageId, $messageD */ protected function prepareEmailUser(EmailModel $model, $origin, $message, $messageDate, $parentMessageId) { - $messageId = '<' . $message->generateId() . '>'; + $messageId = '<' . $message->getId() . '>'; $emailUser = $this->createEmailUser($model, $messageDate, $origin); if ($origin) { $emailUser->addFolder($this->getFolder($model->getFrom(), $origin)); diff --git a/src/Oro/Bundle/EmailBundle/Resources/views/Email/dialog/view.html.twig b/src/Oro/Bundle/EmailBundle/Resources/views/Email/dialog/view.html.twig index 835c777528c..c8967ad3a94 100644 --- a/src/Oro/Bundle/EmailBundle/Resources/views/Email/dialog/view.html.twig +++ b/src/Oro/Bundle/EmailBundle/Resources/views/Email/dialog/view.html.twig @@ -5,7 +5,7 @@ {% block page_container %} {{ oro_widget_render({ 'widgetType': 'block', - 'url': path('oro_email_thread_widget', {'id': entity.id}), + 'url': path('oro_email_thread_widget', {'id': entity.id, 'showSingleEmail': not oro_config_value('oro_activity_list.grouping')}), 'alias': 'thread-view' }) }} {% endblock %}