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

hotline #66771 : do not erase user information from file import when...

hotline #66771 : do not erase user information from file import when webservice does not provide them
parent eb819a05
- ticket #66771 : Compte Abonné : Correction de l'effacement de certaines informations de compte lors de l'identification par webservice
\ No newline at end of file
......@@ -219,27 +219,6 @@ class UsersLoader extends Storm_Model_Loader {
}
public function mapUser($destination, $source) {
$destination
->setIdSigb($source->getIdSigb())
->setIdabon($source->getIdabon())
->setNom($source->getNom())
->setPrenom($source->getPrenom())
->setMail($source->getMail())
->setIsContactMail($source->getIsContactMail())
->setIsContactSms($source->getIsContactSms())
->setDateFin($source->getDateFin())
->setAdresse($source->getAdresse())
->setCodePostal($source->getCodePostal())
->setVille($source->getVille())
->setOrdreabon($source->getOrdreabon())
->setTelephone($source->getTelephone())
->setNaissance($source->getNaissance())
->setIdSite($source->getIdSite())
->setIdIntBib($source->getIdIntBib());
}
public function findBlowfish($login) {
$crypt = new Class_Crypt();
return array_filter(
......@@ -1533,12 +1512,6 @@ class Class_Users extends Storm_Model_Abstract {
}
public function updateUser($source) {
Class_Users::getLoader()->mapUser($this, $source);
return $this;
}
public function canModifyPanier($panier) {
if (!$panier || $panier->isNew())
return true;
......
......@@ -61,17 +61,49 @@ class ZendAfi_Auth_Adapter_CommSigb implements Zend_Auth_Adapter_Interface {
if(!$user_from_sigb)
return null;
return $this->_getUserToSave($user_from_sigb)
->beAbonneSIGB()
->setLogin($this->_identity)
->setPassword($this->_credential)
->updateUser($user_from_sigb);
$user_to_save = $this->_getUserToSave($user_from_sigb)
->beAbonneSIGB()
->setLogin($this->_identity)
->setPassword($this->_credential);
$this->_updateOptionalAttribs($user_from_sigb, $user_to_save);
return $user_to_save;
}
protected function _updateOptionalAttribs($from, $to) {
$attribs = ['id_sigb',
'idabon',
'nom',
'prenom',
'mail',
'is_contact_mail',
'is_contact_sms',
'date_fin',
'adresse',
'code_postal',
'ville',
'ordreabon',
'telephone',
'naissance',
'id_site',
'id_int_bib'];
foreach($attribs as $attrib)
$this->_updateAttribIfNotEmpty($from, $to, $attrib);
}
protected function _updateAttribIfNotEmpty($from, $to, $attrib) {
if ($value = $from->callGetterByAttributeName($attrib))
$to->callSetterByAttributeName($attrib, $value);
}
protected function _getUserToSave($user_from_sigb) {
$finder = new Class_User_DoubleFinder($user_from_sigb);
return ($finder->find())
return $finder->find()
? $finder->getDouble()
: Class_Users::newInstance()->setLogin($this->_identity);
}
......
......@@ -33,7 +33,17 @@ abstract class AuthCommSigbTestCase extends ModelTestCase {
'role_level' => 2,
'id_site' => 2,
'id_int_bib' => 2,
'password' => 'xzy']);
'password' => 'xzy',
'id_sigb' => '7788',
'nom' => 'zork',
'prenom' => 'krog',
'mail' => 'zork.krog@zork.me',
'adresse' => '1 sesame street',
'code_postal' => '67883',
'ville' => 'Cloudy Cloud',
'ordreabon' => 3,
'telephone' => '0123456789',
'naissance' => '01-01-1934']);
$this->onLoaderOfModel('Class_Users');
}
......@@ -484,4 +494,76 @@ class AuthCommSigbAuthenticationSetupInvalidUserTest
}
}
?>
\ No newline at end of file
/** @see http://forge.afi-sa.fr/issues/66771 */
class AuthCommSigbWithWebServicesAndAbonneZorkAndMinimalResponseTest
extends AuthCommSigbTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_IntBib',
['id' => 74,
'comm_sigb' => Class_IntBib::COM_OPSYS,
'nom_court' => 'TestingOpsys']);
$this->fixture('Class_IntMajAuto',
['id' => 100,
'id_bib' => 74,
'profil' => 57]);
$this->fixture('Class_IntProfilDonnees',
['id' => 57,
'libelle' => 'Some patrons',
'type_fichier' => Class_IntProfilDonnees::FT_PATRONS]);
Class_WebService_SIGB_Opsys::setService($this->opsys = $this->mock());
$annecy_library = $this->fixture('Class_Bib',
['id' => 43,
'libelle' => 'annecy']);
$annecy_annexe = $this->fixture('Class_CodifAnnexe',
['id' => 42,
'id_origine' => 'ANN',
'bib' => $annecy_library]);
$this->opsys
->whenCalled('getEmprunteur')
->answers(Class_WebService_SIGB_Emprunteur::newInstance('7788')
->setNom('Zork')
->setPrenom('Zinn')
->setPassword('xzy')
->setTelephone('')
->beValid());
$this->_zork->setIdIntBib(74)
->setIdSite(43)
->save();
$this->_adapter = (new ZendAfi_Auth_Adapter_CommSigb())
->setIdentity('zork_sigb')
->setCredential('xzy');
$this->_result = $this->_adapter->authenticate();
}
public function tearDown() {
Class_WebService_SIGB_Opsys::setService(null);
parent::tearDown();
}
/** @test */
public function dateFinShouldNotBeEmpty() {
$this->assertNotEmpty($this->_zork->getDateFin());
}
/** @test */
public function prenomShouldBecomeZinn() {
$this->assertEquals('Zinn', $this->_zork->getPrenom());
}
}
\ 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