]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #1799 from wallabag/v2-fix-tabs-display-material
authorNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 18 Mar 2016 11:52:40 +0000 (12:52 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 18 Mar 2016 11:52:40 +0000 (12:52 +0100)
fix tabs display on mobile view

src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
src/Wallabag/CoreBundle/Controller/DeveloperController.php
src/Wallabag/CoreBundle/Entity/Entry.php

index 2633a311773a629a96ea37f734c15d1e2fcc502b..744e1a601547b3d968c060dc3657007b1c3c6ce5 100644 (file)
@@ -27,13 +27,13 @@ class WallabagRestController extends FOSRestController
      *
      * @ApiDoc(
      *       parameters={
-     *          {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."},
-     *          {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."},
+     *          {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by archived status."},
+     *          {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by starred status."},
      *          {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
      *          {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
      *          {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
      *          {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."},
-     *          {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
+     *          {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
      *       }
      * )
      *
@@ -43,8 +43,8 @@ class WallabagRestController extends FOSRestController
     {
         $this->validateAuthentication();
 
-        $isArchived = $request->query->get('archive');
-        $isStarred = $request->query->get('star');
+        $isArchived = (int) $request->query->get('archive');
+        $isStarred = (int) $request->query->get('starred');
         $sort = $request->query->get('sort', 'created');
         $order = $request->query->get('order', 'desc');
         $page = (int) $request->query->get('page', 1);
@@ -52,7 +52,7 @@ class WallabagRestController extends FOSRestController
 
         $pager = $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
+            ->findEntries($this->getUser()->getId(), (bool) $isArchived, (bool) $isStarred, $sort, $order);
 
         $pager->setCurrentPage($page);
         $pager->setMaxPerPage($perPage);
@@ -97,8 +97,8 @@ class WallabagRestController extends FOSRestController
      *          {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."},
      *          {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."},
      *          {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
-     *          {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"},
-     *          {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"},
+     *          {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already starred"},
+     *          {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already archived"},
      *       }
      * )
      *
@@ -109,8 +109,8 @@ class WallabagRestController extends FOSRestController
         $this->validateAuthentication();
 
         $url = $request->request->get('url');
-        $isArchived = $request->request->get('archive');
-        $isStarred = $request->request->get('starred');
+        $isArchived = (int) $request->request->get('archive');
+        $isStarred = (int) $request->request->get('starred');
 
         $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
 
@@ -126,12 +126,12 @@ class WallabagRestController extends FOSRestController
             $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
         }
 
-        if (true === (bool) $isStarred) {
-            $entry->setStarred(true);
+        if (!is_null($isStarred)) {
+            $entry->setStarred((bool) $isStarred);
         }
 
-        if (true === (bool) $isArchived) {
-            $entry->setArchived(true);
+        if (!is_null($isArchived)) {
+            $entry->setArchived((bool) $isArchived);
         }
 
         $em = $this->getDoctrine()->getManager();
@@ -154,8 +154,8 @@ class WallabagRestController extends FOSRestController
      *      parameters={
      *          {"name"="title", "dataType"="string", "required"=false},
      *          {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
-     *          {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."},
-     *          {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
+     *          {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="archived the entry."},
+     *          {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="starred the entry."},
      *      }
      * )
      *
@@ -167,19 +167,19 @@ class WallabagRestController extends FOSRestController
         $this->validateUserAccess($entry->getUser()->getId());
 
         $title = $request->request->get('title');
-        $isArchived = $request->request->get('archive');
-        $isStarred = $request->request->get('star');
+        $isArchived = (int) $request->request->get('archive');
+        $isStarred = (int) $request->request->get('starred');
 
         if (!is_null($title)) {
             $entry->setTitle($title);
         }
 
         if (!is_null($isArchived)) {
-            $entry->setArchived($isArchived);
+            $entry->setArchived((bool) $isArchived);
         }
 
         if (!is_null($isStarred)) {
-            $entry->setStarred($isStarred);
+            $entry->setStarred((bool) $isStarred);
         }
 
         $tags = $request->request->get('tags', '');
index 2e78d8b2ca9bc6b06879082f11e118649f102d5a..ccb72d23d5e13f579b99c776243f7f205833a0f8 100644 (file)
@@ -188,8 +188,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase
     {
         $this->client->request('POST', '/api/entries.json', array(
             'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
-            'archive' => true,
-            'starred' => true,
+            'archive' => '1',
+            'starred' => '1',
         ));
 
         $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -203,6 +203,24 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->assertEquals(1, $content['user_id']);
     }
 
+    public function testPostArchivedAndStarredEntryWithoutQuotes()
+    {
+        $this->client->request('POST', '/api/entries.json', array(
+            'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html',
+            'archive' => 0,
+            'starred' => 1,
+        ));
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertGreaterThan(0, $content['id']);
+        $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
+        $this->assertEquals(false, $content['is_archived']);
+        $this->assertEquals(true, $content['is_starred']);
+    }
+
     public function testPatchEntry()
     {
         $entry = $this->client->getContainer()
@@ -220,8 +238,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array(
             'title' => 'New awesome title',
             'tags' => 'new tag '.uniqid(),
-            'star' => true,
-            'archive' => false,
+            'starred' => '1',
+            'archive' => '0',
         ));
 
         $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -235,6 +253,37 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->assertEquals(1, $content['user_id']);
     }
 
+    public function testPatchEntryWithoutQuotes()
+    {
+        $entry = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUser(1);
+
+        if (!$entry) {
+            $this->markTestSkipped('No content found in db.');
+        }
+
+        // hydrate the tags relations
+        $nbTags = count($entry->getTags());
+
+        $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array(
+            'title' => 'New awesome title',
+            'tags' => 'new tag '.uniqid(),
+            'starred' => 1,
+            'archive' => 0,
+        ));
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertEquals($entry->getId(), $content['id']);
+        $this->assertEquals($entry->getUrl(), $content['url']);
+        $this->assertEquals('New awesome title', $content['title']);
+        $this->assertGreaterThan($nbTags, count($content['tags']));
+    }
+
     public function testGetTagsEntry()
     {
         $entry = $this->client->getContainer()
index f519bdbcc21ac87ce4bc9b3c3750714532a7cf99..e5cfd83c656b67209d3f78d87ae3b5d56543729f 100644 (file)
@@ -43,7 +43,7 @@ class DeveloperController extends Controller
         $clientForm->handleRequest($request);
 
         if ($clientForm->isValid()) {
-            $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password','refresh_token'));
+            $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password', 'refresh_token'));
             $em->persist($client);
             $em->flush();
 
index 5e608f05d909a57d99ab0b8a4977721d510e5ae9..8f4ddf613212d96fc640589f95646fce805ec87b 100644 (file)
@@ -59,6 +59,8 @@ class Entry
     /**
      * @var bool
      *
+     * @Exclude
+     *
      * @ORM\Column(name="is_archived", type="boolean")
      *
      * @Groups({"entries_for_user", "export_all"})
@@ -68,6 +70,8 @@ class Entry
     /**
      * @var bool
      *
+     * @Exclude
+     *
      * @ORM\Column(name="is_starred", type="boolean")
      *
      * @Groups({"entries_for_user", "export_all"})
@@ -271,6 +275,16 @@ class Entry
         return $this->isArchived;
     }
 
+    /**
+     * @VirtualProperty
+     * @SerializedName("is_archived")
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    public function is_Archived()
+    {
+        return (int) $this->isArchived();
+    }
+
     public function toggleArchive()
     {
         $this->isArchived = $this->isArchived() ^ 1;
@@ -302,6 +316,16 @@ class Entry
         return $this->isStarred;
     }
 
+    /**
+     * @VirtualProperty
+     * @SerializedName("is_starred")
+     * @Groups({"entries_for_user", "export_all"})
+     */
+    public function is_Starred()
+    {
+        return (int) $this->isStarred();
+    }
+
     public function toggleStar()
     {
         $this->isStarred = $this->isStarred() ^ 1;