Commit 3cdb7a8f authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'dev#62896_contractuel_sanop_miop_evolution_boite_sitotheque' into 'master'

Dev#62896 contractuel sanop miop evolution boite sitotheque

See merge request !2428
parents 0129c7c2 c147223f
'62896' =>
['Label' => $this->_('Evolution de la boite sitothèque'),
'Desc' => $this->_('Possibilité d\'éditer ou d\'ajouter un site, dans une boite sithothèque, depuis l'interface publique.'),
'Image' => '',
'Video' => '',
'Category' => 'Administration',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Boite_Sitoth%C3%A8que#Ajout_et_modification_de_sites_depuis_l.27interface_publique',
'Test' => '',
'Date' => '2017-11-28'],
\ No newline at end of file
- ticket #62896 : Boite sitothèque : possibilité d'ajouter et/ou d'éditer un site en front
\ No newline at end of file
......@@ -850,7 +850,7 @@ class Class_Users extends Storm_Model_Abstract {
* @return array
*/
public function getRights() {
$rights = array();
$rights = [];
$groups = $this->getUserGroups();
foreach ($groups as $group)
$rights = array_merge($rights, $group->getRights());
......@@ -884,6 +884,11 @@ class Class_Users extends Storm_Model_Abstract {
}
public function hasRightConfigSito() {
return $this->isAdmin() || $this->hasRightToAccess(Class_UserGroup::RIGHT_USER_SITOTHEQUE);
}
/**
* @return bool
*/
......
......@@ -27,6 +27,29 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base
}
protected function _extendedActions() {
return [function() { return $this->addSitoAddButton(); }];
}
protected function addSitoAddButton() {
if (!$user = Class_Users::getIdentity())
return '';
if (!$user->hasRightConfigSito())
return '';
return $this->view
->tagAnchor($this->view->url(['module' => 'admin',
'controller' => 'sito',
'action' => 'add',
'id_cat' => $this->getPreference('id_categorie')]),
Class_Admin_Skin::current()
->renderActionIconOn('add', $this->view,
['title' => $this->_('Ajouter un nouveau site')]),
['data-popup' => 'true']);
}
public function shouldCacheContent() {
return $this->isPaginatedDisplay()
? false
......@@ -204,7 +227,7 @@ class SitoDisplayStrategy {
return Class_Sitotheque::getSitesFromIdsAndCategories(explode('-',
$this->getPreference('id_items')),
explode('-',
$this->getPreference('id_categorie')));
$this->getPreference('id_categorie')));
}
......
......@@ -24,6 +24,7 @@ class ZendAfi_View_Helper_RenderSito extends ZendAfi_View_Helper_BaseHelper {
public function renderSito($site) {
return $this->_renderLabelOf($site) . $site->getDescription();
}
......@@ -33,7 +34,9 @@ class ZendAfi_View_Helper_RenderSito extends ZendAfi_View_Helper_BaseHelper {
$this->_renderImageOf($site) . $site->getTitre(),
['href' => $site->getUrl(),
'title' => $this->_('Aller sur le site %s',
$site->getTitre())]));
$site->getTitre())]).
$this->view->tagEditSito($site));
}
......
<?php
/**
* Copyright (c) 2012, 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_TagEditSito extends ZendAfi_View_Helper_BaseHelper {
protected
$_sito,
$_current_skin;
public function __construct() {
parent::__construct();
$this->_current_skin = Class_Admin_Skin::current();
}
/**
* @param Class_Sito $sito
* @return string
*/
public function tagEditSito($sito) {
if (!$user = Class_Users::getIdentity())
return '';
if (!$user->hasRightConfigSito())
return '';
return $this->_tag('span', $this->renderEdit($sito),
['class' => 'edit_sito']);
}
public function setSito($sito) {
$this->_sito = $sito;
return $this;
}
public function renderEdit($sito) {
return $this->setSito($sito)
->_renderEdit()
.$this->_renderAddInCategory();
}
protected function _renderEdit() {
return $this
->_renderActionLink('edit', $this->_('Modifier le site'),
['module' => 'admin',
'controller' => 'sito',
'action' => 'edit',
'id' => $this->_sito->getId()]);
}
protected function _renderAddInCategory() {
return $this
->_renderActionLink('add', $this->_('Ajouter un site dans la catégorie: '). $this->_sito->getCategorie()->getLibelle(),
['module' => 'admin',
'controller' => 'sito',
'action' => 'add',
'id_cat' => $this->_sito->getCategorie()->getId()]);
}
protected function _renderActionLink($icon, $label, $url) {
$icon = $this->_current_skin
->renderActionIconOn($icon, $this->view, ['alt' => $label]);
return $this->view->tagAnchor($url, $icon,
['data-popup' => 'true', 'title' => $label]);
}
}
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
n * Copyright (c) 2012, 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
......@@ -29,9 +29,12 @@ abstract class SitoViewHelperTestCase extends ViewHelperTestCase {
protected $_france;
protected $_creuse;
public function parentSetup() {
parent::setUp();
}
public function setUp() {
parent::setUp();
$this->parentSetup();
Storm_Cache::beVolatile();
Storm_Cache::setSeed('local');
......@@ -43,7 +46,25 @@ abstract class SitoViewHelperTestCase extends ViewHelperTestCase {
]);
Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => ''])->save();
$this->addFixturesSito();
$this->createBoxAndHelper();
}
protected function createBoxAndHelper() {
$this->_helper = new ZendAfi_View_Helper_Accueil_Sito(2, ['division' => '1',
'type_module' => 'SITO',
'preferences' => $this->_preferences]);
$view = new ZendAfi_Controller_Action_Helper_View();
$view->setScriptPath('application/modules/opac/views/scripts');
$this->_helper->setView($view);
$this->html = $this->_helper->getBoite();
}
protected function addFixturesSito() {
$this->_belgique = $this->fixture('Class_SitothequeCategorie',
['id' => 5, 'libelle'=>'Belgique']);
......@@ -96,14 +117,7 @@ abstract class SitoViewHelperTestCase extends ViewHelperTestCase {
'url' => 'http://www.rmll.info',
'categorie' => $this->_france]);
$this->_helper = new ZendAfi_View_Helper_Accueil_Sito(2, ['division' => '1',
'type_module' => 'SITO',
'preferences' => $this->_preferences]);
$view = new ZendAfi_Controller_Action_Helper_View();
$view->setScriptPath('application/modules/opac/views/scripts');
$this->_helper->setView($view);
$this->html = $this->_helper->getBoite();
}
}
......@@ -348,6 +362,128 @@ class SitoViewHelperLastTest extends SitoViewHelperTestCase {
}
class SitoViewHelperAdminTest extends SitoViewHelperTestCase {
protected $_preferences = ['titre' => 'Ma sito',
'type_aff' => 1,
'id_items' => '12-15',
'id_categorie' => '',
'nb_aff' => 0,
'display_order' => 'Selection'];
public function setUp() {
$this->parentSetup();
}
protected function logAdmin() {
$joe = $this->fixture('Class_Users',
['id' => 23,
'login' => 'Joe',
'password' => 'unsupermotdepasse',
'id_site' => 1,
'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1']),
'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]);
ZendAfi_Auth::getInstance()->logUser($joe);
$this->addFixturesSito();
$this->createBoxAndHelper();
}
protected function logModo() {
$joe = $this->fixture('Class_Users',
['id' => 23,
'login' => 'Joe',
'password' => 'unsupermotdepasse',
'id_site' => 1,
'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1']),
'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL]);
ZendAfi_Auth::getInstance()->logUser($joe);
$this->addFixturesSito();
$this->createBoxAndHelper();
}
protected function logModoAllowed() {
$group_sito= $this->fixture('Class_UserGroup',
['id' => 22,
'libelle' => 'Testing group',
'rights' => [Class_UserGroup::RIGHT_USER_SITOTHEQUE]]);
$joe = $this->fixture('Class_Users',
['id' => 23,
'login' => 'Joe',
'password' => 'unsupermotdepasse',
'id_site' => 1,
'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1']),
'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL,
'user_groups' => [$group_sito]]);
ZendAfi_Auth::getInstance()->logUser($joe);
$this->addFixturesSito();
$this->createBoxAndHelper();
}
/** @test */
public function editAdminButtonSitoShouldBeDisplayed() {
$this->logAdmin();
$this->assertXPath($this->html,
'//a[contains(@href,"/admin/sito/edit/id/12")]//img[@alt="Modifier le site"]',$this->html);
}
/** @test */
public function editAdminButtonSitoShouldNotBeDisplayedWithModo() {
$this->logModo();
$this->assertNotXPath($this->html,
'//img[@alt="Modifier le site"]',$this->html);
}
/** @test */
public function addAdminButtonSitoShouldNotBeDisplayedWithModo() {
$this->logModo();
$this->assertNotXPath($this->html,
'//img[contains(@alt,"Ajouter un site")]',$this->html);
}
/** @test */
public function addAdminButtonNewSitoShouldBeDisplayedWithUserWithRights() {
$this->logModoAllowed();
$this->assertXPath($this->html,
'//img[contains(@alt,"Ajouter un nouveau site")]',$this->html);
}
/** @test */
public function editAdminButtonAddSitoShouldBeDisplayed() {
$this->logAdmin();
$this->assertXPath($this->html,
'//a[contains(@href,"/admin/sito/add/id_cat/9")]//img[@alt="Ajouter un site dans la catégorie: France"]',$this->html);
}
/** @test */
public function editWithUserGroupSitoButtonAddSitoShouldBeDisplayed() {
$this->logModoAllowed();
$this->assertXPath($this->html,
'//a[contains(@href,"/admin/sito/add/id_cat/9")]//img[@alt="Ajouter un site dans la catégorie: France"]',$this->html);
}
}
class SitoViewHelperGroupByCategorieTest extends SitoViewHelperTestCase {
......
Markdown is supported
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