aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php30
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php27
3 files changed, 41 insertions, 18 deletions
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
465 { 465 {
466 $this->checkUserAction($entry); 466 $this->checkUserAction($entry);
467 467
468 if ('' === $entry->getUuid() || null === $entry->getUuid()) { 468 if (null === $entry->getUuid()) {
469 $this->generateEntryUuid($entry); 469 $entry->generateUuid();
470
471 $em = $this->getDoctrine()->getManager();
472 $em->persist($entry);
473 $em->flush();
470 } 474 }
471 475
472 return $this->redirect($this->generateUrl('share_entry', [ 476 return $this->redirect($this->generateUrl('share_entry', [
@@ -488,6 +492,7 @@ class EntryController extends Controller
488 $this->checkUserAction($entry); 492 $this->checkUserAction($entry);
489 493
490 $entry->cleanUuid(); 494 $entry->cleanUuid();
495
491 $em = $this->getDoctrine()->getManager(); 496 $em = $this->getDoctrine()->getManager();
492 $em->persist($entry); 497 $em->persist($entry);
493 $em->flush(); 498 $em->flush();
@@ -498,31 +503,24 @@ class EntryController extends Controller
498 } 503 }
499 504
500 /** 505 /**
501 * Share entry content. 506 * Ability to view a content publicly.
502 * 507 *
503 * @param Entry $entry 508 * @param Entry $entry
504 * 509 *
505 * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") 510 * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
506 * @Cache(maxage="25200", public=true) 511 * @Cache(maxage="25200", smaxage="25200", public=true)
507 * 512 *
508 * @return \Symfony\Component\HttpFoundation\Response 513 * @return \Symfony\Component\HttpFoundation\Response
509 */ 514 */
510 public function shareEntryAction(Entry $entry) 515 public function shareEntryAction(Entry $entry)
511 { 516 {
517 if (!$this->get('craue_config')->get('share_public')) {
518 throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
519 }
520
512 return $this->render( 521 return $this->render(
513 '@WallabagCore/themes/share.html.twig', 522 '@WallabagCore/themes/share.html.twig',
514 array('entry' => $entry) 523 ['entry' => $entry]
515 ); 524 );
516 } 525 }
517
518 /**
519 * @param Entry $entry
520 */
521 private function generateEntryUuid(Entry $entry)
522 {
523 $entry->generateUuid();
524 $em = $this->getDoctrine()->getManager();
525 $em->persist($entry);
526 $em->flush();
527 }
528} 526}
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 67c2bb43..4d7e001b 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -627,7 +627,7 @@ class Entry
627 627
628 public function generateUuid() 628 public function generateUuid()
629 { 629 {
630 if (empty($this->uuid) || is_null($this->uuid)) { 630 if (null === $this->uuid) {
631 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter 631 // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
632 $this->uuid = uniqid('', true); 632 $this->uuid = uniqid('', true);
633 } 633 }
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 3b54f057..f9ac28c3 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -709,11 +709,36 @@ class EntryControllerTest extends WallabagCoreTestCase
709 ->getRepository('WallabagCoreBundle:Entry') 709 ->getRepository('WallabagCoreBundle:Entry')
710 ->findOneByUser($this->getLoggedInUserId()); 710 ->findOneByUser($this->getLoggedInUserId());
711 711
712 // no uuid
712 $client->request('GET', '/share/'.$content->getUuid()); 713 $client->request('GET', '/share/'.$content->getUuid());
713 $this->assertContains('max-age=25200, public', $client->getResponse()->headers->get('cache-control')); 714 $this->assertEquals(404, $client->getResponse()->getStatusCode());
715
716 // generating the uuid
717 $client->request('GET', '/share/'.$content->getId());
718 $this->assertEquals(302, $client->getResponse()->getStatusCode());
719
720 // follow link with uuid
721 $crawler = $client->followRedirect();
722 $this->assertEquals(200, $client->getResponse()->getStatusCode());
723 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
724 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
725 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
714 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); 726 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
715 727
728 // sharing is now disabled
729 $client->getContainer()->get('craue_config')->set('share_public', 0);
730 $client->request('GET', '/share/'.$content->getUuid());
731 $this->assertEquals(404, $client->getResponse()->getStatusCode());
732
716 $client->request('GET', '/view/'.$content->getId()); 733 $client->request('GET', '/view/'.$content->getId());
717 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); 734 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
735
736 // removing the share
737 $client->request('GET', '/share/delete/'.$content->getId());
738 $this->assertEquals(302, $client->getResponse()->getStatusCode());
739
740 // share is now disable
741 $client->request('GET', '/share/'.$content->getUuid());
742 $this->assertEquals(404, $client->getResponse()->getStatusCode());
718 } 743 }
719} 744}