From 13bd448e017f33f4a386842ee0eaf578323da35e Mon Sep 17 00:00:00 2001 From: Michael Ciociola Date: Sun, 4 Dec 2022 14:16:00 -0600 Subject: [PATCH 1/6] feat: use session instead of referer for redirects --- .../Controller/ConfigController.php | 2 +- .../CoreBundle/Controller/EntryController.php | 21 +++++++------------ .../CoreBundle/Controller/TagController.php | 8 +++---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index bc650c57b..acc52ae78 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -626,7 +626,7 @@ class ConfigController extends Controller $em->persist($user); $em->flush(); - return $this->redirect($request->headers->get('referer')); + return $this->redirect($request->getSession()->get('prevUrl')); } /** diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 63a2ace22..76acb531b 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -110,9 +110,7 @@ class EntryController extends Controller $em->flush(); } - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); - - return $this->redirect($redirectUrl); + return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'))); } /** @@ -379,6 +377,7 @@ class EntryController extends Controller public function viewAction(Entry $entry) { $this->checkUserAction($entry); + $this->get('session')->set('prevUrl', $this->generateUrl('view', ['id' => $entry->getId()])); return $this->render( '@WallabagCore/Entry/entry.html.twig', @@ -443,9 +442,7 @@ class EntryController extends Controller $message ); - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); - - return $this->redirect($redirectUrl); + return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'))); } /** @@ -473,9 +470,7 @@ class EntryController extends Controller $message ); - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer')); - - return $this->redirect($redirectUrl); + return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'))); } /** @@ -509,10 +504,9 @@ class EntryController extends Controller 'flashes.entry.notice.entry_deleted' ); - // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) - $referer = $request->headers->get('referer'); - $to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null); - + // don't redirect user to the deleted entry + $prev = $request->getSession()->get('prevUrl'); + $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null); $redirectUrl = $this->get(Redirect::class)->to($to); return $this->redirect($redirectUrl); @@ -612,6 +606,7 @@ class EntryController extends Controller $repository = $this->get(EntryRepository::class); $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $request->getSession()->set('prevUrl', $request->getRequestUri()); $formOptions = []; diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 53ce07c98..630f5a3ac 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -76,7 +76,7 @@ class TagController extends Controller $em->flush(); } - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); + $redirectUrl = $this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true); return $this->redirect($redirectUrl); } @@ -159,7 +159,7 @@ class TagController extends Controller $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); + $redirectUrl = $this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true); if ($form->isSubmitted() && $form->isValid()) { $newTag = new Tag(); @@ -227,7 +227,7 @@ class TagController extends Controller $em->flush(); - return $this->redirect($this->get(Redirect::class)->to($request->headers->get('referer'), '', true)); + return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true)); } /** @@ -253,6 +253,6 @@ class TagController extends Controller $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); - return $this->redirect($redirectUrl); + return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true)); } } From fbccae8a79ae22273a40c346b731cfbe417965fc Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 10 Dec 2022 11:52:18 -0600 Subject: [PATCH 2/6] fix: update remove tag test to accept root relative urls --- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 538df700d..33de69f57 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -124,7 +124,7 @@ class TagControllerTest extends WallabagCoreTestCase // We make a first request to set an history and test redirection after tag deletion $client->request('GET', '/view/' . $entry->getId()); - $entryUri = $client->getRequest()->getUri(); + $entryUri = $client->getRequest()->getRequestUri(); $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); $this->assertSame(302, $client->getResponse()->getStatusCode()); From 97fee36fa600a23e4915872d498bca90de028f2a Mon Sep 17 00:00:00 2001 From: Michael Ciociola <549853+Spoons@users.noreply.github.com> Date: Fri, 23 Dec 2022 11:03:25 -0600 Subject: [PATCH 3/6] Update src/Wallabag/CoreBundle/Controller/TagController.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémy Benoist --- src/Wallabag/CoreBundle/Controller/TagController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 630f5a3ac..d95727de3 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -251,8 +251,6 @@ class TagController extends Controller $em->flush(); } - $redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'), '', true); - return $this->redirect($this->get(Redirect::class)->to($request->getSession()->get('prevUrl'), '', true)); } } From 9729db75dee124da14d87bed7d57b718ffda7b16 Mon Sep 17 00:00:00 2001 From: Michael Ciociola <549853+Spoons@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:19:49 +0000 Subject: [PATCH 4/6] Update EntryController.php --- src/Wallabag/CoreBundle/Controller/EntryController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 8491a2875..e458dc113 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -128,7 +128,7 @@ class EntryController extends AbstractController $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -453,7 +453,7 @@ class EntryController extends AbstractController ); - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -483,7 +483,7 @@ class EntryController extends AbstractController $message ); - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -520,7 +520,7 @@ class EntryController extends AbstractController // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) - $prev = $request->headers->get('prevUrl'); + $prev = $request->getSession()->get('prevUrl'); $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null); $redirectUrl = $this->redirectHelper->to($to); From e90daf06903184994aaf343c4c67aab78c3fe198 Mon Sep 17 00:00:00 2001 From: Michael Ciociola <549853+Spoons@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:20:35 +0000 Subject: [PATCH 5/6] Update TagController.php --- src/Wallabag/CoreBundle/Controller/TagController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 75c0bc0b2..6e147df98 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -104,7 +104,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); return $this->redirect($redirectUrl); } @@ -185,7 +185,7 @@ class TagController extends AbstractController $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); if ($form->isSubmitted() && $form->isValid()) { $newTag = new Tag(); @@ -257,7 +257,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - return $this->redirect($this->redirectHelper->to($request->headers->get('prevUrl'), '', true)); + return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true)); } /** @@ -279,7 +279,7 @@ class TagController extends AbstractController $this->entityManager->remove($tag); $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->headers->get('prevUrl'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); return $this->redirect($redirectUrl); } From 8d3d916d4ae311eb05409e6eeec552246f919e70 Mon Sep 17 00:00:00 2001 From: Michael Ciociola <549853+Spoons@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:46:52 +0000 Subject: [PATCH 6/6] Remove extraneous blank lines from EntryController.php --- src/Wallabag/CoreBundle/Controller/EntryController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e458dc113..655217c95 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -452,7 +452,6 @@ class EntryController extends AbstractController $message ); - $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); @@ -518,7 +517,6 @@ class EntryController extends AbstractController 'flashes.entry.notice.entry_deleted' ); - // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) $prev = $request->getSession()->get('prevUrl'); $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null);