From f1be7af446052c6fed7033664c6c6350f558961b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 Aug 2016 16:49:12 +0200 Subject: [PATCH] Change share entry behavior --- .../Version20160410190541.php | 12 ----- .../CoreBundle/Controller/EntryController.php | 51 +++++++++++++++++-- src/Wallabag/CoreBundle/Entity/Entry.php | 7 ++- .../Resources/translations/messages.da.yml | 1 + .../Resources/translations/messages.de.yml | 1 + .../Resources/translations/messages.en.yml | 1 + .../Resources/translations/messages.es.yml | 1 + .../Resources/translations/messages.fa.yml | 1 + .../Resources/translations/messages.fr.yml | 1 + .../Resources/translations/messages.it.yml | 2 + .../Resources/translations/messages.oc.yml | 1 + .../Resources/translations/messages.pl.yml | 1 + .../Resources/translations/messages.ro.yml | 1 + .../Resources/translations/messages.tr.yml | 1 + .../themes/material/Entry/entry.html.twig | 7 ++- .../CoreBundle/Command/InstallCommandTest.php | 2 +- var/SymfonyRequirements.php | 13 +++-- 17 files changed, 81 insertions(+), 23 deletions(-) diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index f35f54ce..77c78c54 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -28,18 +28,6 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI $this->addSql('ALTER TABLE `wallabag_entry` ADD `uuid` LONGTEXT DEFAULT NULL'); } - public function postUp(Schema $schema) - { - $em = $this->container->get('doctrine.orm.entity_manager'); - $repository = $em->getRepository('WallabagCoreBundle:Entry'); - $entries = $repository->findAll(); - - /** @var Entry $entry */ - foreach ($entries as $entry) { - $this->addSql('UPDATE `wallabag_entry` SET `uuid` = "'.uniqid('', true).'" WHERE id = '.$entry->getId()); - } - } - /** * @param Schema $schema */ 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 diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a629efc7..8c20cde2 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -436,8 +436,6 @@ class Entry } $this->updatedAt = new \DateTime(); - - $this->generateUuid(); } /** @@ -634,4 +632,9 @@ class Entry $this->uuid = uniqid('', true); } } + + public function cleanUuid() + { + $this->uuid = null; + } } diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 2eb0b7b0..f9b7bfac 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -188,6 +188,7 @@ entry: share_content: 'Deling' # share_email_label: 'Email' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Download' # print: 'Print' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 3d4ae9b3..79d03286 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -188,6 +188,7 @@ entry: share_content: 'Teilen' share_email_label: 'E-Mail' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Herunterladen' print: 'Drucken' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index b7a16446..d921b39f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -188,6 +188,7 @@ entry: share_content: 'Share' share_email_label: 'Email' public_link: 'public link' + delete_public_link: 'delete public link' download: 'Download' print: 'Print' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 0e4c0e6e..c2ec4dbd 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -188,6 +188,7 @@ entry: share_content: 'Compartir' share_email_label: 'Dirección e-mail' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Descargar' print: 'Imprimir' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 3b36f6f2..561ed907 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -188,6 +188,7 @@ entry: share_content: 'هم‌رسانی' share_email_label: 'نشانی ایمیل' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'بارگیری' print: 'چاپ' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index df7c2271..c0671883 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -188,6 +188,7 @@ entry: share_content: 'Partager' share_email_label: 'Email' public_link: 'Lien public' + delete_public_link: 'Supprimer lien public' download: 'Télécharger' print: 'Imprimer' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 3760c2d6..2e3dd08b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -185,6 +185,8 @@ entry: add_a_tag: 'Aggiungi un tag' share_content: 'Condividi' share_email_label: 'E-mail' + # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Download' print: 'Stampa' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index f3bfbd80..7b978a60 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -188,6 +188,7 @@ entry: share_content: 'Partatjar' share_email_label: 'Corrièl' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Telecargar' print: 'Imprimir' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 93d3e91f..da170e4d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -188,6 +188,7 @@ entry: share_content: 'Udostępnij' share_email_label: 'Adres email' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Pobierz' print: 'Drukuj' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 3ba1e078..fa2d6468 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -188,6 +188,7 @@ entry: share_content: 'Dă mai departe' share_email_label: 'E-mail' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'Descarcă' # print: 'Print' problem: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index f6337caa..05c31336 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -188,6 +188,7 @@ entry: share_content: 'Paylaş' share_email_label: 'E-posta' # public_link: 'public link' + # delete_public_link: 'delete public link' download: 'İndir' # print: 'Print' problem: diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 585e4dd5..05bb378d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -101,10 +101,15 @@