From 00b82c85c91ec7714d52275bb4e8e70513316856 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Wed, 13 Apr 2022 12:20:36 +0200
Subject: [PATCH] hotline #154406 fix edit article link in moderation mail
 after being saved in a popup

---
 VERSIONS_HOTLINE/154406                          |  1 +
 library/Class/Article/WorkflowNotification.php   |  2 +-
 library/ZendAfi/View/Helper/TagEditArticle.php   | 12 +++++++-----
 .../admin/controllers/CmsControllerTest.php      | 16 ++++++++++++++++
 4 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/154406

diff --git a/VERSIONS_HOTLINE/154406 b/VERSIONS_HOTLINE/154406
new file mode 100644
index 00000000000..f07e652b91d
--- /dev/null
+++ b/VERSIONS_HOTLINE/154406
@@ -0,0 +1 @@
+ - correctif #154406 : Administration : correction des liens d'accès aux articles à valider dans les emails. Lorsqu'un article brouillon était modifié dans un popup, le contexte de popup était ajouté au lien dans l'email.
\ No newline at end of file
diff --git a/library/Class/Article/WorkflowNotification.php b/library/Class/Article/WorkflowNotification.php
index eba88cba601..032d1fb81c6 100644
--- a/library/Class/Article/WorkflowNotification.php
+++ b/library/Class/Article/WorkflowNotification.php
@@ -86,7 +86,7 @@ class Class_Article_WorkflowNotification {
 
   protected function _bodyText() {
     $replacements = ['TITRE_ARTICLE' => $this->_article->getTitre(),
-                     'URL_ARTICLE' => (new ZendAfi_View_Helper_TagEditArticle)->getEditUrl($this->_article),
+                     'URL_ARTICLE' => (new ZendAfi_View_Helper_TagEditArticle)->getEditUrl($this->_article, ['render' => null]),
                      'AUTHOR_ARTICLE' => $this->_article->getNomCompletAuteur(),
                      'SAVED_BY_ARTICLE' => $this->_user->getNomComplet(),
                      'NEXT_STATUS_ARTICLE' => $this->_article->getNextWorkflowStatusLabel(),
diff --git a/library/ZendAfi/View/Helper/TagEditArticle.php b/library/ZendAfi/View/Helper/TagEditArticle.php
index ff629920a19..c69fef6a491 100644
--- a/library/ZendAfi/View/Helper/TagEditArticle.php
+++ b/library/ZendAfi/View/Helper/TagEditArticle.php
@@ -86,10 +86,12 @@ class ZendAfi_View_Helper_TagEditArticle extends ZendAfi_View_Helper_BaseHelper
   }
 
 
-  public function getEditUrl($article) {
-    return Class_Url::absolute(['module' => 'admin',
-                                'controller' => 'cms',
-                                'action' => 'edit',
-                                'id' => $article->getId()]);
+  public function getEditUrl(Class_Article $article, array $params = []) : string {
+    return
+      Class_Url::absolute(array_merge(['module' => 'admin',
+                                       'controller' => 'cms',
+                                       'action' => 'edit',
+                                       'id' => $article->getId()],
+                                      $params));
   }
 }
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index eda6f8f2a3e..f0f31437dd4 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -1868,6 +1868,22 @@ class CmsControllerNewsAddActionPostWithWorkflowTest
     $this->assertEquals(Class_Article::STATUS_DRAFT,
                         Class_Article::findFirstBy(['order' => 'id desc'])->getStatus());
   }
+
+
+  /** @test */
+  public function sentMailToAdminWhenValidationPendingInPopupShouldURLWithoutRenderPopup() {
+    Class_Article::find(18)->setStatus(Class_Article::STATUS_DRAFT)->save();
+    $data = $this->_basePostDatas;
+    $data['status'] = Class_Article::STATUS_VALIDATION_PENDING;
+    $this->postDispatch('/admin/cms/edit/id/18/render/popup', $data);
+    $this->assertEquals('Un nouvel article de Batman est à valider. Katsuhiro Otomo en dédicace ! http://localhost'
+                        . BASE_URL
+                        . '/admin/cms/edit/id/18',
+                        quoted_printable_decode(($this->mock_transport
+                                                 ->getSentMails()[0]
+                                                 ->getBodyText()
+                                                 ->getContent())));
+  }
 }
 
 
-- 
GitLab