Commit 29001a18 authored by efalcy's avatar efalcy Committed by Patrick Barroca

hotline #108047 : numeric resources : allow guest and non validity date for users to access

parent f19c48a0
Pipeline #9710 passed with stage
in 42 minutes and 25 seconds
- ticket #108047 : Ressources numériques : autoriser l'accès aux non abonnés et aux abonnés n'ayant pas de date de fin d'abonnement
\ No newline at end of file
......@@ -76,7 +76,7 @@ class Class_ArteVodLink {
'nom' => $this->_user->getNom(),
'email' => $this->_user->getMail(),
'dnaiss' => $this->_user->getNaissance(),
'datout' => $this->_user->getDateFin(),
'datout' => $this->_user->getValidSubscriptionEndDate(),
'return_url' => $this->baseUrl(),
'referer' => Class_Url::getProtocol(). Class_AdminVar::getNomDomaine()];
......
......@@ -152,9 +152,6 @@ class Class_DigitalResource extends Class_Entity {
if (!$this->isPluginDocType($plugin))
return false;
if ($user->isAbonne() && !$user->isAbonnementValid())
return false;
if(!$this->hasPermissionOn($plugin, $user))
return false;
......
......@@ -92,10 +92,11 @@ class Class_User_SearchCriteriaValidSubscription extends Class_SearchCriteria_Ab
}
public function modelMatch($user) {
return $user->isAbonne()
? $user->isAbonnementValid()
: true;
public function modelMatch($model) {
if (!$this->_should_filter)
return true;
return $model->isValid();
}
......
......@@ -874,13 +874,6 @@ class Class_Users extends Storm_Model_Abstract {
}
public function isAbonneAndHasRightToAccess($access_name) {
if ($this->isAbonne() && !$this->isAbonnementValid())
return false;
return $this->hasRightToAccess($access_name);
}
/**
* @return array
*/
......@@ -965,57 +958,57 @@ class Class_Users extends Storm_Model_Abstract {
* @return bool
*/
public function hasRightAccessNumeriquePremium() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_NUMERIQUEPREMIUM);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_NUMERIQUEPREMIUM);
}
public function hasRightAccesArteVod() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_ARTEVOD);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_ARTEVOD);
}
public function hasRightAccesNumilog() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_NUMILOG);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_NUMILOG);
}
public function hasRightAccesVodeclic() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_VODECLIC);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_VODECLIC);
}
public function hasRightAccessCyberlibris() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_CYBERLIBRIS);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_CYBERLIBRIS);
}
public function hasRightAccessCiteDeLaMusique() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCESS_CITEDELAMUSIQUE);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCESS_CITEDELAMUSIQUE);
}
public function hasRightAccessMyCow() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_MYCOW);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_MYCOW);
}
public function hasRightAccessPlanetNemo() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_PLANETNEMO);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_PLANETNEMO);
}
public function hasRightAccesKidilangues() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_KIDILANGUES);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_KIDILANGUES);
}
public function hasRightAccessDilicom() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCES_PNB_DILICOM);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCES_PNB_DILICOM);
}
public function hasRightAccessLeSocial() {
return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCESS_LESOCIAL);
return $this->hasRightToAccess(Class_UserGroup::RIGHT_ACCESS_LESOCIAL);
}
......@@ -1930,4 +1923,11 @@ class Class_Users extends Storm_Model_Abstract {
$this->save();
return $this;
}
public function getValidSubscriptionEndDate() {
if ($this->getDateFin() && ($this->getDateFin()) > ($this->getCurrentDate()))
return $this->getDateFin();
return $this->addDaysToCurrentDate(30);
}
}
......@@ -236,9 +236,7 @@ class Cvs_Service {
'dnaiss' => (($naissance = $user->getNaissance())
? Class_Date::frToIso($naissance)
: ''),
'datout' => (($finabo = $user->getDateFin())
? Class_Date::frToIso($finabo)
: ''),
'datout' => Class_Date::frToIso($user->getValidSubscriptionEndDate()),
'bibliotheque' => (($label = $this->_var('BMLABEL'))
? $label : $user->getLibelleBib())]);
......
......@@ -29,6 +29,7 @@ abstract class CvsActivatedTestCase extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
Class_AdminVar::set('Cvs_BMKEY', '22222');
Class_AdminVar::set('Cvs_BMID', '22223');
......@@ -648,6 +649,7 @@ class CvsSearchWithDemoAccountTest extends CvsActivatedTestCase {
<page><![CDATA[1]]></page>
<nombre_par_page><![CDATA[5]]></nombre_par_page>
<login>cvs_login_test</login>
<datout>2020-04-09</datout>
</body>
</albums>';
......@@ -792,6 +794,100 @@ l’école primaire, l’adaptation du matériel aux pratiques pédagogiques.',
class CvsSearchWithJerryExpiredLoggedTest extends CvsActivatedTestCase {
protected
$_cvs,
$_result;
public function setUp() {
parent::setUp();
$jerry = $this->fixture('Class_Users',
['id' => 4,
'idabon' => 34,
'login' => 34,
'pseudo' => 'J&Khan',
'prenom' => 'Jerry',
'nom' => 'Khan',
'mail' => 'feu@essence.fr',
'password' => 'secret',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'id_site' => 1,
'date_fin' => '2000-09-02',
'naissance' => '1977-06-27']);
$jerry->setBib($this->fixture('Class_Bib',
['id' => 34,
'libelle' => 'Annecy']));
ZendAfi_Auth::getInstance()->logUser($jerry);
$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);
$this->_result = $this->_cvs->find('ecole', 1, 5);
}
protected function _expectedXML() {
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<albums>
<header>
<bmid>22223</bmid>
<sourceid>22225</sourceid>
<key>d0a1b72e8e6d7af27d400e2009c1a873</key>
<time>1369640315</time>
<adhid>34</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>34</login>
<nom>Khan</nom>
<prenom>Jerry</prenom>
<pseudo>J&amp;Khan</pseudo>
<password>secret</password>
<email>feu@essence.fr</email>
<dnaiss>1977-06-27</dnaiss>
<datout>2020-04-09</datout>
<bibliotheque>Annecy</bibliotheque>
</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() {
$this->assertEquals('Etre et avoir',
$this->_result->getRecords()[0]->getTitrePrincipal());
}
}
class CvsLinkWithBorrowerTest extends CvsActivatedTestCase {
protected
......@@ -1036,6 +1132,7 @@ class CvsSearchWithAnonymousAccessTest extends CvsActivatedTestCase {
<page><![CDATA[1]]></page>
<nombre_par_page><![CDATA[5]]></nombre_par_page>
<login>cvs_login_test</login>
<datout>2020-04-09</datout>
</body>
</albums>';
......
......@@ -89,7 +89,7 @@ class LesYeuxDoc_Config extends Class_DigitalResource_Config {
'nom' => $user->getNom(),
'email' => $user->getMail(),
'dnaiss' => ($date = $user->getNaissance()) ? $date : '',
'datout' => $user->getDateFin(),
'datout' => $user->getValidSubscriptionEndDate(),
'return_url' => $return_url];
return $this->getAdminVar('SSO_URL')
......
......@@ -77,6 +77,8 @@ class LesYeuDocDashboardTestCase extends LesYeuxDocActivatedTestCase {
public function setUp() {
parent::setUp();
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
$this->dispatch('/LesYeuxDoc_Plugin', true);
}
......@@ -89,14 +91,14 @@ class LesYeuDocDashboardTestCase extends LesYeuxDocActivatedTestCase {
/** @test */
public function ssoUrlForTestUserShouldBePortalMediathequeNumerique() {
$this->assertContains('<pre>https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=79&id_encrypted=aff73a5e918d0cbefa1077d3468cfcfc03abd9c94b3d827b1b7dd283db2450f9&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=&nom=&email=&dnaiss=&datout=&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr</pre>',
$this->assertContains('<pre>https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=79&id_encrypted=aff73a5e918d0cbefa1077d3468cfcfc03abd9c94b3d827b1b7dd283db2450f9&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=&nom=&email=&dnaiss=&datout=2020-04-09&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr</pre>',
$this->_response->getBody());
}
/** @test */
public function ssoUrlForTestUserAndAlbumOlivierRolinShouldBePortalMediathequeNumerique() {
$this->assertContains('<pre>https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=79&id_encrypted=aff73a5e918d0cbefa1077d3468cfcfc03abd9c94b3d827b1b7dd283db2450f9&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=&nom=&email=&dnaiss=&datout=&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr%2Ffilm%2F703%2Folivier-rolin</pre>',
$this->assertContains('<pre>https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=79&id_encrypted=aff73a5e918d0cbefa1077d3468cfcfc03abd9c94b3d827b1b7dd283db2450f9&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=&nom=&email=&dnaiss=&datout=2020-04-09&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr%2Ffilm%2F703%2Folivier-rolin</pre>',
$this->_response->getBody());
}
}
......@@ -299,6 +301,22 @@ class LesYeuDocModuleSsoTest extends AbstractControllerTestCase {
'document.location.href="http://lesyeuxdoc.com?sso_id=afi&id=2345&id_encrypted=8043a43d11f8daccc5b1a0a5ccbadedd1a3edba6b551c0ca1abaf42e49a36158&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=Jean&nom=Rouch&email=rouch%40ethno.fr&dnaiss=1975-01-01&datout=2023-01-01&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr";',
$this->_response->getBody());
}
/** @test */
public function withExpiredSubscriptionshouldRedirectToLesYeuxDocWithValidDate() {
$this->fixtures->activate();
$this->fixtures->logValidUser();
Class_Users::find(1)->setDateFin('2000-01-01')->save();
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
LesYeuxDoc_Config::setTimeSource(new TimeSourceForTest('2018-28-05 11:50:00'));
$this->dispatch('/opac/modules/les-yeux-doc', true);
$this->assertXpathContentContains('//script',
'document.location.href="http://lesyeuxdoc.com?sso_id=afi&id=2345&id_encrypted=8043a43d11f8daccc5b1a0a5ccbadedd1a3edba6b551c0ca1abaf42e49a36158&d=d0f3e0faa0b2546ea784554bea817f2dcac68a0c5e658ce907af0711e6674e53&prenom=Jean&nom=Rouch&email=rouch%40ethno.fr&dnaiss=1975-01-01&datout=2020-04-09&return_url=https%3A%2F%2Fwww.lesyeuxdoc.fr";',
$this->_response->getBody());
}
}
......
......@@ -34,7 +34,7 @@ class Syracuse_Plugin_AuthController extends Class_DigitalResource_Controller {
$attributes = ['lastname' => $user->getNom(),
'firstname' => $user->getPrenom(),
'mail' => $user->getMail(),
'expire_at' => $user->getDateFin(),
'expire_at' => $user->getValidSubscriptionEndDate(),
'card_number' => $user->getIdabon(),
'site_code' => $user->getLibraryId(),
'site_label' => $user->getLibelleBib(),
......
......@@ -33,6 +33,7 @@ abstract class SyracuseModulesControllerTestCase extends AbstractControllerTestC
$this->fixture('Class_Bib',
['id' => 34,
'libelle' => 'Gresivaudan']);
Class_Users::setTimeSource(new TimeSourceForTest('2019-03-10'));
$this->_user = $this->fixture('Class_Users',
['id' => 10,
......@@ -154,6 +155,22 @@ class SyracuseModulesControllerTest extends SyracuseModulesControllerTestCase {
}
/** @test */
public function withExpiredSubscriptionDateShouldSetValidExpiredDate() {
$tag ='expire_at';
$value = '2020-04-09';
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
$this->_user
->beAbonneSIGB()
->setDateFin('2000-02-12')->save();
$ticket = (new Class_CasTicket())->getTicketForCurrentUser();
$this->dispatch('/Syracuse_Plugin/auth/servicevalidate/service/syracuse/ticket/' . $ticket);
$this->assertContains('<cas:expire_at>2020-04-09</cas:expire_at>',
$this->_response->getBody());
}
/** @test */
public function validateWithValidUserTicketShouldContainsFifteenCasAttributes() {
$ticket = (new Class_CasTicket())->getTicketForCurrentUser();
......
......@@ -137,12 +137,13 @@ class ModulesControllerArteVodTest extends AbstractControllerTestCase {
public function moduleAccessWithRightShouldRedirectToArte() {
$group = $this->fixture('Class_UserGroup', ['id' => 1])
->addRight(Class_UserGroup::RIGHT_ACCES_ARTEVOD);
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
Class_Users::getIdentity()->setUserGroups([$group]);
Class_AdminVar::set('NOM_DOMAINE', 'mymediatheque.com');
$this->dispatch('/opac/modules/artevod');
$this->assertXpathContentContains('//script',
'document.location.href="https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=666&id_encrypted=ce04173447e59a7a3608f625b0348ccec5f4070c7c3f286b032cbe6374ec9f32&d=d8fb24f80a99bded9ed417591c5ac5cc1e123bcce10d65e1f6a83211ca18d3e8&return_url=https%3A%2F%2Fvod.mediatheque-numerique.com%2Fmediatheques%2Fuser&referer=http%3A%2F%2Fmymediatheque.com";', $this->_response->getBody());
'document.location.href="https://portal.mediatheque-numerique.com/sso_login?sso_id=afi&id=666&id_encrypted=ce04173447e59a7a3608f625b0348ccec5f4070c7c3f286b032cbe6374ec9f32&d=d8fb24f80a99bded9ed417591c5ac5cc1e123bcce10d65e1f6a83211ca18d3e8&datout=2020-04-09&return_url=https%3A%2F%2Fvod.mediatheque-numerique.com%2Fmediatheques%2Fuser&referer=http%3A%2F%2Fmymediatheque.com";', $this->_response->getBody());
}
}
......
......@@ -48,6 +48,7 @@ class ArteVodLinkWithUserAndAlbumTest extends ModelTestCase {
->beArteVOD()
->setExternalUri('http://www.mediatheque-numerique.com/films/entre-les-murs')
->setTitle('Entre les murs');
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
$this->_james_bond = Class_Users::newInstanceWithId(19)
->setIdabon(45)
......@@ -107,6 +108,26 @@ class ArteVodLinkWithUserAndAlbumTest extends ModelTestCase {
}
/** @test */
public function userWithoutExpiredSubscriptionDateShouldHaveValidDate() {
$this->_james_bond
->setPrenom('')
->setNom('')
->setMail('')
->setDateFin('2020-03-10');
Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10'));
$this->assertEquals('https://portal.mediatheque-numerique.com/sso_login'
.'?sso_id=afi'
.'&id=45'
.'&id_encrypted='. hash('sha256', '45' . $this->_sso_key)
.'&d='. hash('sha256', date('dmY'). $this->_sso_key)
.'&datout=2020-04-09'
.'&return_url=' . urlencode('http://www.mediatheque-numerique.com/films/entre-les-murs')
.'&referer=http%3A%2F%2Fmymediatheque.com',
$this->_arte_vod_link->url());
}
/** @test */
public function userInviteShouldHaveUserIdInSSOLink() {
$this->_james_bond
......@@ -122,6 +143,7 @@ class ArteVodLinkWithUserAndAlbumTest extends ModelTestCase {
.'&id=19'
.'&id_encrypted='. hash('sha256', '19' . $this->_sso_key)
.'&d='. hash('sha256', date('dmY') . $this->_sso_key)
.'&datout=2020-04-09'
.'&return_url=' . urlencode('http://www.mediatheque-numerique.com/films/entre-les-murs')
.'&referer=http%3A%2F%2Fmymediatheque.com',
......@@ -144,6 +166,7 @@ class ArteVodLinkWithUserAndAlbumTest extends ModelTestCase {
.'&id_encrypted='. hash('sha256', '45' . $this->_sso_key)
.'&d='. hash('sha256', date('dmY') . $this->_sso_key)
.'&dnaiss=1975-01-01'
.'&datout=2020-04-09'
.'&return_url=' . urlencode('http://www.mediatheque-numerique.com/films/entre-les-murs')
.'&referer=http%3A%2F%2Fmymediatheque.com',
$this->_arte_vod_link->url());
......
......@@ -258,6 +258,15 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
'search_age_debut' => 18
])]);
$this->_abonnes = $this
->fixture('Class_UserGroup',
['id' => 22,
'libelle' => 'Abonnes',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode([
'search_role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB
])]);
Class_UserGroup::resetDynamicsOfUserCache();
}
......@@ -282,6 +291,8 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['_shella', '_subscription_ended'],
['_shella', '_minors'],
['_gontran', '_adults'],
['_shella', '_abonnes'],
['_gontran', '_abonnes'],
];
}
......
......@@ -1803,6 +1803,11 @@ class PnbDilicomViewHelperRenderAlbumPNBLoggedButBlockedTest
$group = $this->fixture('Class_UserGroup',
['id' => '20',
'libelle' => 'Dilicom',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode([
'search_role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'search_valid_subscription' => 1]),
'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]]);
$this->logged_user = $this
......@@ -1818,7 +1823,7 @@ class PnbDilicomViewHelperRenderAlbumPNBLoggedButBlockedTest
'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)
......@@ -1833,6 +1838,7 @@ class PnbDilicomViewHelperRenderAlbumPNBLoggedButBlockedTest
'record_origin_id' => 'Dilicom-88817216',
'user_id' => '6']);
$this->_html = $this->_helper->renderAlbum($this->book);
}
......@@ -2089,6 +2095,10 @@ class PnbDilicomBibNumeriqueControllerBlockedUserTest extends AbstractController
$group = $this->fixture('Class_UserGroup', ['id' => '20',
'libelle' => 'Dilicom',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode([
'search_role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'search_valid_subscription' => 1]),
'rights' => [Class_UserGroup::RIGHT_ACCES_PNB_DILICOM]]);
$logged_user = $this->fixture('Class_Users',
......@@ -2103,7 +2113,7 @@ class PnbDilicomBibNumeriqueControllerBlockedUserTest extends AbstractController
'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)
......@@ -4182,7 +4192,8 @@ abstract class PnbDilicomHoldsTestCase extends PnbDilicomHubTestCase {
'mail' => 'thelma@example.com',
'bib' => $bib,
'idabon' => '129',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
]);
$darryl = $this->fixture('Class_Users',
['id' => 8,
......
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