]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #2327 from wallabag/user-management
authorJeremy Benoist <j0k3r@users.noreply.github.com>
Sun, 2 Oct 2016 13:00:02 +0000 (15:00 +0200)
committerGitHub <noreply@github.com>
Sun, 2 Oct 2016 13:00:02 +0000 (15:00 +0200)
Add users management UI

src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

index dd17ef976d38a6a3f8f49ae3b639a5ba5e65a94a..104720a9ef98aa9567f83c8c6ab2c5770114c8fc 100644 (file)
@@ -22,6 +22,38 @@ class WallabagRestController extends FOSRestController
         }
     }
 
+    /**
+     * Check if an entry exist by url.
+     *
+     * @ApiDoc(
+     *       parameters={
+     *          {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
+     *       }
+     * )
+     *
+     * @return JsonResponse
+     */
+    public function getEntriesExistsAction(Request $request)
+    {
+        $this->validateAuthentication();
+
+        $url = $request->query->get('url', '');
+
+        if (empty($url)) {
+            throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$user->getId());
+        }
+
+        $res = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId($url, $this->getUser()->getId());
+
+        $exists = false === $res ? false : true;
+
+        $json = $this->get('serializer')->serialize(['exists' => $exists], 'json');
+
+        return (new JsonResponse())->setJson($json);
+    }
+
     /**
      * Retrieve all entries. It could be filtered by many options.
      *
index 302e5a5387c6a64c72f79594d598988f288c6539..1b023e960817154b3c2240fe6f2f6e78ad7486a9 100644 (file)
@@ -281,7 +281,7 @@ class EntryRepository extends EntityRepository
     public function findByUrlAndUserId($url, $userId)
     {
         $res = $this->createQueryBuilder('e')
-            ->where('e.url = :url')->setParameter('url', $url)
+            ->where('e.url = :url')->setParameter('url', urldecode($url))
             ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
             ->getQuery()
             ->getResult();
index 101c20eb69fd82572d85f0549f633e41e4ecd21e..9b5760bcc98e3b6f8b0c45706eb9263ba90b6292 100644 (file)
@@ -684,4 +684,26 @@ class WallabagRestControllerTest extends WallabagApiTestCase
 
         $this->assertEquals(true, $content['is_starred']);
     }
+
+    public function testGetEntriesExists()
+    {
+        $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertEquals(true, $content['exists']);
+    }
+
+    public function testGetEntriesExistsWhichDoesNotExists()
+    {
+        $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertEquals(false, $content['exists']);
+    }
 }
index 053aa6791a0ca67ec5cfe12e47159921b89ba76b..c40e10a50041135efd2b49af3ba57edba2e8adda 100644 (file)
@@ -160,6 +160,50 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
     }
 
+    public function testPostNewOkUrlExistWithAccent()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('form[name=entry]')->form();
+
+        $data = [
+            'entry[url]' => $url,
+        ];
+
+        $client->submit($form, $data);
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('form[name=entry]')->form();
+
+        $data = [
+            'entry[url]' => $url,
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+        $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
+
+        $em = $client->getContainer()
+            ->get('doctrine.orm.entity_manager');
+        $entry = $em
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUrl(urldecode($url));
+
+        $em->remove($entry);
+        $em->flush();
+    }
+
     /**
      * This test will require an internet connection.
      */