diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-12-27 21:28:48 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-12-28 13:42:50 +0100 |
commit | 2863bf2ab58a4903128f60751aa416130db93e52 (patch) | |
tree | 42c40d24baab371f5dd41eda12d3cbdbe6445a51 /src/Wallabag | |
parent | 71eff67f8b65a8337bd169fe8c271957ddd0aba0 (diff) | |
download | wallabag-2863bf2ab58a4903128f60751aa416130db93e52.tar.gz wallabag-2863bf2ab58a4903128f60751aa416130db93e52.tar.zst wallabag-2863bf2ab58a4903128f60751aa416130db93e52.zip |
Don't redirect to the content page after deletion
Fix #1512
We generate the url of the removed content and compare it to the referer url. If they matche, we redirect user to the homepage otherwise to the referer url.
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 14 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 46 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 6769799b..2f3fd6a9 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Controller; | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
8 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 10 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
10 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 11 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
@@ -316,7 +317,7 @@ class EntryController extends Controller | |||
316 | } | 317 | } |
317 | 318 | ||
318 | /** | 319 | /** |
319 | * Deletes entry and redirect to the homepage. | 320 | * Deletes entry and redirect to the homepage or the last viewed page. |
320 | * | 321 | * |
321 | * @param Entry $entry | 322 | * @param Entry $entry |
322 | * | 323 | * |
@@ -328,6 +329,14 @@ class EntryController extends Controller | |||
328 | { | 329 | { |
329 | $this->checkUserAction($entry); | 330 | $this->checkUserAction($entry); |
330 | 331 | ||
332 | // generates the view url for this entry to check for redirection later | ||
333 | // to avoid redirecting to the deleted entry. Ugh. | ||
334 | $url = $this->generateUrl( | ||
335 | 'view', | ||
336 | array('id' => $entry->getId()), | ||
337 | UrlGeneratorInterface::ABSOLUTE_URL | ||
338 | ); | ||
339 | |||
331 | $em = $this->getDoctrine()->getManager(); | 340 | $em = $this->getDoctrine()->getManager(); |
332 | $em->remove($entry); | 341 | $em->remove($entry); |
333 | $em->flush(); | 342 | $em->flush(); |
@@ -337,7 +346,8 @@ class EntryController extends Controller | |||
337 | 'Entry deleted' | 346 | 'Entry deleted' |
338 | ); | 347 | ); |
339 | 348 | ||
340 | return $this->redirect($request->headers->get('referer')); | 349 | // don't redirect user to the deleted entry |
350 | return $this->redirect($url !== $request->headers->get('referer') ?: $this->generateUrl('homepage')); | ||
341 | } | 351 | } |
342 | 352 | ||
343 | /** | 353 | /** |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index af62aee8..9f585d85 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | 5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | 7 | ||
7 | class EntryControllerTest extends WallabagCoreTestCase | 8 | class EntryControllerTest extends WallabagCoreTestCase |
8 | { | 9 | { |
@@ -290,6 +291,51 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
290 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 291 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
291 | } | 292 | } |
292 | 293 | ||
294 | /** | ||
295 | * It will create a new entry. | ||
296 | * Browse to it. | ||
297 | * Then remove it. | ||
298 | * | ||
299 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | ||
300 | */ | ||
301 | public function testViewAndDelete() | ||
302 | { | ||
303 | $this->logInAs('admin'); | ||
304 | $client = $this->getClient(); | ||
305 | |||
306 | // add a new content to be removed later | ||
307 | $user = $client->getContainer() | ||
308 | ->get('doctrine.orm.entity_manager') | ||
309 | ->getRepository('WallabagUserBundle:User') | ||
310 | ->findOneByUserName('admin'); | ||
311 | |||
312 | $content = new Entry($user); | ||
313 | $content->setUrl('http://1.1.1.1/entry'); | ||
314 | $content->setReadingTime(12); | ||
315 | $content->setDomainName('domain.io'); | ||
316 | $content->setMimetype('text/html'); | ||
317 | $content->setTitle('test title entry'); | ||
318 | $content->setContent('This is my content /o/'); | ||
319 | $content->setArchived(true); | ||
320 | $content->setLanguage('fr'); | ||
321 | |||
322 | $client->getContainer() | ||
323 | ->get('doctrine.orm.entity_manager') | ||
324 | ->persist($content); | ||
325 | $client->getContainer() | ||
326 | ->get('doctrine.orm.entity_manager') | ||
327 | ->flush(); | ||
328 | |||
329 | $client->request('GET', '/view/'.$content->getId()); | ||
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
331 | |||
332 | $client->request('GET', '/delete/'.$content->getId()); | ||
333 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
334 | |||
335 | $client->followRedirect(); | ||
336 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
337 | } | ||
338 | |||
293 | public function testViewOtherUserEntry() | 339 | public function testViewOtherUserEntry() |
294 | { | 340 | { |
295 | $this->logInAs('admin'); | 341 | $this->logInAs('admin'); |