Commit da65bea3 authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

dev #98074 : blocked patron cannot access digital resources

parent da2c827a
Pipeline #8470 passed with stage
in 41 minutes and 57 seconds
- ticket #98074 : Ressources numériques : Si la carte d'un abonné est bloquée l'accès aux ressources numériques n'est plus autorisé
\ No newline at end of file
......@@ -19,6 +19,14 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class BibNumeriqueController extends ZendAfi_Controller_Action {
protected $_user;
public function init() {
parent::init();
$this->_user = $this->view->user = Class_Users::getIdentity();
}
public function viewAlbumAction() {
if (null === ($album = Class_Album::getLoader()->find((int)$this->_getParam('id')))) {
$this->_redirect('opac/');
......@@ -29,9 +37,6 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
/**
* Génére le JSON pour le livre numérique
*/
public function albumAction() {
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
......@@ -40,13 +45,10 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
public function albumXspfPlaylistAction() {
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
$playlist = $this->view->album_XspfPlaylistVisitor($album);
$this->getHelper('ViewRenderer')->setNoRender();
$response = $this->_response;
$response->clearAllHeaders();
......@@ -148,6 +150,7 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
$this->_getParam('attachment', false));
}
/**
* Interpretation des permaliens type http://localhost/afi-opac3/bib-numerique/notice/ido/D09030001/folio/1R4
* sur les Albums + folios
......@@ -251,31 +254,31 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
protected function _redirectToLogin() {
if (!$this->_user = Class_Users::getLoader()->getIdentity()) {
$this->_forward('login', 'auth', 'opac', ['redirect' => $this->view->absoluteUrl()]);
return true;
}
return false;
if ($this->_user)
return false;
$this->_forward('login', 'auth', 'opac', ['redirect' => $this->view->absoluteUrl()]);
return true;
}
protected function _redirectToPopupLogin($url) {
if (!$this->_user = Class_Users::getLoader()->getIdentity()) {
$this->_forward('popup-login', 'auth', 'opac', ['redirect' => $url]);
return true;
}
return false;
if ($this->_user)
return false;
$this->_forward('popup-login', 'auth', 'opac', ['redirect' => $url]);
return true;
}
protected function _userShouldBeRedirect() {
if($this->_redirectToPopupLogin($this->view->url()))
if ($this->_redirectToPopupLogin($this->view->url()))
return true;
if (!$this->_user->hasRightAccessDilicom())
return $this->_ajaxRedirectToNotice();
if(!$this->view->album = Class_Album::find($this->_getParam('id')))
if (!$this->view->album = Class_Album::find($this->_getParam('id')))
return $this->_ajaxRedirectToNotice();
return false;
......@@ -291,59 +294,39 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
public function consultBookAjaxAction() {
if($this->_userShouldBeRedirect())
return;
$this->view->titre = $this->_('Consulter le livre en ligne');
$this->renderScript('bib-numerique/consult-book.phtml');
}
public function consultBookOpenAjaxAction() {
if($this->_userShouldBeRedirect())
public function loanBookAction() {
if ($this->_redirectToLogin())
return;
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())->consultBook($this->view->album,
$client_ip,
$this->_user);
return $this->_withContentDo($response,
function($url)
{
$this->view->open_url = $url;
$this->renderPopupResult($this->_('Consultation'),
$this->view->render('bib-numerique/consult-book-open.phtml'));
});
}
if (!$this->_user->hasRightAccessDilicom())
return $this->_redirectToReferer();
if (!$album = Class_Album::find($this->_getParam('id')))
return $this->_redirectToReferer();
protected function _withContentDo($content, $closure) {
if(!$content)
return $this->_ajaxRedirectToNotice();
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook($album, $this->_user);
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_ajaxRedirectToNotice();
return $this->_redirectToNotice($album->getNoticeId());
}
$closure($content->link->url);
$this->_redirect($content->link->url);
}
public function downloadLoanBookAjaxAction() {
if($this->_userShouldBeRedirect())
if ($this->_userShouldBeRedirect())
return;
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook(Class_Album::find($this->_getParam('id')), $this->_user);
return $this->_withContentDo($content,
function($url)
{
$this->view->download_url = $url;
$this->renderPopupResult($this->_('Téléchargement'), $this->view->render('bib-numerique/download-book.phtml'));
});
$this->_withContentDo($content,
function($url)
{
$this->view->download_url = $url;
$this->renderPopupResult($this->_('Téléchargement'), $this->view->render('bib-numerique/download-book.phtml'));
});
}
......@@ -351,22 +334,52 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
$this->view->redirect_url = $this->view->url(['controller' => 'recherche',
'action' => 'viewnotice',
'render' => 'false']);
return $this->renderPopupResult('', $this->view->render('bib-numerique/redirect.phtml'));
$this->renderPopupResult('', $this->view->render('bib-numerique/redirect.phtml'));
return true;
}
public function consultBookAjaxAction() {
if($this->_userShouldBeRedirect())
return;
$this->view->titre = $this->_('Consulter le livre en ligne');
$this->renderScript('bib-numerique/consult-book.phtml');
}
public function consultBookOpenAjaxAction() {
if ($this->_userShouldBeRedirect())
return;
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())
->consultBook($this->view->album, $client_ip, $this->_user);
return $this->_withContentDo($response,
function($url)
{
$this->view->open_url = $url;
$this->renderPopupResult($this->_('Consultation'),
$this->view->render('bib-numerique/consult-book-open.phtml'));
});
}
public function consultBookAction() {
if ($this->_redirectToLogin())
return ;
if (!$this->_user->hasRightAccessDilicom())
return;
if (!$this->_user->hasRightAccessDilicom())
return $this->_redirectToReferer();
$album = Class_Album::find($this->_getParam('id'));
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())->consultBook($album,
$client_ip,
Class_Users::getIdentity());
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())
->consultBook($album, $client_ip, $this->_user);
$content = $response;
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
......@@ -386,24 +399,16 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
}
public function loanBookAction() {
if ($this->_redirectToLogin())
return ;
if (!$this->_user->hasRightAccessDilicom())
return;
if(!$album = Class_Album::find($this->_getParam('id')))
return $this->_redirectToReferer();
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook($album, $this->_user);
protected function _withContentDo($content, $closure) {
if (!$content)
return $this->_ajaxRedirectToNotice();
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_redirectToNotice($album->getNoticeId());
return $this->_ajaxRedirectToNotice();
}
return $this->_redirect($content->link->url);
$closure($content->link->url);
}
......@@ -424,5 +429,3 @@ class BibNumeriqueController extends ZendAfi_Controller_Action {
$viewRenderer->setLayoutScript('empty.phtml');
}
}
?>
\ No newline at end of file
......@@ -29,21 +29,21 @@ class Class_User_ILSSubscription {
}
public function isILSExpirable() {
return $this->_user->isAbonne() && $this->_user->hasDateFin();
public function isExpirable() {
return $this->_user->isAbonne() && $this->_user->hasDateFin();
}
public function isILSExpired() {
public function isExpired() {
return
$this->isILSExpirable()
$this->isExpirable()
&& ($this->_user->getDateFin() < $this->getTimeSource()->dateYmd());
}
public function isILSAboutToExpire() {
public function isAboutToExpire() {
return
$this->isILSExpirable()
$this->isExpirable()
&& ($this->ilsExpireIn() >= 0)
&& (Class_AdminVar::getValueOrDefault('NDAYS_EXPIRY_NOTICE') >= $this->ilsExpireIn());
}
......@@ -57,13 +57,15 @@ class Class_User_ILSSubscription {
public function isValid() {
if (! $this->_user->isAbonne())
if (!$this->_user->isAbonne())
return false;
if (! $this->_user->hasDateFin())
return true;
return !$this->isExpired() && !$this->isBlocked();
}
return ($this->_user->getDateFin() >= $this->getTimeSource()->dateYmd());
public function isBlocked() {
return $this->_user->isAbonne() && $this->_user->isBlocked();
}
......@@ -114,10 +116,10 @@ class Class_User_ILSSubscription {
public function registerNotificationsWith($notifiable, $expired_message, $about_to_expire_message) {
if($this->isILSExpired())
if ($this->isExpired())
$notifiable->notify($expired_message);
if ($this->isILSAboutToExpire())
if ($this->isAboutToExpire())
$notifiable->notify($about_to_expire_message);
return $this;
......
......@@ -1930,4 +1930,9 @@ class Class_Users extends Storm_Model_Abstract {
foreach($this->getFormulaires() as $form)
$form->anonymize()->save();
}
public function isBlocked() {
return $this->getEmprunteur()->isBlocked();
}
}
......@@ -79,10 +79,9 @@ class Class_WebService_SIGB_EmprunteurCache {
* @return Class_WebService_SIGB_Emprunteur
*/
public function loadFromCacheOrSIGB($user, $sigb) {
if ($this->isCached($user))
return $this->load($user);
return $this->save($user, $sigb->getEmprunteur($user));
return $this->isCached($user)
? $this->load($user)
: $this->save($user, $sigb->getEmprunteur($user));
}
......@@ -95,5 +94,3 @@ class Class_WebService_SIGB_EmprunteurCache {
return $this;
}
}
?>
\ No newline at end of file
......@@ -110,7 +110,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
return;
}
return parent::_redirect($url, $options);
parent::_redirect($url, $options);
}
......@@ -235,14 +235,14 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
public function _redirectToReferer() {
return $this->_redirect($this->_getReferer());
$this->_redirect($this->_getReferer());
}
public function _redirectToUrlOrReferer($url) {
return $this->_redirect($this->_getParam('redirect') == 'referer'
? $this->_getReferer()
: $url);
$this->_redirect($this->_getParam('redirect') == 'referer'
? $this->_getReferer()
: $url);
}
......
......@@ -59,7 +59,7 @@ class Intonation_View_RenderUserBadges extends ZendAfi_View_Helper_BaseHelper {
? 'success'
: 'danger';
$validity_class = $subscription->isILSAboutToExpire()
$validity_class = $subscription->isAboutToExpire()
? 'warning'
: $validity_class;
......
......@@ -1613,7 +1613,7 @@ abstract class PnbDilicomViewHelperRenderAlbumTestCase extends ViewHelperTestCas
$this->book = (new DilicomFixtures())->albumTotemThora();
RessourcesNumeriquesFixtures::activateDilicom();
$this->_http = Storm_Test_ObjectWrapper::mock();
$this->_http = $this->mock();
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http);
$this->_time_source = new TimeSourceForTest('2014-05-02 14:14:14');
......@@ -1660,7 +1660,8 @@ class PnbDilicomViewHelperRenderAlbumPNBNotLoggedTest extends PnbDilicomViewHelp
class PnbDilicomViewHelperRenderAlbumPNBLoggedButNotAuthorizeTest extends PnbDilicomViewHelperRenderAlbumTestCase {
class PnbDilicomViewHelperRenderAlbumPNBLoggedButNotAuthorizeTest
extends PnbDilicomViewHelperRenderAlbumTestCase {
public function setUp() {
parent::setUp();
......@@ -1782,6 +1783,78 @@ class PnbDilicomViewHelperRenderAlbumPNBTest extends PnbDilicomViewHelperRenderA
class PnbDilicomViewHelperRenderAlbumPNBLoggedButBlockedTest
extends PnbDilicomViewHelperRenderAlbumTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_Bib', ['id' => 1,
'libelle' => 'Annecy',
'gln' => '333']);
$group = $this->fixture('Class_UserGroup',
['id' => '20',
'libelle' => 'Dilicom',
'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]]);
$this->logged_user = $this
->fixture('Class_Users',
['id' => 6,
'nom'=>'Pito',
'login'=>'Chat',
'password'=>'123456',
'id_site' => 1,
'int_bib' => $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => ['url_serveur' => 'tests/fixtures/orphee.wsdl',
'allow_hold_available_items' => true]]),
'idabon' => '12345',
'user_groups' => [$group]]);
Class_WebService_SIGB_Orphee::setService($this->mock()
->whenCalled('isConnected')->answers(true)
->whenCalled('getEmprunteur')
->answers(Class_WebService_SIGB_Emprunteur::nullInstance()->beBlocked())
);
$this->logged_user->beAbonneSIGB()->assertSave();
ZendAfi_Auth::getInstance()->logUser($this->logged_user);
$this->fixture('Class_Loan_Pnb', ['id' => 1,
'record_origin_id' => 'Dilicom-88817216',
'user_id' => '6']);
$this->_html = $this->_helper->renderAlbum($this->book);
}
public function tearDown() {
unset($_SERVER['HTTPS']);
Class_WebService_SIGB_Orphee::setService(null);
parent::tearDown();
}
/** @test */
public function htmlShouldContainsIFrameOnEdenBook() {
$this->assertXPath($this->_html,
'//iframe[@src="http://www.edenlivres.fr/p/23416"][@width="100%"][@height="600px"]',
$this->_html);
}
/** @test */
public function htmlShouldContainsNotAuthorizedMessage() {
$this->assertXPathContentContains($this->_html, '//div', 'Vous n\'avez pas le droit');
}
}
class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomViewHelperRenderAlbumTestCase {
public function setUp() {
......@@ -1916,6 +1989,116 @@ class PnbDilicomViewHelperRenderAlbumPNBGetLoanStatusTest extends PnbDilicomView
class PnbDilicomBibNumeriqueControllerBlockedUserTest extends AbstractControllerTestCase {
protected
$_http,
$_book,
$_time_source,
$_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = '/viewnotice/id/3';
$this->fixture('Class_Bib', ['id' => 1, 'gln' => '2345889']);
Class_AdminVar::set('DILICOM_PNB_MAX_LOAN_DURATION', 0);
Class_WebService_BibNumerique_Dilicom_Hub::setPhpCommand($this->mock()->whenCalled('rand')->answers('1930')
->whenCalled('hash')->answers('10'));
$group = $this->fixture('Class_UserGroup', ['id' => '20',
'libelle' => 'Dilicom',
'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]]);
$logged_user = $this->fixture('Class_Users',
['id' => 6,
'nom'=>'Pito',
'login'=>'Chat',
'password'=>'123456',
'id_site' => 1,
'int_bib' => $this->fixture('Class_IntBib',
['id' => 1,
'comm_sigb' => Class_IntBib::COM_ORPHEE,
'comm_params' => ['url_serveur' => 'tests/fixtures/orphee.wsdl',
'allow_hold_available_items' => true]]),
'idabon' => '12345',
'user_groups' => [$group]]);
Class_WebService_SIGB_Orphee::setService($this->mock()
->whenCalled('isConnected')->answers(true)
->whenCalled('getEmprunteur')
->answers(Class_WebService_SIGB_Emprunteur::nullInstance()->beBlocked())
);
$logged_user->beAbonneSIGB()->assertSave();
ZendAfi_Auth::getInstance()->logUser($logged_user);
$this->_book = (new DilicomFixtures)->albumTotemThora();
RessourcesNumeriquesFixtures::activateDilicom();
$this->_http = $this->mock();
Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http);
$this->_time_source = new TimeSourceForTest('2014-05-02 14:14:14');
Class_WebService_BibNumerique_Dilicom_Hub::setTimeSource($this->_time_source);
Class_Album_UsageConstraint::setTimeSource($this->_time_source);
Class_Album_UsageConstraints::setTimeSource($this->_time_source);
Class_Loan_Pnb::setTimeSource($this->_time_source);
}
public function tearDown() {
Class_WebService_BibNumerique_Dilicom_Hub::setTimeSource(null);
Class_Album_UsageConstraint::setTimeSource(null);
Class_Loan_Pnb::setTimeSource(null);
RessourcesNumeriquesFixtures::deactivateDilicom();
Class_WebService_SIGB_Orphee::setService(null);
parent::tearDown();
}
/** @test */
public function shouldNotBeAbleToConsult() {
$this->dispatch('/bib-numerique/consult-book/id/3', true);
$this->assertRedirect($this->_response->getBody());
}
/** @test */
public function shouldNotBeAbleToConsultAjax() {
$this->dispatch('/bib-numerique/consult-book-ajax/id/3', true);
$this->assertContains('location.href=', $this->_response->getBody());
}
/** @test */
public function shouldNotBeAbleToLoan() {
$this->dispatch('/bib-numerique/loan-book/id/3', true);
$this->assertRedirect($this->_response->getBody());
}
/** @test */
public function shouldNotBeAbleToLoanAjax() {
$this->dispatch('/bib-numerique/loan-book-ajax/id/3', true);
$this->assertContains('location.href=', $this->_response->getBody());
}