From 71eff67f8b65a8337bd169fe8c271957ddd0aba0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Dec 2015 21:25:37 +0100 Subject: Entry data should have unique url --- src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php index 176c529e..0513cdb8 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php @@ -16,7 +16,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface public function load(ObjectManager $manager) { $entry1 = new Entry($this->getReference('admin-user')); - $entry1->setUrl('http://0.0.0.0'); + $entry1->setUrl('http://0.0.0.0/entry1'); $entry1->setReadingTime(11); $entry1->setDomainName('domain.io'); $entry1->setMimetype('text/html'); @@ -29,7 +29,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('entry1', $entry1); $entry2 = new Entry($this->getReference('admin-user')); - $entry2->setUrl('http://0.0.0.0'); + $entry2->setUrl('http://0.0.0.0/entry2'); $entry2->setReadingTime(1); $entry2->setDomainName('domain.io'); $entry2->setMimetype('text/html'); @@ -42,7 +42,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('entry2', $entry2); $entry3 = new Entry($this->getReference('bob-user')); - $entry3->setUrl('http://0.0.0.0'); + $entry3->setUrl('http://0.0.0.0/entry3'); $entry3->setReadingTime(1); $entry3->setDomainName('domain.io'); $entry3->setMimetype('text/html'); @@ -63,7 +63,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('entry3', $entry3); $entry4 = new Entry($this->getReference('admin-user')); - $entry4->setUrl('http://0.0.0.0'); + $entry4->setUrl('http://0.0.0.0/entry4'); $entry4->setReadingTime(12); $entry4->setDomainName('domain.io'); $entry4->setMimetype('text/html'); @@ -84,7 +84,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('entry4', $entry4); $entry5 = new Entry($this->getReference('admin-user')); - $entry5->setUrl('http://0.0.0.0'); + $entry5->setUrl('http://0.0.0.0/entry5'); $entry5->setReadingTime(12); $entry5->setDomainName('domain.io'); $entry5->setMimetype('text/html'); @@ -99,7 +99,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('entry5', $entry5); $entry6 = new Entry($this->getReference('admin-user')); - $entry6->setUrl('http://0.0.0.0'); + $entry6->setUrl('http://0.0.0.0/entry6'); $entry6->setReadingTime(12); $entry6->setDomainName('domain.io'); $entry6->setMimetype('text/html'); -- cgit v1.2.3 From 2863bf2ab58a4903128f60751aa416130db93e52 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Dec 2015 21:28:48 +0100 Subject: 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. --- .../CoreBundle/Controller/EntryController.php | 14 ++++++- .../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; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Form\Type\NewEntryType; use Wallabag\CoreBundle\Form\Type\EditEntryType; @@ -316,7 +317,7 @@ class EntryController extends Controller } /** - * Deletes entry and redirect to the homepage. + * Deletes entry and redirect to the homepage or the last viewed page. * * @param Entry $entry * @@ -328,6 +329,14 @@ class EntryController extends Controller { $this->checkUserAction($entry); + // generates the view url for this entry to check for redirection later + // to avoid redirecting to the deleted entry. Ugh. + $url = $this->generateUrl( + 'view', + array('id' => $entry->getId()), + UrlGeneratorInterface::ABSOLUTE_URL + ); + $em = $this->getDoctrine()->getManager(); $em->remove($entry); $em->flush(); @@ -337,7 +346,8 @@ class EntryController extends Controller 'Entry deleted' ); - return $this->redirect($request->headers->get('referer')); + // don't redirect user to the deleted entry + return $this->redirect($url !== $request->headers->get('referer') ?: $this->generateUrl('homepage')); } /** 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 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase { @@ -290,6 +291,51 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + /** + * It will create a new entry. + * Browse to it. + * Then remove it. + * + * And it'll check that user won't be redirected to the view page of the content when it had been removed + */ + public function testViewAndDelete() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // add a new content to be removed later + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagUserBundle:User') + ->findOneByUserName('admin'); + + $content = new Entry($user); + $content->setUrl('http://1.1.1.1/entry'); + $content->setReadingTime(12); + $content->setDomainName('domain.io'); + $content->setMimetype('text/html'); + $content->setTitle('test title entry'); + $content->setContent('This is my content /o/'); + $content->setArchived(true); + $content->setLanguage('fr'); + + $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->persist($content); + $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->flush(); + + $client->request('GET', '/view/'.$content->getId()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $client->request('GET', '/delete/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $client->followRedirect(); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testViewOtherUserEntry() { $this->logInAs('admin'); -- cgit v1.2.3