From 088a2ba9ce9ea5f0b7e6c100656a21b090347138 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 3 Mar 2021 15:59:02 +0100 Subject: [PATCH] hotline MT #124508 fix rendering of widget in article --- VERSIONS_HOTLINE/124508 | 1 + library/Class/Systeme/Widget/Abstract.php | 19 +++++- .../View/Helper/Article/RenderWidget.php | 10 ++- .../templates/Intonation/System/Abstract.php | 3 + .../Intonation/View/Article/RenderWidget.php | 31 +++++++++ .../Templates/TemplatesArticlesTest.php | 68 ++++++++++++++++++- 6 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 VERSIONS_HOTLINE/124508 create mode 100644 library/templates/Intonation/View/Article/RenderWidget.php diff --git a/VERSIONS_HOTLINE/124508 b/VERSIONS_HOTLINE/124508 new file mode 100644 index 00000000000..345ecf4cd5c --- /dev/null +++ b/VERSIONS_HOTLINE/124508 @@ -0,0 +1 @@ + - ticket #124508 : Magasin de thèmes : correction de l'affichage des carrousels embarqués dans des articles \ No newline at end of file diff --git a/library/Class/Systeme/Widget/Abstract.php b/library/Class/Systeme/Widget/Abstract.php index 4b7bfb90d01..a29da821b76 100644 --- a/library/Class/Systeme/Widget/Abstract.php +++ b/library/Class/Systeme/Widget/Abstract.php @@ -33,7 +33,8 @@ abstract class Class_Systeme_Widget_Abstract extends Class_Entity { protected $_cache_key, $_errors = [], - $_is_in_menu = false; + $_is_in_menu = false, + $_disable_fonction_admin = false; public function load() { @@ -90,12 +91,13 @@ abstract class Class_Systeme_Widget_Abstract extends Class_Entity { public function loadFromSettings($settings) { return $this ->setProfileId(Class_Profil::getCurrentProfil()->getId()) - ->setId('no') + ->setId('no_' . uniqid()) ->init() ->_transmute($settings) ->setTitle($this->_getTitle()) ->setForm($this->_getForm()) - ->setViewHelper($this->_getViewHelper()); + ->setViewHelper($this->_getViewHelper()) + ->_disableFonctionAdmin(); } @@ -434,4 +436,15 @@ abstract class Class_Systeme_Widget_Abstract extends Class_Entity { public function settitre($titre) { return $this->set('titre', $titre); } + + + protected function _disableFonctionAdmin() { + $this->_disable_fonction_admin = true; + return $this; + } + + + public function isFonctionAdminDisabled() { + return $this->_disable_fonction_admin; + } } diff --git a/library/ZendAfi/View/Helper/Article/RenderWidget.php b/library/ZendAfi/View/Helper/Article/RenderWidget.php index 744c40bfc2c..21e9006a9f5 100644 --- a/library/ZendAfi/View/Helper/Article/RenderWidget.php +++ b/library/ZendAfi/View/Helper/Article/RenderWidget.php @@ -24,11 +24,17 @@ class ZendAfi_View_Helper_Article_RenderWidget extends ZendAfi_View_Helper_BaseH public function article_RenderWidget($code, $form) { $prefs = []; parse_str(html_entity_decode($form), $prefs); - $params = ['type_module'=> $code, - 'preferences' => $prefs]; + + return $this->_getHTMLWith(['type_module'=> $code, + 'preferences' => $prefs]); + } + + + protected function _getHTMLWith($params) { $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams(null, $params, $this->view); + return $helper ->setFonctionAdminHelper(null) ->getBoite(); diff --git a/library/templates/Intonation/System/Abstract.php b/library/templates/Intonation/System/Abstract.php index 2092b068415..028ce832f99 100644 --- a/library/templates/Intonation/System/Abstract.php +++ b/library/templates/Intonation/System/Abstract.php @@ -67,6 +67,9 @@ abstract class Intonation_System_Abstract { $this->forForm(), $view); + if ($this->_settings->isFonctionAdminDisabled()) + $widget->setFonctionAdminHelper(null); + return $base->wrap($widget); } diff --git a/library/templates/Intonation/View/Article/RenderWidget.php b/library/templates/Intonation/View/Article/RenderWidget.php new file mode 100644 index 00000000000..f3966a429a3 --- /dev/null +++ b/library/templates/Intonation/View/Article/RenderWidget.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_View_Article_RenderWidget extends ZendAfi_View_Helper_Article_RenderWidget { + + protected function _getHTMLWith($params) { + $widget = ((new Class_Systeme_Widget_Widget) + ->loadFromSettings($params)); + + return Class_Template::current()->renderWidget($widget, $this->view); + } +} diff --git a/tests/scenarios/Templates/TemplatesArticlesTest.php b/tests/scenarios/Templates/TemplatesArticlesTest.php index 515f3ccffd8..188c635a115 100644 --- a/tests/scenarios/Templates/TemplatesArticlesTest.php +++ b/tests/scenarios/Templates/TemplatesArticlesTest.php @@ -773,4 +773,70 @@ class TemplatesArticlesWidgetAjaxRenderingTest extends AbstractControllerTestCas public function exactly112ArticlesShouldHaveBeenCounted() { $this->assertXPathContentContains('//span', '112', $this->_response->getBody()); } -} \ No newline at end of file +} + + + + + +abstract class TemplatesArticlesWithWidgetRenderWallTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->_buildTemplateProfil(['id' => 32, + 'template' => 'MYBIBAPP']); + + $this->_logAdmin(); + + $this->fixture('Class_Article', [ 'id' => 55, + 'titre' => 'Mes dvds', + 'contenu' => '<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&">']); + + $this->dispatch('/cms/articleview/id/55'); + } + + + protected function _logAdmin() { + } +} + + + + +class TemplatesArticlesWithWidgetRenderWallNotLoggedTest + extends TemplatesArticlesWithWidgetRenderWallTestCase { + + /** @test */ + public function bokehKioskShouldBeRemoved() { + $this->assertNotXPath('//img[@class="bokeh_kiosk"]'); + } + + + /** @test */ + public function wallJSShouldBeCallWithId() { + $this->assertXPathContentContains('//script[contains(text(), \'$(function(){$("#no_\')]', '.parent().masonry();});'); + } +} + + + + +class TemplatesArticlesWithWidgetRenderWallLoggedAsAdminTest + extends TemplatesArticlesWithWidgetRenderWallTestCase { + + protected function _logAdmin() { + ZendAfi_Auth::getInstance() + ->logUser($this->fixture('Class_Users', + ['id' => 123, + 'login' => 'admin', + 'password' => 'auieauei', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN])); + } + + + /** @test */ + public function adminToolsShouldNotBePresent() { + $this->assertNotXPath('//a[contains(@href, "admin/widget/edit-widget/id/no_")]'); + } +} -- GitLab