From d1e0a3866cf15d1dac976d5e642dfaae736f6b24 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 2 May 2017 10:49:37 +0200 Subject: [PATCH] hotline #59808 fix PNB widget rendering when logged as sysadmin --- VERSIONS_HOTLINE/59808 | 1 + library/Class/Users.php | 4 ++- .../ZendAfi/View/Helper/TagDilicomWidget.php | 28 +++++++++++-------- .../ZendAfi/View/Helper/RenderAlbumTest.php | 9 ++++++ 4 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 VERSIONS_HOTLINE/59808 diff --git a/VERSIONS_HOTLINE/59808 b/VERSIONS_HOTLINE/59808 new file mode 100644 index 00000000000..80e4bccdcad --- /dev/null +++ b/VERSIONS_HOTLINE/59808 @@ -0,0 +1 @@ + - ticket #59808 : PNB: le player ne s'affiche pas si on est loggé sysadm \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index 01a2cec25db..931857a1a48 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -1730,7 +1730,9 @@ class Class_Users extends Storm_Model_Abstract { public function getBibGLN() { - return $this->getBib()->getGln(); + return $this->hasBib() + ? $this->getBib()->getGln() + : ''; } diff --git a/library/ZendAfi/View/Helper/TagDilicomWidget.php b/library/ZendAfi/View/Helper/TagDilicomWidget.php index c027963fc29..19983f64430 100644 --- a/library/ZendAfi/View/Helper/TagDilicomWidget.php +++ b/library/ZendAfi/View/Helper/TagDilicomWidget.php @@ -21,28 +21,34 @@ class ZendAfi_View_Helper_TagDilicomWidget extends ZendAfi_View_Helper_BaseHelper { - protected $_album, + protected + $_album, $_user; public function tagDilicomWidget($album) { $this->_album = $album; + return $this->_renderPNBActions() . $this->renderBookPreview($album); + } - $links = $this->_tag('p', - $this->_('Vous n\'avez pas le droit d\'accéder à la consultation en ligne.')); + protected function _renderPNBActions() { $this->_user = Class_Users::getIdentity(); if (!$this->_user || ($this->_user->hasRightAccessDilicom() && $this->_user->getBibGLN())) - $links = $this->getConsultBookAnchor() - . $this->getLoanBookAnchor(); + return $this->getConsultBookAnchor() . $this->getLoanBookAnchor(); + + if (!$this->_user->hasRightAccessDilicom()) + return $this->_tag('p', + $this->_('Vous n\'avez pas le droit d\'accéder à la consultation en ligne.')); + - if ($this->_user - && $this->_user->hasRightAccessDilicom() - && !$this->_user->getBibGLN()) - $links = $this->_tag('p', - $this->_('%s n\'a pas accès à la consultation en ligne.', $this->_user->getBib()->getLibelle())); + if (!$this->_user->getBib()) + return $this->_tag('p', + $this->_('Vous devez être inscrit dans une bibliothèque pour accéder à la consultation en ligne')); - return $links . $this->renderBookPreview($album); + return $this->_tag('p', + $this->_('%s n\'a pas accès à la consultation en ligne.', + $this->_user->getBib()->getLibelle())); } diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php index 0f914fed16f..e938c619167 100644 --- a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php +++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php @@ -405,6 +405,15 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_ } + /** @test */ + public function userWithoutBibShouldReturnErrorMessage() { + $this->logged_user->setBib(null)->save(); + $this->_html = $this->_helper->renderAlbum($this->book); + $this->assertXPathContentContains($this->_html, + '//p', utf8_encode('Vous devez être inscrit dans une bibliothèque pour accéder à la consultation en ligne')); + + } + /** @test */ public function withHttpsPreviewSrcShouldBeHttps() { $_SERVER['HTTPS'] = 'on'; -- GitLab