From 0d3043a29c4aba541d6a18c2d5cc7ebffc6ddc78 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 15 Mar 2016 18:50:13 +0100 Subject: fix api properties and typo --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 4 ++-- .../ApiBundle/Tests/Controller/WallabagRestControllerTest.php | 4 ++-- src/Wallabag/CoreBundle/Controller/DeveloperController.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 2633a311..3265ba38 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -126,11 +126,11 @@ class WallabagRestController extends FOSRestController $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } - if (true === (bool) $isStarred) { + if ($isStarred === 'true') { $entry->setStarred(true); } - if (true === (bool) $isArchived) { + if ($isArchived === 'true') { $entry->setArchived(true); } diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index 2e78d8b2..f5a9748c 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -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' => 'true', + 'starred' => 'true', )); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php index f519bdbc..e5cfd83c 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php @@ -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(); -- cgit v1.2.3 From 189ef6342a3f9befec379c406821ed10730cacd2 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 16 Mar 2016 20:41:29 +0100 Subject: use integers for archived/starred status --- .../Controller/WallabagRestController.php | 36 +++++++++++----------- .../Controller/WallabagRestControllerTest.php | 8 ++--- src/Wallabag/CoreBundle/Entity/Entry.php | 24 +++++++++++++++ 3 files changed, 46 insertions(+), 22 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 3265ba38..d0a35013 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -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,11 +126,11 @@ class WallabagRestController extends FOSRestController $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } - if ($isStarred === 'true') { + if (true === (bool) $isStarred) { $entry->setStarred(true); } - if ($isArchived === 'true') { + if (true === (bool) $isArchived) { $entry->setArchived(true); } @@ -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', ''); diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index f5a9748c..6bc7afa6 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -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()); @@ -220,8 +220,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()); diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 5e608f05..8f4ddf61 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -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; -- cgit v1.2.3 From 2f60e5ea7566e4b2904f274bc94efea390d9ecd8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 16 Mar 2016 21:38:50 +0100 Subject: check if archive/star parameters without quotes work --- .../Controller/WallabagRestControllerTest.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index 6bc7afa6..ccb72d23 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -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() @@ -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() -- cgit v1.2.3 From 0cd0d6eb8c5a7a6ba04f1086b16f9612acbc9b68 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 16 Mar 2016 22:43:32 +0100 Subject: fix updating entry status through API --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index d0a35013..a590dda1 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -126,13 +126,9 @@ class WallabagRestController extends FOSRestController $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } - if (true === (bool) $isStarred) { - $entry->setStarred(true); - } + $entry->setStarred((bool) $isStarred); - if (true === (bool) $isArchived) { - $entry->setArchived(true); - } + $entry->setArchived((bool) $isArchived); $em = $this->getDoctrine()->getManager(); $em->persist($entry); -- cgit v1.2.3 From bc2b947cd54e49a03c267f3c0f13dc5b8a04d962 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 16 Mar 2016 22:47:12 +0100 Subject: add check --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index a590dda1..744e1a60 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -126,9 +126,13 @@ class WallabagRestController extends FOSRestController $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } - $entry->setStarred((bool) $isStarred); + if (!is_null($isStarred)) { + $entry->setStarred((bool) $isStarred); + } - $entry->setArchived((bool) $isArchived); + if (!is_null($isArchived)) { + $entry->setArchived((bool) $isArchived); + } $em = $this->getDoctrine()->getManager(); $em->persist($entry); -- cgit v1.2.3