Commit 50363de9 authored by efalcy's avatar efalcy Committed by Laurent
Browse files

hotline #99071: prevent redirect when subscribe and sending mail when already subscribe

parent 24754b7c
Pipeline #8746 passed with stage
in 42 minutes and 59 seconds
- ticket #99071 : Inscription à une activité : message de confirmation envoyé 20 fois
\ No newline at end of file
......@@ -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()));
......
......@@ -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)
......
......@@ -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')
......
......@@ -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 {
......
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