Commit b8cae5e7 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #59224 fix rt comments

parent 5c342a3c
Pipeline #4030 failed with stage
in 33 minutes and 54 seconds
......@@ -605,8 +605,6 @@ class AbonneController extends ZendAfi_Controller_Action {
->setPassword($password)
->setNewsletters($newsletters);
$this->_updatePasswordInILS();
if ($this->_user->save()) {
$this->_helper->notify($this->_('Vos modifications ont bien été enregistrées'));
$this->_redirect('/abonne/fiche');
......@@ -622,14 +620,6 @@ class AbonneController extends ZendAfi_Controller_Action {
}
protected function _updatePasswordInILS() {
if(!$comm = $this->_user->getSIGBComm())
return;
$comm->changePasswordOfBy($this->_user, $this->_user->getPassword());
}
public function authenticateAction() {
$this->getHelper('ViewRenderer')->setNoRender();
......
......@@ -104,6 +104,11 @@ abstract class Class_WebService_SIGB_AbstractService {
}
public function providesChangePasswordService() {
return false;
}
public function pickupLocationsFor($user, $item) {
return [];
}
......@@ -199,9 +204,6 @@ abstract class Class_WebService_SIGB_AbstractService {
}
public function changePasswordOfBy($user, $new_password) {}
abstract public function getServerRoot();
abstract public function getEmprunteur($user);
......
......@@ -141,27 +141,12 @@ class Class_WebService_SIGB_Koha_RestfulService
}
public function changePasswordOfBy($user, $new_password) {
if(!$user)
return;
public function saveEmprunteur($emprunteur) {
$this->restfulPut('auth/change_password',
['user_name' => $emprunteur->getId(),
'new_password' => $emprunteur->getPassword()]);
if(!$new_password)
return;
$response = $this->restfulPut('auth/change_password',
['user_name' => $user->getLogin(),
'new_password' => $new_password]);
if (null === ($json = json_decode($response, true)))
throw new Class_WebService_Exception($this->_('Échec de la connexion au webservice, le SIGB a répondu "%s"',
trim($response)));
$json = reset($json);
if (!array_key_exists('success', $json))
throw new Class_WebService_Exception($this->_('Échec du changement de mot de passe le SIGB à répondu "%s"',
trim($response)));
return $this->_success();
return $emprunteur;
}
......
......@@ -259,12 +259,6 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
}
public function changePasswordOfBy($user, $new_password) {
return $this->providesChangePasswordService()
? $this->getRestfulService()->changePasswordOfBy($user, $new_password)
: null;
}
public function getRestfulService() {
return Class_WebService_SIGB_Koha_RestfulService::newFromIlsdi($this);
......@@ -330,4 +324,11 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
->getRestfulService()
->branches($int_bib);
}
public function saveEmprunteur($emprunteur) {
return $this->providesChangePasswordService()
? $this->getRestfulService()->saveEmprunteur($emprunteur)
: parent::saveEmprunteur($emprunteur);
}
}
\ No newline at end of file
......@@ -59,6 +59,12 @@ class AbonneControllerChangePasswordOnKohaTest extends AbstractControllerTestCas
$sigb_comm = Class_IntBib::find(3)->getSIGBComm();
$sigb_comm->setWebClient($mock_web_client);
$borrower = new Class_WebService_SIGB_Emprunteur('ml34', 'ml34');
$koha_user->setFicheSigb(['type_comm' => Class_IntBib::COM_KOHA,
'fiche' => $borrower]);
ZendAfi_Auth::getInstance()->logUser($koha_user);
$logger = $this->mock()
......@@ -117,6 +123,12 @@ class AbonneControllerChangePasswordOnNanookTest extends AbstractControllerTestC
'idabon' => '123456',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
$borrower = new Class_WebService_SIGB_Emprunteur('ml34', 'ml34');
$nanook_user->setFicheSigb(['type_comm' => Class_IntBib::COM_KOHA,
'fiche' => $borrower]);
$mock_web_client = $this->mock()
->whenCalled('open_url')
->with('http://plage.com/cgi-bin/nanook/ilsdi.pl/service/AuthenticatePatron/username/ml34/password/achanger')
......
......@@ -436,11 +436,18 @@ class KohaRestGetUserHistoryTest extends KohaRestfulTestCase {
class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
public function setUp() {
parent::setUp();
$borrower = new Class_WebService_SIGB_Emprunteur('1', 'harlock');
$borrower->setService($this->service);
$user = $this->fixture('Class_Users',
['id' => 34,
'login' => 'harlock',
'password' => 'arcadia',
'idabon' => 'AO989IE']);
$user->setFicheSIGB(['fiche' => $borrower]);
$this->mock_web_client
->whenCalled('putData')
->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/rest.pl/auth/change_password',
......@@ -448,13 +455,15 @@ class KohaRestfulChangePasswordTest extends KohaRestfulTestCase {
'new_password' => 'ce1snm2p'])
->answers(json_encode([['success' => ['password' => '$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK']]]))
->beStrict();
$this->response = $this->service->changePasswordOfBy($user, 'ce1snm2p');
$user
->setPassword('ce1snm2p')
->save();
}
/** @test */
public function responseShouldReturnSuccess() {
$this->assertEquals(['statut' => true,
'erreur' => ''], $this->response);
public function userPasswordShouldBeCe1snm2p() {
$this->assertEquals('ce1snm2p', Class_Users::find(34)->getPassword());
}
}
\ No newline at end of file
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