diff --git a/VERSIONS_HOTLINE/99071 b/VERSIONS_HOTLINE/99071 new file mode 100644 index 0000000000000000000000000000000000000000..60525c546d910031021720772832b4e5bdbf1c89 --- /dev/null +++ b/VERSIONS_HOTLINE/99071 @@ -0,0 +1 @@ + - ticket #99071 : Inscription à une activité : message de confirmation envoyé 20 fois \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index a7d1b4553e5d6bd0474855b15a120f18dc00d5ef..cb7d487fa4255ada263d47832f5fcf1b41eab1fe 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -85,12 +85,21 @@ class AbonneController extends ZendAfi_Controller_Action { public function inscrireSessionAction() { - $this->_redirectToReferer(); + $redirect = $this->_getParam('redirect_url', $this->_getReferer()); + + if (strpos($redirect, 'inscrire-session') !== false) + $redirect = Class_Url::absolute(['controller' => 'abonne', + 'action' => 'activities'], null, true); + + $this->_redirectToUrlOrReferer($redirect); if ((!$session = Class_SessionActivity::find((int)$this->_getParam('id'))) || $session->isInscriptionClosed()) return $this->_helper->notify($this->_('L\'inscription à cette session est fermée')); + if ($session->hasStagiaire($this->_user)) + return $this->_helper->notify($this->_('Vous êtes déjà inscrit à cette session')); + $session->addStagiaire($this->_user); if (!$session->save()) return $this->_helper->notify(implode('<br/>', $session->getErrors())); diff --git a/library/Class/SessionActivity.php b/library/Class/SessionActivity.php index f2d460ad6ea02e21241151e14566f11a45b13b90..b1a6b206f2f601542c0129704bbde913a3234c7b 100644 --- a/library/Class/SessionActivity.php +++ b/library/Class/SessionActivity.php @@ -312,6 +312,13 @@ class Class_SessionActivity extends Storm_Model_Abstract { } + public function hasStagiaire($user) { + return null !== (new Storm_Model_Collection($this->getStagiaires())) + ->detect(function ($stagiaire) use ($user) + { return $stagiaire->getId() == $user->getId();}); + } + + public function toArray() { $intervenant_ids = []; foreach($this->getIntervenants() as $intervenant) diff --git a/library/ZendAfi/Controller/Plugin/AdminAuth.php b/library/ZendAfi/Controller/Plugin/AdminAuth.php index 7bd9242d2b366fa6a33e1a6c00f65fe8b097b193..dd63656e84ae20d4e2335d35d89c09c68d1576a8 100644 --- a/library/ZendAfi/Controller/Plugin/AdminAuth.php +++ b/library/ZendAfi/Controller/Plugin/AdminAuth.php @@ -64,7 +64,7 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac if ((!$user = Class_Users::getIdentity()) && $action !== "authenticate" && in_array($controller, ["abonne", 'bookmarked-searches'])) { - $request->setParam('redirect', Class_Url::absolute()); + $request->setParam('redirect', $this->_getRedirect($request, $action)); $controller = 'auth'; $action = ($request->getParam('render') == 'popup') ? 'popup-login' : 'login'; } @@ -76,6 +76,18 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac } + protected function _getRedirect($request, $action) { + $redirect = Class_Url::absolute(); + if ($action != 'inscrire-session') + return $redirect; + + if (! $referer = $request->getServer('HTTP_REFERER')) + return $redirect; + + return $redirect.'?redirect_url='.urlencode($referer); + } + + protected function _handleAdmin($request) { Zend_Controller_Front::getInstance() ->getPlugin('Zend_Controller_Plugin_ErrorHandler') diff --git a/tests/application/modules/opac/controllers/AbonneControllerActivitiesTest.php b/tests/application/modules/opac/controllers/AbonneControllerActivitiesTest.php index 32ac1fb1c79c1572f2602c14fe3ee775429419fa..bb86afda9033032bad7c56195dbb64cb7c00ec65 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerActivitiesTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerActivitiesTest.php @@ -896,6 +896,50 @@ class AbonneControllerActivitiesInscritSessionWithoutRightSuivreActivityTest ext +class AbonneControllerActivitiesInscriptionNotLoggedTest extends AbstractAbonneControllerActivitiesTestCase { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->clearIdentity(); + $_SERVER['HTTP_REFERER'] = '/myurl'; + $session = Class_SessionActivity::find(31); + $this->dispatch('/opac/abonne/inscrire-session/id/31'); + } + + + /** @test */ + public function redirectHiddenInputShouldReturnRedirectUrl() { + $this->assertXPath('//input[contains(@value,"/abonne/inscrire-session/id/31?redirect_url=%2Fmyurl")]',$this->_response->getBody()); + } +} + + + + +class AbonneControllerActivitiesInscriptionRedirectionTest extends AbstractAbonneControllerActivitiesTestCase { + public function setUp() { + parent::setUp(); + $_SERVER['HTTP_REFERER'] = '/inscrire-session/id/31'; + $session = Class_SessionActivity::find(31); + $session->addStagiaire(Class_Users::find(435))->save(); + $this->dispatch('/opac/abonne/inscrire-session/id/31'); + } + + + /** @test */ + public function redirectOnAbonnePagesIfNoRedirectUrl() { + $this->assertRedirectTo(Class_Url::absolute('/abonne/activities')); + } + + + /** @test */ + public function flashMessageShouldBeYouHaveAlreadySubscribed() { + $this->assertFlashMessengerContentContains('Vous êtes déjà inscrit à cette session'); + } + +} + + + class AbonneControllerActivitiesAmadouDesinscritSessionJuilletPythonTest extends AbstractAbonneControllerActivitiesTestCase {