From f3d0cb91063840f2b05c63954d3fef3e5b8943fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 17:33:15 +0200 Subject: Share entry with a public URL --- .../CoreBundle/Controller/EntryController.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 93db0d6c..a78dd00c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -291,6 +291,8 @@ class EntryController extends Controller { $this->checkUserAction($entry); + $this->generateEntryUuid($entry); + return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] @@ -449,5 +451,34 @@ class EntryController extends Controller private function checkIfEntryAlreadyExists(Entry $entry) { return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); + + } + + /* + * Share entry content. + * + * @param Entry $entry + * + * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function shareEntry(Entry $entry) + { + return $this->render( + '@WallabagCore/themes/share.html.twig', + array('entry' => $entry) + ); + } + + /** + * @param Entry $entry + */ + private function generateEntryUuid(Entry $entry) + { + $entry->generateUuid(); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } } -- cgit v1.2.3 From d0545b6bd6edc38bf06604900b1e20a60e7c8583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 21:48:11 +0200 Subject: Add migration --- src/Wallabag/CoreBundle/Controller/EntryController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index a78dd00c..e3b4b1eb 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -451,10 +451,9 @@ class EntryController extends Controller private function checkIfEntryAlreadyExists(Entry $entry) { return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); - } - /* + /** * Share entry content. * * @param Entry $entry @@ -463,7 +462,7 @@ class EntryController extends Controller * * @return \Symfony\Component\HttpFoundation\Response */ - public function shareEntry(Entry $entry) + public function shareEntryAction(Entry $entry) { return $this->render( '@WallabagCore/themes/share.html.twig', -- cgit v1.2.3 From 222e09f140099f3b1b8f6db1846d35e6810d43a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 13 Apr 2016 22:26:02 +0200 Subject: Add Cache on Share Action --- src/Wallabag/CoreBundle/Controller/EntryController.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e3b4b1eb..c94b47f0 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Form\Type\EntryFilterType; use Wallabag\CoreBundle\Form\Type\EditEntryType; use Wallabag\CoreBundle\Form\Type\NewEntryType; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; class EntryController extends Controller { @@ -459,6 +460,7 @@ class EntryController extends Controller * @param Entry $entry * * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * @Cache(maxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response */ -- cgit v1.2.3 From f1be7af446052c6fed7033664c6c6350f558961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 Aug 2016 16:49:12 +0200 Subject: Change share entry behavior --- .../CoreBundle/Controller/EntryController.php | 51 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index c94b47f0..e500ad75 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -292,8 +292,6 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $this->generateEntryUuid($entry); - return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] @@ -437,7 +435,7 @@ class EntryController extends Controller */ private function checkUserAction(Entry $entry) { - if ($this->getUser()->getId() != $entry->getUser()->getId()) { + if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) { throw $this->createAccessDeniedException('You can not access this entry.'); } } @@ -454,12 +452,57 @@ class EntryController extends Controller return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); } + /** + * Get public URL for entry (and generate it if necessary). + * + * @param Entry $entry + * + * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function shareAction(Entry $entry) + { + $this->checkUserAction($entry); + + if ('' === $entry->getUuid() || null === $entry->getUuid()) { + $this->generateEntryUuid($entry); + } + + return $this->redirect($this->generateUrl('share_entry', [ + 'uuid' => $entry->getUuid(), + ])); + } + + /** + * Disable public sharing for an entry. + * + * @param Entry $entry + * + * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function deleteShareAction(Entry $entry) + { + $this->checkUserAction($entry); + + $entry->cleanUuid(); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + return $this->redirect($this->generateUrl('view', [ + 'id' => $entry->getId(), + ])); + } + /** * Share entry content. * * @param Entry $entry * - * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") * @Cache(maxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response -- cgit v1.2.3 From eddda878a0ec375fa738e3228a72dd01b23e0fab Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Aug 2016 22:29:36 +0200 Subject: Update test and some cleanup --- .../CoreBundle/Controller/EntryController.php | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e500ad75..d71ba6cd 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -465,8 +465,12 @@ class EntryController extends Controller { $this->checkUserAction($entry); - if ('' === $entry->getUuid() || null === $entry->getUuid()) { - $this->generateEntryUuid($entry); + if (null === $entry->getUuid()) { + $entry->generateUuid(); + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } return $this->redirect($this->generateUrl('share_entry', [ @@ -488,6 +492,7 @@ class EntryController extends Controller $this->checkUserAction($entry); $entry->cleanUuid(); + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -498,31 +503,24 @@ class EntryController extends Controller } /** - * Share entry content. + * Ability to view a content publicly. * * @param Entry $entry * * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") - * @Cache(maxage="25200", public=true) + * @Cache(maxage="25200", smaxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response */ public function shareEntryAction(Entry $entry) { + if (!$this->get('craue_config')->get('share_public')) { + throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.'); + } + return $this->render( '@WallabagCore/themes/share.html.twig', - array('entry' => $entry) + ['entry' => $entry] ); } - - /** - * @param Entry $entry - */ - private function generateEntryUuid(Entry $entry) - { - $entry->generateUuid(); - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - } } -- cgit v1.2.3