X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FEntryController.php;h=e500ad752af6f0af4e30a502542634a2bc5fafca;hb=f1be7af446052c6fed7033664c6c6350f558961b;hp=c94b47f0db5e6f05d9926aa8cf09cbf1d4f559ea;hpb=3377c938f8e5bd6af2cd4430494f39a517a7e910;p=github%2Fwallabag%2Fwallabag.git 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