Commit 9671dc85 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72845 add anonymous access

parent 3a980587
......@@ -197,7 +197,7 @@ class Class_DigitalResource_Config extends Class_Entity {
}
public function urlFor($user, $params=[]) {
public function urlFor($user, $params = []) {
if(!$user)
return;
......
......@@ -52,7 +52,8 @@ class Cvs_Config extends Class_DigitalResource_Config {
'SOURCEKEY' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'SOURCEPASSWORD' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'LOGINTEST' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'API_URL' => Class_AdminVar_Meta::newDefault($this->_('Url de l\'API'), ['value' => 'http://stream.cvs-mediatheques.com/api/partners.php'])->bePrivate()
'API_URL' => Class_AdminVar_Meta::newDefault($this->_('Url de l\'API'), ['value' => 'http://stream.cvs-mediatheques.com/api/partners.php'])->bePrivate(),
'ANONYMOUS_ACCESS' => Class_AdminVar_Meta::newOnOff($this->_('Authoriser l\'accès aux visiteurs anonymes'))->bePrivate()
],
];
}
......@@ -74,6 +75,9 @@ class Cvs_Config extends Class_DigitalResource_Config {
public function hasRightAccess($user) {
if ($this->getAdminVar('ANONYMOUS_ACCESS'))
return true;
if (!$user)
return true == (boolean) $this->getAdminVar('LOGINTEST');
......
......@@ -129,14 +129,14 @@ class Cvs_Service {
}
protected function _getUser() {
public function getUser() {
$user = $this->_user
? $this->_user
: Class_Users::getIdentity();
return $user
? $user
: Class_Users::newInstance(['login' => $this->_config->getAdminVar('LOGINTEST')]);
: Class_Users::newInstance(['login' => $this->_var('LOGINTEST')]);
}
......@@ -166,7 +166,7 @@ class Cvs_Service {
protected function _getLogin() {
$user = $this->_getUser();
$user = $this->getUser();
return $user->getIdabon() ? $user->getIdabon() : $user->getLogin();
}
......@@ -190,7 +190,6 @@ class Cvs_Service {
$header->appendChild($xml->createElement($key, $value));
$closure($xml, $params);
// : $this->_searchAction($xml, $params);
$this->_appendUser($xml);
......@@ -226,7 +225,7 @@ class Cvs_Service {
protected function _appendUser($xml) {
$user = $this->_getUser();
$user = $this->getUser();
$user_data = array_filter(['login' => $user->getLogin(),
'nom' => $user->getNom(),
......
......@@ -20,4 +20,19 @@
*/
class Cvs_Plugin_IndexController extends Class_DigitalResource_Controller {}
\ No newline at end of file
class Cvs_Plugin_IndexController extends Class_DigitalResource_Controller {
public function ssoAction() {
if((!$this->_config->getAdminVar('ANONYMOUS_ACCESS')))
return parent::ssoAction();
$user = ($user = Class_Users::getIdentity())
? $user
: (new Cvs_Service)->getUser();
$url = $this->_config->urlFor($user, $this->_request->getParams());
return $url
? $this->_javascriptRedirectTo($url)
: $this->_redirectToIndex($this->_config->getNotAllowedMessage());
}
}
\ No newline at end of file
......@@ -941,4 +941,102 @@ class CvsServiceWithBorrowerAndLibraryLabelTest extends CvsActivatedTestCase {
$this->assertEquals('http://montauban.cvs-mediatheques.com/?ln=musique&con=01255712bd8d68e9e08fe3ff1dadc57a&if=0',
$this->_cvs->getSiteAccessFor(Class_Users::getIdentity()));
}
}
\ No newline at end of file
}
class CvsSearchWithAnonymousAccessTest extends CvsActivatedTestCase {
protected $_cvs;
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->clearIdentity();
Class_AdminVar::set('Cvs_ANONYMOUS_ACCESS', 1);
$this->_cvs = new Cvs_Service;
$http_client = $this
->mock()
->whenCalled('postData')
->with(Class_AdminVar::get('Cvs_API_URL'),
['xml' => $this->_expectedXML()])
->answers($this->_returnedXML())
->beStrict();
Class_WebService_Abstract::setHttpClient($http_client);
}
protected function _expectedXML() {
$xml = '<?xml version="1.0" encoding="utf-8"?>
<albums>
<header>
<bmid>22223</bmid>
<sourceid>22225</sourceid>
<key>73844495168ecc1aa59ba96c8cea6e82</key>
<time>1369640315</time>
<adhid>cvs_login_test</adhid>
<action>search_document</action>
</header>
<body>
<q><![CDATA[ecole]]></q>
<espace><![CDATA[]]></espace>
<classement><![CDATA[consultes]]></classement>
<page><![CDATA[1]]></page>
<nombre_par_page><![CDATA[5]]></nombre_par_page>
<login>cvs_login_test</login>
</body>
</albums>';
$dom = $this->_cvs->createDomDocument();
$dom->loadXML($xml);
return $this->_cvs->getEncodedXML($dom->saveXML());
}
protected function _returnedXML() {
return file_get_contents(__DIR__ . '/cvs_search_ecole.xml');
}
/** @test */
public function searchEcoleShouldReturnTitleForFirstNoticeEtreEtAvoir() {
$result = $this->_cvs->find('ecole', 1, 5);
$this->assertEquals('Etre et avoir',
$result->getRecords()[0]->getTitrePrincipal());
}
}
class CvsSsoAnonymousAccessTest extends CvsActivatedTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('Cvs_ANONYMOUS_ACCESS', 1);
ZendAfi_Auth::getInstance()->clearIdentity();
}
/** @test */
public function shouldRedirectToCvs() {
$this->dispatch('/opac/modules/cvs', true);
$this->assertXPathContentContains('//script',
'document.location.href="https://rayonnages',
$this->_response->getBody());
}
/** @test */
public function shouldRedirectToAlbum() {
$this->dispatch('/opac/modules/cvs?docid=135', true);
$this->assertXPathContentContains('//script',
'#album&docid=135',
$this->_response->getBody());
}
}
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