diff --git a/VERSIONS_HOTLINE/111520 b/VERSIONS_HOTLINE/111520 new file mode 100644 index 0000000000000000000000000000000000000000..a400262b9ad7f3776d01000bb5ef6cf9cd44e324 --- /dev/null +++ b/VERSIONS_HOTLINE/111520 @@ -0,0 +1 @@ +hotline#111520 : Drive : Correction de l'affichage des réservations dans l'interface administrateur lorsque l'option LOGIN_THROUGH_SIGB_ONLY est activée \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php index 06fc7bbe3d046b70a055f2fc037545dd79eb0293..168ea86d1c823f481c15f79a5894bd53629c5308 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -207,12 +207,7 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR if(!$user) return Class_WebService_SIGB_Emprunteur::nullInstance(); - $patron_id = Class_Users::isLogged($user) - ? $user->getIdSigb() - : ''; - - if(!$patron_id) - $patron_id = $this->_authenticateWebservice($user); + $patron_id = $this->_patronIdFromUser($user); if (!$patron_id) return Class_WebService_SIGB_Emprunteur::nullInstance(); @@ -222,6 +217,21 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR } + protected function _patronIdFromUser($user) { + if (Class_Users::isCurrentUserCanAccesBackend() && $user->getIdSigb()) + return $user->getIdSigb(); + + $patron_id = Class_Users::isLogged($user) + ? $user->getIdSigb() + : ''; + + if (!$patron_id) + return $this->_authenticateWebservice($user); + + return $patron_id; + } + + public function getUserAnnexe($user) { return null; } diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index 6393634b405351136433b4708b876ecfc08a1946..0f5859a744e055b9ea376fe8ff5678782656c238 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -128,6 +128,9 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac protected function _patronIdFromUser($user) { + if (Class_Users::isCurrentUserCanAccesBackend() && $user->getIdSigb()) + return $user->getIdSigb(); + $patron_id = Class_Users::isLogged($user) ? $user->getIdSigb() : ''; diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php index e6c78064481ef49c012d9c3f564d47ab8f804652..02d9f95a5f9c30df49435326167ddb4bf17eb382 100644 --- a/tests/library/Class/WebService/SIGB/KohaTest.php +++ b/tests/library/Class/WebService/SIGB/KohaTest.php @@ -32,6 +32,13 @@ class KohaGetServiceTest extends ModelTestCase { } + public function tearDown() { + Class_WebService_SIGB_Koha::reset(); + parent::tearDown(); + } + + + /** @test */ public function getServiceShouldCreateAnInstanceOfKohaService() { $this->assertInstanceOf('Class_WebService_SIGB_Koha_Service', @@ -102,6 +109,12 @@ abstract class KohaTestCase extends ModelTestCase { $this->service = Class_WebService_SIGB_Koha::getService(['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl']); $this->service->setWebClient($this->mock_web_client); } + + + public function tearDown() { + Class_WebService_SIGB_Koha::reset(); + parent::tearDown(); + } } @@ -722,17 +735,11 @@ class KohaGetEmprunteurLaureAfondTest extends KohaTestCase { -class KohaGetEmprunteurLisianneWithIdSIGBTest extends KohaTestCase { +abstract class KohaGetEmprunteurLisianneWithIdSIGBTestCase extends KohaTestCase { public function setUp() { parent::setUp(); $this->mock_web_client - ->whenCalled('postData') - ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', - [ 'service' => 'AuthenticatePatron', - 'username' => 'lisianne', - 'password' => 'zork']) - ->answers(KohaFixtures::xmlLookupPatronLisianne()) ->whenCalled('open_url') ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=GetPatronInfo&patron_id=16186&show_contact=1&show_loans=0&show_holds=1') ->answers(file_get_contents(__DIR__ . '/holds-koha.xml')) @@ -744,15 +751,65 @@ class KohaGetEmprunteurLisianneWithIdSIGBTest extends KohaTestCase { $this->fixture('Class_CodifAnnexe', ['id' => 33, 'libelle' => 'Testing branch', 'id_origine' => 'BIB']); + + $this->lisianne_user = $this->fixture('Class_Users', + ['id' => 43, + 'login' => 'lisianne', + 'password' => 'zork', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => 'lisianne', + 'id_site' => 3, + 'id_sigb' => 'lisianne']); + + } +} + + + + +class KohaGetEmprunteurLisianneWithUserAdminTest extends KohaGetEmprunteurLisianneWithIdSIGBTestCase { + public function setUp() { + parent::setUp(); + $this->lisianne_user + ->setPassword('') + ->setIdSigb(16186) + ->save(); + + Class_AdminVar::set('LOGIN_THROUGH_SIGB_ONLY',1); + $admin = $this->fixture('Class_Users', + ['id' => 38, + 'login' => 'admin', + 'password' => '1234', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL]); + ZendAfi_Auth::getInstance()->logUser($admin); + $this->lisianne = $this->service - ->getEmprunteur($this->fixture('Class_Users', - ['id' => 43, - 'login' => 'lisianne', - 'password' => 'zork', - 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, - 'idabon' => 'lisianne', - 'id_site' => 3, - 'id_sigb' => 'lisianne'])); + ->getEmprunteur($this->lisianne_user); + } + + /** @test */ + public function nbReservationsShouldReturnFive() { + $this->assertEquals(5, $this->lisianne->getNbReservations()); + } +} + + + + +class KohaGetEmprunteurLisianneWithIdSIGBTest extends KohaGetEmprunteurLisianneWithIdSIGBTestCase { + public function setUp() { + parent::setUp(); + + $this->mock_web_client + ->whenCalled('postData') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', + [ 'service' => 'AuthenticatePatron', + 'username' => 'lisianne', + 'password' => 'zork']) + ->answers(KohaFixtures::xmlLookupPatronLisianne()); + + $this->lisianne = $this->service + ->getEmprunteur($this->lisianne_user); } diff --git a/tests/library/Class/WebService/SIGB/NanookTest.php b/tests/library/Class/WebService/SIGB/NanookTest.php index 678e6789eed405d08e742f325dda1e1113e69bd7..7c2cec3de7f139d56b947dcc8303af8bf7d17032 100644 --- a/tests/library/Class/WebService/SIGB/NanookTest.php +++ b/tests/library/Class/WebService/SIGB/NanookTest.php @@ -451,7 +451,9 @@ class NanookGetUserAnnexeTest extends NanookTestCase { } -class NanookGetEmprunteurChristelDelpeyrouxTest extends NanookTestCase { + + +abstract class NanookGetEmprunteurChristelDelpeyrouxTestCase extends NanookTestCase { /** @var Class_WebService_SIGB_Emprunteur */ protected $_emprunteur; @@ -460,9 +462,6 @@ class NanookGetEmprunteurChristelDelpeyrouxTest extends NanookTestCase { parent::setUp(); $this->_mock_web_client - ->whenCalled('open_url') - ->with('http://localhost:8080/afi_Nanook/ilsdi/service/AuthenticatePatron/username/8765/password/2002') - ->answers(NanookFixtures::xmlAuthenticatePatronChristelDelpeyroux()) ->whenCalled('open_url') ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPatronInfo/patronId/1') @@ -472,13 +471,52 @@ class NanookGetEmprunteurChristelDelpeyrouxTest extends NanookTestCase { 'login' => 8765, 'password' => 2002, 'id_site' => 3]); - $this->_emprunteur = $this->_service->getEmprunteur($this->_chrystel); - $this->_emprunteur->updateUser($this->_chrystel); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') ->whenCalled('findFirstBy') ->answers(null); } +} + + + + +class NanookGetEmprunteurChristelDelpeyrouxAsAdminTest extends NanookGetEmprunteurChristelDelpeyrouxTestCase { + public function setUp() { + parent::setUp(); + $this->_chrystel->setPassword(''); + Class_AdminVar::set('LOGIN_THROUGH_SIGB_ONLY',1); + $admin = $this->fixture('Class_Users', + [ + 'id'=> 38, + 'login'=> 'admin', + 'password' => '1234', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL + ]); + ZendAfi_Auth::getInstance()->logUser($admin); + $this->_emprunteur = $this->_service->getEmprunteur($this->_chrystel); + } + + /** @test */ + public function nbReservationsShouldBeFour() { + $this->assertEquals(4, $this->_emprunteur->getNbReservations()); + } +} + + + + +class NanookGetEmprunteurChristelDelpeyrouxTest extends NanookGetEmprunteurChristelDelpeyrouxTestCase { + public function setUp() { + parent::setUp(); + $this->_mock_web_client + ->whenCalled('open_url') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/AuthenticatePatron/username/8765/password/2002') + ->answers(NanookFixtures::xmlAuthenticatePatronChristelDelpeyroux()); + + $this->_emprunteur = $this->_service->getEmprunteur($this->_chrystel); + $this->_emprunteur->updateUser($this->_chrystel); + } /** @test */