]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Merge pull request #2252 from wallabag/fix-last-merge
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index c94b47f0db5e6f05d9926aa8cf09cbf1d4f559ea..624576b5bee67a43be98418a72e5c4ce93831233 100644 (file)
@@ -226,6 +226,10 @@ class EntryController extends Controller
         $repository = $this->get('wallabag_core.entry_repository');
 
         switch ($type) {
+            case 'untagged':
+                $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
+
+                break;
             case 'starred':
                 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
                 break;
@@ -292,8 +296,6 @@ class EntryController extends Controller
     {
         $this->checkUserAction($entry);
 
-        $this->generateEntryUuid($entry);
-
         return $this->render(
             'WallabagCoreBundle:Entry:entry.html.twig',
             ['entry' => $entry]
@@ -437,7 +439,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.');
         }
     }
@@ -455,31 +457,89 @@ class EntryController extends Controller
     }
 
     /**
-     * Share entry content.
+     * Get public URL for entry (and generate it if necessary).
      *
      * @param Entry $entry
      *
-     * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share")
-     * @Cache(maxage="25200", public=true)
+     * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
      *
      * @return \Symfony\Component\HttpFoundation\Response
      */
-    public function shareEntryAction(Entry $entry)
+    public function shareAction(Entry $entry)
     {
-        return $this->render(
-            '@WallabagCore/themes/share.html.twig',
-            array('entry' => $entry)
-        );
+        $this->checkUserAction($entry);
+
+        if (null === $entry->getUuid()) {
+            $entry->generateUuid();
+
+            $em = $this->getDoctrine()->getManager();
+            $em->persist($entry);
+            $em->flush();
+        }
+
+        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
      */
-    private function generateEntryUuid(Entry $entry)
+    public function deleteShareAction(Entry $entry)
     {
-        $entry->generateUuid();
+        $this->checkUserAction($entry);
+
+        $entry->cleanUuid();
+
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
         $em->flush();
+
+        return $this->redirect($this->generateUrl('view', [
+            'id' => $entry->getId(),
+        ]));
+    }
+
+    /**
+     * Ability to view a content publicly.
+     *
+     * @param Entry $entry
+     *
+     * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
+     * @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',
+            ['entry' => $entry]
+        );
+    }
+
+    /**
+     * Shows untagged articles for current user.
+     *
+     * @param Request $request
+     * @param int     $page
+     *
+     * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function showUntaggedEntriesAction(Request $request, $page)
+    {
+        return $this->showEntries('untagged', $request, $page);
     }
 }