Skip to content
Snippets Groups Projects
Commit d80c47b8 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'dev#101702_mon_bokeh_n_est_pas_dans_la_derniere_version' into 'WIP'

dev #101702 display alert on admin page if Bokeh is not latest version

See merge request !3366
parents 5408bbb2 84448e08
Branches
Tags
1 merge request!3366dev #101702 display alert on admin page if Bokeh is not latest version
Pipeline #9142 passed with stage
in 44 minutes and 45 seconds
- 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
......@@ -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();
......
<?php
echo $this->renderBokehVersion();
if ($this->is_request_secure)
echo $this->myBibAppTeaser()
echo $this->myBibAppTeaser();
?>
<h2 class="toggle_video">
......
<?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
<?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)]);
}
}
......@@ -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) {
......
<?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());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment