diff --git a/VERSIONS_WIP/101702 b/VERSIONS_WIP/101702 new file mode 100644 index 0000000000000000000000000000000000000000..050709e58fa58740fd655cf30712d429cb0c5959 --- /dev/null +++ b/VERSIONS_WIP/101702 @@ -0,0 +1 @@ + - ticket #101702 : Affiche un message d'avertissement sur l'accueil de l'administration si Bokeh n'est pas dans la dernière version \ No newline at end of file diff --git a/application/modules/admin/controllers/IndexController.php b/application/modules/admin/controllers/IndexController.php index 682dc3b1fdcb0044d43c65c47b0662c144cf2855..af4e4d9c2dfb7da4e883e5d1e562066f77d8a1aa 100644 --- a/application/modules/admin/controllers/IndexController.php +++ b/application/modules/admin/controllers/IndexController.php @@ -20,12 +20,7 @@ */ class Admin_IndexController extends ZendAfi_Controller_Action { public function indexAction() { - $this->view->titre = $this->_('Accueil') - . $this->view->tag('span', - $this->_(' version %s', - $this->view->tag('a', BOKEH_RELEASE_NUMBER, - ['href' => BOKEH_REMOTE_FILES . 'blob/master/VERSIONS'])), - ['class' => 'version']); + $this->view->titre = $this->_('Accueil'); $this->view->user = Class_Users::getIdentity(); diff --git a/application/modules/admin/views/scripts/index/index.phtml b/application/modules/admin/views/scripts/index/index.phtml index b7abcae2fc2eb933393a78be4683d85d1e5c92c8..64bc32060f4fddf7d8a049669057658caa1e80ab 100644 --- a/application/modules/admin/views/scripts/index/index.phtml +++ b/application/modules/admin/views/scripts/index/index.phtml @@ -1,6 +1,10 @@ + + <?php +echo $this->renderBokehVersion(); + if ($this->is_request_secure) - echo $this->myBibAppTeaser() + echo $this->myBibAppTeaser(); ?> <h2 class="toggle_video"> diff --git a/library/Class/BokehVersion.php b/library/Class/BokehVersion.php new file mode 100644 index 0000000000000000000000000000000000000000..ee3110b86afa7cf0b4a4f1a5668cbb4f841d3d4c --- /dev/null +++ b/library/Class/BokehVersion.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright (c) 2012-2019, 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 Class_BokehVersion { + public function current() { + return BOKEH_RELEASE_NUMBER; + } + + + public function isUpToDate() { + return $this->current() == $this->latest(); + } + + + public function latest() { + try { + return (new Storm_Cache()) + ->memoize([__CLASS__, __FUNCTION__], + function() + { + $json = Class_WebService_SimpleWebClient::getInstance() + ->open_url('https://git.afi-sa.net/api/v4/projects/4/repository/tags?per_page=1&order_by=updated&sort=desc'); + $version = json_decode($json, true)[0]['name']; + return $version ? $version : $this->current(); + }); + } catch(Exception $e) { + return $this->current(); + } + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderBokehVersion.php b/library/ZendAfi/View/Helper/RenderBokehVersion.php new file mode 100644 index 0000000000000000000000000000000000000000..643d7269a4cf38753e826f27d43bb2c7cd09cf10 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderBokehVersion.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2012-2020, 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 ZendAfi_View_Helper_RenderBokehVersion extends ZendAfi_View_Helper_BaseHelper { + protected $_bokeh_version; + + public function init() { + $this->_bokeh_version = new Class_BokehVersion(); + return $this; + } + + + public function renderBokehVersion() { + return $this->_tag('div', + $this->_renderCurrentVersion() . $this->_renderLatestVersion()); + + } + + + protected function _renderCurrentVersion() { + return $this->_tag('span', + $this->_('Version %s', + $this->_linkToChangelog($this->_bokeh_version->current())), + ['class' => 'version']); + } + + + protected function _renderLatestVersion() { + if ($this->_bokeh_version->isUpToDate()) + return ''; + + return ' - ' + . $this->_tag('span', + $this->_('Nous vous recommandons de mettre à jour Bokeh dans la dernière version %s. Merci de contacter votre hébergeur', + $this->_linkToChangelog($this->_bokeh_version->latest())), + ['class' => 'error']); + } + + + protected function _linkToChangelog($version) { + return $this->_tag('a', + $version, + ['href' => 'https://git.afi-sa.net/afi/opacce/tags/'. $version, + 'title' => $this->_('Liste des évolutions de la version %s', $version)]); + } +} diff --git a/tests/application/modules/admin/controllers/IndexControllerTest.php b/tests/application/modules/admin/controllers/IndexControllerTest.php index 0686e77c24c6bc93839d6cead9ef93e8a4fe868b..04284ea713e611289929999ff278821466071717 100644 --- a/tests/application/modules/admin/controllers/IndexControllerTest.php +++ b/tests/application/modules/admin/controllers/IndexControllerTest.php @@ -59,6 +59,7 @@ class Admin_IndexControllerWithHTTPSTest extends Admin_IndexControllerTestCase { class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { + protected $_next_version; public function setUp() { parent::setUp(); @@ -67,12 +68,21 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { 'clef' => 'NOM_DOMAINE', 'valeur' => 'https://bokeh-library-portal.org']); + $this->_next_version = BOKEH_MAJOR_VERSION . '.' . (1 + (int)explode('.', BOKEH_RELEASE_NUMBER)[2]); + + $mock_http = $this->mock() + ->whenCalled('open_url') + ->with('https://git.afi-sa.net/api/v4/projects/4/repository/tags?per_page=1&order_by=updated&sort=desc') + ->answers('[{"name":"' . $this->_next_version . '"}]'); + Class_WebService_SimpleWebClient::setInstance($mock_http); + $this->dispatch('/admin/index/index', true); } public function tearDown() { ZendAfi_View_Helper_Admin_CosmoStatus::setTimeSource(null); + Class_WebService_SimpleWebClient::resetInstance(); parent::tearDown(); } @@ -121,7 +131,14 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { /** @test */ public function titleShouldContainsVersion() { - $this->assertXPathContentContains('//div[@class="modules"]//h1//a', BOKEH_RELEASE_NUMBER); + $this->assertXPathContentContains('//div[@class="modules"]//div//a', BOKEH_RELEASE_NUMBER); + } + + + /** @test */ + public function pageShouldContainsWarningObsoleteVersion() { + $this->assertXPathContentContains('//span[@class="error"][contains(text(), "mettre à jour")]/a[@href="https://git.afi-sa.net/afi/opacce/tags/' . $this->_next_version . '"]', + $this->_next_version); } @@ -199,6 +216,40 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { + +class Admin_IndexControllerWhenUpToDateTest extends Admin_IndexControllerTestCase { + protected $_next_version; + + public function setUp() { + parent::setUp(); + + $mock_http = $this->mock() + ->whenCalled('open_url') + ->with('https://git.afi-sa.net/api/v4/projects/4/repository/tags?per_page=1&order_by=updated&sort=desc') + ->answers('[{"name":"' . BOKEH_RELEASE_NUMBER . '"}]'); + Class_WebService_SimpleWebClient::setInstance($mock_http); + + $this->dispatch('/admin/index/index', true); + } + + + public function tearDown() { + Class_WebService_SimpleWebClient::resetInstance(); + parent::tearDown(); + } + + + /** @test */ + public function pageShouldNotContainsWarningObsoleteVersion() { + $this->assertNotXPathContentContains('//span', + 'mettre à jour', + $this->_response->getBody()); + } +} + + + + class Admin_IndexControllerRedacteurTest extends Admin_IndexControllerTestCase { protected function _loginHook($account) { diff --git a/tests/library/Class/BokehVersionTest.php b/tests/library/Class/BokehVersionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..bb90c4d76b73da1ff49b86b701eb75174f2f3605 --- /dev/null +++ b/tests/library/Class/BokehVersionTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright (c) 2012-2019, 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 BokehVersionTest extends ModelTestCase { + protected + $_next_version, + $_mock_http; + + public function setUp() { + parent::setUp(); + Storm_Cache::beVolatile(); + + $this->_next_version = BOKEH_MAJOR_VERSION . '.' . (1 + (int)explode('.', BOKEH_RELEASE_NUMBER)[2]); + + $this->_mock_http = $this->mock() + ->whenCalled('open_url') + ->with('https://git.afi-sa.net/api/v4/projects/4/repository/tags?per_page=1&order_by=updated&sort=desc') + ->answers('[{"name":"' . $this->_next_version . '"}]'); + + Class_WebService_SimpleWebClient::setInstance($this->_mock_http); + } + + + public function tearDown() { + Class_WebService_SimpleWebClient::resetInstance(); + parent::tearDown(); + } + + + /** @test */ + public function latestVersionShouldBeCached() { + (new Class_BokehVersion())->latest(); + $this->_mock_http->clearAllRedirections() + ->whenCalled('open_url') + ->never(); + + $this->assertEquals($this->_next_version, (new Class_BokehVersion())->latest()); + } + + + /** @test */ + public function latestVersionShouldReturnCurrentVersionOnError() { + $this->_mock_http->clearAllRedirections() + ->whenCalled('open_url') + ->willDo(function() + { + throw new Exception('unreachable !'); + }); + $this->assertEquals(BOKEH_RELEASE_NUMBER, (new Class_BokehVersion())->latest()); + } + + + + /** @test */ + public function latestVersionShouldReturnCurrentVersionOnEmptyResponse() { + $this->_mock_http->clearAllRedirections() + ->whenCalled('open_url') + ->answers(''); + $this->assertEquals(BOKEH_RELEASE_NUMBER, (new Class_BokehVersion())->latest()); + } + +}