From 0f00688096645606c7806a619ca27e6f30ce820c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 11:45:38 +0100 Subject: first draft of hypermedia implementation --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index e9cd8c93..cadd7e75 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -5,10 +5,12 @@ namespace Wallabag\CoreBundle\Controller; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; +use Hateoas\HateoasBuilder; class WallabagRestController extends Controller { @@ -72,6 +74,9 @@ class WallabagRestController extends Controller throw $this->createNotFoundException(); } + $hateoas = HateoasBuilder::create()->build(); + $json = $hateoas->serialize($entries, 'json'); + return $entries; } @@ -87,7 +92,10 @@ class WallabagRestController extends Controller */ public function getEntryAction(Entry $entry) { - return $entry; + $hateoas = HateoasBuilder::create()->build(); + $json = $hateoas->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 0ed6302212eec00e188c61acbd92bde80406f4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 12:00:20 +0100 Subject: returns serialzed object for GET /entries --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index cadd7e75..d48c7bbb 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -77,7 +77,7 @@ class WallabagRestController extends Controller $hateoas = HateoasBuilder::create()->build(); $json = $hateoas->serialize($entries, 'json'); - return $entries; + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From aa4d6562c196926a55819326b0fbe504daf2156f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 14:18:01 +0100 Subject: improve hateoas implementation --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index d48c7bbb..b9f7efea 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -10,7 +10,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; -use Hateoas\HateoasBuilder; class WallabagRestController extends Controller { @@ -74,8 +73,7 @@ class WallabagRestController extends Controller throw $this->createNotFoundException(); } - $hateoas = HateoasBuilder::create()->build(); - $json = $hateoas->serialize($entries, 'json'); + $json = $this->get('serializer')->serialize($entries, 'json'); return new Response($json, 200, array('application/json')); } @@ -92,8 +90,7 @@ class WallabagRestController extends Controller */ public function getEntryAction(Entry $entry) { - $hateoas = HateoasBuilder::create()->build(); - $json = $hateoas->serialize($entry, 'json'); + $json = $this->get('serializer')->serialize($entry, 'json'); return new Response($json, 200, array('application/json')); } @@ -124,7 +121,9 @@ class WallabagRestController extends Controller $em->persist($entry); $em->flush(); - return $entry; + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 1d14779154481b320e1c44fccf2558d8c9fa43a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 15:36:25 +0100 Subject: remove isDeleted flag --- .../CoreBundle/Controller/EntryController.php | 5 +++-- .../Controller/WallabagRestController.php | 22 ++++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 81ab7788..8a8f3cd7 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -192,8 +192,9 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $entry->setDeleted(1); - $this->getDoctrine()->getManager()->flush(); + $em = $this->getDoctrine()->getManager(); + $em->remove($entry); + $em->flush(); $this->get('session')->getFlashBag()->add( 'notice', diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index b9f7efea..276cfe1c 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -43,7 +43,6 @@ class WallabagRestController extends Controller * 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"="delete", "dataType"="boolean", "required"=false, "format"="true or false, default '0'", "description"="filter by deleted 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."}, @@ -57,7 +56,6 @@ class WallabagRestController extends Controller { $isArchived = $request->query->get('archive'); $isStarred = $request->query->get('star'); - $isDeleted = $request->query->get('delete', 0); $sort = $request->query->get('sort', 'created'); $order = $request->query->get('order', 'desc'); $page = $request->query->get('page', 1); @@ -67,7 +65,7 @@ class WallabagRestController extends Controller $entries = $this ->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') - ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $isDeleted, $sort, $order); + ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); if (!($entries)) { throw $this->createNotFoundException(); @@ -138,8 +136,7 @@ class WallabagRestController extends Controller * {"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"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."}, - * } + * } * ) * @return Entry */ @@ -148,7 +145,6 @@ class WallabagRestController extends Controller $title = $request->request->get("title"); $tags = $request->request->get("tags", array()); $isArchived = $request->request->get("archive"); - $isDeleted = $request->request->get("delete"); $isStarred = $request->request->get("star"); if (!is_null($title)) { @@ -159,10 +155,6 @@ class WallabagRestController extends Controller $entry->setArchived($isArchived); } - if (!is_null($isDeleted)) { - $entry->setDeleted($isDeleted); - } - if (!is_null($isStarred)) { $entry->setStarred($isStarred); } @@ -185,15 +177,13 @@ class WallabagRestController extends Controller */ public function deleteEntriesAction(Entry $entry) { - if ($entry->isDeleted()) { - throw new NotFoundHttpException('This entry is already deleted'); - } - $em = $this->getDoctrine()->getManager(); - $entry->setDeleted(1); + $em->remove($entry); $em->flush(); - return $entry; + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 2691cf04384239c546e141af6cc3c22b210dae58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 16:38:24 +0100 Subject: GET /api/tags/id_tag method --- .../CoreBundle/Controller/WallabagRestController.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 276cfe1c..cb68784d 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -6,7 +6,6 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; @@ -244,12 +243,24 @@ class WallabagRestController extends Controller * * @ApiDoc( * requirements={ - * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} + * {"name"="label", "dataType"="string", "requirement"="\w+", "description"="Label of the tag"} * } * ) */ - public function getTagAction(Tag $tag) + public function getTagAction($label) { + $tag = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($label); + + if (is_null($tag)) { + throw $this->createNotFoundException(); + } + + $json = $this->get('serializer')->serialize($tag, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 6d37a7e6c11666c2c220c9eb358a877f15bcfa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 17:20:12 +0100 Subject: remove dumb code --- .../Controller/WallabagRestController.php | 28 ++-------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index cb68784d..2384325f 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -232,37 +232,13 @@ class WallabagRestController extends Controller * Retrieve all tags * * @ApiDoc( + * {"name"="user", "dataType"="integer", "requirement"="\w+", "description"="The user ID"} * ) */ - public function getTagsAction() + public function getTagsUserAction() { } - /** - * Retrieve a single tag - * - * @ApiDoc( - * requirements={ - * {"name"="label", "dataType"="string", "requirement"="\w+", "description"="Label of the tag"} - * } - * ) - */ - public function getTagAction($label) - { - $tag = $this - ->getDoctrine() - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($label); - - if (is_null($tag)) { - throw $this->createNotFoundException(); - } - - $json = $this->get('serializer')->serialize($tag, 'json'); - - return new Response($json, 200, array('application/json')); - } - /** * Permanently remove one tag from **every** entry * -- cgit v1.2.3 From 0a018fe03980b35c9f7aca838e67a8efa43b7f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 20:29:33 +0100 Subject: add relation between entry and tag --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 2384325f..b895b67c 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -196,6 +196,9 @@ class WallabagRestController extends Controller */ public function getEntriesTagsAction(Entry $entry) { + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 1bd12b62296569764ac329d88e964059dec530be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Feb 2015 20:36:05 +0100 Subject: fix GET /api/entries/{entry}/tags --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index b895b67c..db9cf1be 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -196,7 +196,7 @@ class WallabagRestController extends Controller */ public function getEntriesTagsAction(Entry $entry) { - $json = $this->get('serializer')->serialize($entry, 'json'); + $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); return new Response($json, 200, array('application/json')); } -- cgit v1.2.3 From a36737f4859e3acbddf5cfe90c279ba725a6d88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 24 Feb 2015 22:00:24 +0100 Subject: POST entries/tags with test --- .../Controller/WallabagRestController.php | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index db9cf1be..e59ad4b7 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -213,8 +213,34 @@ class WallabagRestController extends Controller * } * ) */ - public function postEntriesTagsAction(Entry $entry) + public function postEntriesTagsAction(Request $request, Entry $entry) { + $tags = explode(',', $request->request->get('tags')); + + foreach ($tags as $label) { + $tagEntity = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($label); + + if (is_null($tagEntity)) { + $tagEntity = new Tag(); + $tagEntity->setLabel($label); + } + + // only add the tag on the entry if the relation doesn't exist + if (!$entry->getTags()->contains($tagEntity)) { + $entry->addTag($tagEntity); + } + } + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From 092ca70725b0263390e45c46f93828c613eca3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 26 Feb 2015 09:41:42 +0100 Subject: add relation between user and tags, tests are broken --- .../Controller/WallabagRestController.php | 104 ++++++++++++++++----- 1 file changed, 81 insertions(+), 23 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index e59ad4b7..81bfbe12 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -9,9 +9,35 @@ use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; class WallabagRestController extends Controller { + /** + * @param Entry $entry + * @param string $tags + */ + private function assignTagsToEntry(Entry $entry, $tags) + { + foreach (explode(',', $tags) as $label) { + $label = trim($label); + $tagEntity = $this + ->getDoctrine() + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($label); + + if (is_null($tagEntity)) { + $tagEntity = new Tag($this->getUser()); + $tagEntity->setLabel($label); + } + + // only add the tag on the entry if the relation doesn't exist + if (!$entry->getTags()->contains($tagEntity)) { + $entry->addTag($tagEntity); + } + } + } + /** * Retrieve salt for a giver user. * @@ -87,6 +113,10 @@ class WallabagRestController extends Controller */ public function getEntryAction(Entry $entry) { + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + $json = $this->get('serializer')->serialize($entry, 'json'); return new Response($json, 200, array('application/json')); @@ -106,7 +136,6 @@ class WallabagRestController extends Controller */ public function postEntriesAction(Request $request) { - //TODO gérer si on passe les tags $url = $request->request->get('url'); $content = Extractor::extract($url); @@ -114,6 +143,9 @@ class WallabagRestController extends Controller $entry->setUrl($url); $entry->setTitle($request->request->get('title') ?: $content->getTitle()); $entry->setContent($content->getBody()); + + $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -141,8 +173,11 @@ class WallabagRestController extends Controller */ public function patchEntriesAction(Entry $entry, Request $request) { + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + $title = $request->request->get("title"); - $tags = $request->request->get("tags", array()); $isArchived = $request->request->get("archive"); $isStarred = $request->request->get("star"); @@ -158,6 +193,8 @@ class WallabagRestController extends Controller $entry->setStarred($isStarred); } + $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $em = $this->getDoctrine()->getManager(); $em->flush(); @@ -176,6 +213,10 @@ class WallabagRestController extends Controller */ public function deleteEntriesAction(Entry $entry) { + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + $em = $this->getDoctrine()->getManager(); $em->remove($entry); $em->flush(); @@ -196,6 +237,12 @@ class WallabagRestController extends Controller */ public function getEntriesTagsAction(Entry $entry) { + var_dump($entry->getUser()->getId()); + var_dump($this->getUser()->getId()); + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); return new Response($json, 200, array('application/json')); @@ -215,25 +262,12 @@ class WallabagRestController extends Controller */ public function postEntriesTagsAction(Request $request, Entry $entry) { - $tags = explode(',', $request->request->get('tags')); - - foreach ($tags as $label) { - $tagEntity = $this - ->getDoctrine() - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($label); - - if (is_null($tagEntity)) { - $tagEntity = new Tag(); - $tagEntity->setLabel($label); - } - - // only add the tag on the entry if the relation doesn't exist - if (!$entry->getTags()->contains($tagEntity)) { - $entry->addTag($tagEntity); - } + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); } + $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -255,17 +289,30 @@ class WallabagRestController extends Controller */ public function deleteEntriesTagsAction(Entry $entry, Tag $tag) { + if ($entry->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + + $entry->removeTag($tag); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new Response($json, 200, array('application/json')); } /** * Retrieve all tags * - * @ApiDoc( - * {"name"="user", "dataType"="integer", "requirement"="\w+", "description"="The user ID"} - * ) + * @ApiDoc() */ - public function getTagsUserAction() + public function getTagsAction() { + $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); + + return new Response($json, 200, array('application/json')); } /** @@ -279,5 +326,16 @@ class WallabagRestController extends Controller */ public function deleteTagAction(Tag $tag) { + if ($tag->getUser()->getId() != $this->getUser()->getId()) { + throw $this->createAccessDeniedException(); + } + + $em = $this->getDoctrine()->getManager(); + $em->remove($tag); + $em->flush(); + + $json = $this->get('serializer')->serialize($tag, 'json'); + + return new Response($json, 200, array('application/json')); } } -- cgit v1.2.3 From d8f9f37ab2deb172f8dfc58b3b3775990188762f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 26 Feb 2015 12:35:59 +0100 Subject: remove debug lines --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 81bfbe12..4215e447 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -237,8 +237,6 @@ class WallabagRestController extends Controller */ public function getEntriesTagsAction(Entry $entry) { - var_dump($entry->getUser()->getId()); - var_dump($this->getUser()->getId()); if ($entry->getUser()->getId() != $this->getUser()->getId()) { throw $this->createAccessDeniedException(); } -- cgit v1.2.3 From 0ca374e6a1698926b08635d6a276ff3bf91c76a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 26 Feb 2015 14:25:40 +0100 Subject: replace Response with JsonResponse --- .../Controller/WallabagRestController.php | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 4215e447..a382caf7 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -5,11 +5,10 @@ namespace Wallabag\CoreBundle\Controller; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; class WallabagRestController extends Controller { @@ -48,12 +47,12 @@ class WallabagRestController extends Controller * ) * @return array */ - public function getSaltAction($username) + public function getSaltAction(Request $request) { $user = $this ->getDoctrine() ->getRepository('WallabagCoreBundle:User') - ->findOneByUsername($username); + ->findOneByUsername($request->query->get('username')); if (is_null($user)) { throw $this->createNotFoundException(); @@ -98,7 +97,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entries, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -119,7 +118,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -144,7 +143,10 @@ class WallabagRestController extends Controller $entry->setTitle($request->request->get('title') ?: $content->getTitle()); $entry->setContent($content->getBody()); - $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } $em = $this->getDoctrine()->getManager(); $em->persist($entry); @@ -152,7 +154,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -193,12 +195,17 @@ class WallabagRestController extends Controller $entry->setStarred($isStarred); } - $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } $em = $this->getDoctrine()->getManager(); $em->flush(); - return $entry; + $json = $this->get('serializer')->serialize($entry, 'json'); + + return new JsonResponse($json, 200); } /** @@ -223,7 +230,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -243,7 +250,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -264,7 +271,10 @@ class WallabagRestController extends Controller throw $this->createAccessDeniedException(); } - $this->assignTagsToEntry($entry, $request->request->get('tags', array())); + $tags = $request->request->get('tags', ''); + if (!empty($tags)) { + $this->assignTagsToEntry($entry, $tags); + } $em = $this->getDoctrine()->getManager(); $em->persist($entry); @@ -272,7 +282,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -298,7 +308,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -310,7 +320,7 @@ class WallabagRestController extends Controller { $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } /** @@ -334,6 +344,6 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($tag, 'json'); - return new Response($json, 200, array('application/json')); + return new JsonResponse($json, 200); } } -- cgit v1.2.3 From 6ee416a06963916ca8050e7711538d4e9463a2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 26 Feb 2015 15:00:28 +0100 Subject: commit bug with getSalt --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index a382caf7..81974371 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -40,19 +40,15 @@ class WallabagRestController extends Controller /** * Retrieve salt for a giver user. * - * @ApiDoc( - * parameters={ - * {"name"="username", "dataType"="string", "required"=true, "description"="username"} - * } - * ) + * @ApiDoc() * @return array */ - public function getSaltAction(Request $request) + public function getSaltAction($username) { $user = $this ->getDoctrine() ->getRepository('WallabagCoreBundle:User') - ->findOneByUsername($request->query->get('username')); + ->findOneByUsername($username); if (is_null($user)) { throw $this->createNotFoundException(); -- cgit v1.2.3 From b0cce9e6369b0b821c01163a0e4df5552f9924f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 27 Feb 2015 15:24:36 +0100 Subject: fix tests for GET /entries/tags --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 81974371..e25ac6db 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -6,6 +6,7 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; @@ -246,7 +247,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** -- cgit v1.2.3 From db2b4bf678c4c9e778ed0b817df182c9ee06520f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 27 Feb 2015 17:51:36 +0100 Subject: remove JsonResponse --- .../CoreBundle/Controller/WallabagRestController.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index e25ac6db..612c59d1 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -5,7 +5,6 @@ namespace Wallabag\CoreBundle\Controller; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -94,7 +93,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entries, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -115,7 +114,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -151,7 +150,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -202,7 +201,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -227,7 +226,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -279,7 +278,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -305,7 +304,7 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($entry, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -317,7 +316,7 @@ class WallabagRestController extends Controller { $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } /** @@ -341,6 +340,6 @@ class WallabagRestController extends Controller $json = $this->get('serializer')->serialize($tag, 'json'); - return new JsonResponse($json, 200); + return new Response($json, 200, array('application/json')); } } -- cgit v1.2.3 From efad7e53a1e881dd686c003b624b429ee1e5b52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 5 Mar 2015 19:34:30 +0100 Subject: add more log on AccessDeniedException --- .../Controller/WallabagRestController.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 612c59d1..3e25fe49 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -40,7 +40,11 @@ class WallabagRestController extends Controller /** * Retrieve salt for a giver user. * - * @ApiDoc() + * @ApiDoc( + * parameters={ + * {"name"="username", "dataType"="string", "required"=true, "description"="username"} + * } + * ) * @return array */ public function getSaltAction($username) @@ -87,7 +91,7 @@ class WallabagRestController extends Controller ->getRepository('WallabagCoreBundle:Entry') ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); - if (!($entries)) { + if (!$entries) { throw $this->createNotFoundException(); } @@ -109,7 +113,7 @@ class WallabagRestController extends Controller public function getEntryAction(Entry $entry) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $json = $this->get('serializer')->serialize($entry, 'json'); @@ -172,7 +176,7 @@ class WallabagRestController extends Controller public function patchEntriesAction(Entry $entry, Request $request) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $title = $request->request->get("title"); @@ -217,7 +221,7 @@ class WallabagRestController extends Controller public function deleteEntriesAction(Entry $entry) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $em = $this->getDoctrine()->getManager(); @@ -241,7 +245,7 @@ class WallabagRestController extends Controller public function getEntriesTagsAction(Entry $entry) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); @@ -264,7 +268,7 @@ class WallabagRestController extends Controller public function postEntriesTagsAction(Request $request, Entry $entry) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $tags = $request->request->get('tags', ''); @@ -294,7 +298,7 @@ class WallabagRestController extends Controller public function deleteEntriesTagsAction(Entry $entry, Tag $tag) { if ($entry->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $entry->removeTag($tag); @@ -331,7 +335,7 @@ class WallabagRestController extends Controller public function deleteTagAction(Tag $tag) { if ($tag->getUser()->getId() != $this->getUser()->getId()) { - throw $this->createAccessDeniedException(); + throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$tag->getUser()->getId().', logged user id: '.$this->getUser()->getId()); } $em = $this->getDoctrine()->getManager(); -- cgit v1.2.3 From 6e22bd737b2e543c85487864a9a25b0f2d5cc3f2 Mon Sep 17 00:00:00 2001 From: William Durand Date: Fri, 6 Mar 2015 11:07:39 +0100 Subject: Use pager in getEntries() and return Hateoas collection --- .../Controller/WallabagRestController.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 3e25fe49..14f42c48 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -9,6 +9,8 @@ use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Service\Extractor; +use Hateoas\Configuration\Route; +use Hateoas\Representation\Factory\PagerfantaFactory; class WallabagRestController extends Controller { @@ -82,20 +84,29 @@ class WallabagRestController extends Controller $isStarred = $request->query->get('star'); $sort = $request->query->get('sort', 'created'); $order = $request->query->get('order', 'desc'); - $page = $request->query->get('page', 1); - $perPage = $request->query->get('perPage', 30); + $page = (int) $request->query->get('page', 1); + $perPage = (int) $request->query->get('perPage', 30); $tags = $request->query->get('tags', array()); - $entries = $this + $pager = $this ->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); - if (!$entries) { + if (0 === $pager->getNbResults()) { throw $this->createNotFoundException(); } - $json = $this->get('serializer')->serialize($entries, 'json'); + $pager->setCurrentPage($page); + $pager->setMaxPerPage($perPage); + + $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); + $paginatedCollection = $pagerfantaFactory->createRepresentation( + $pager, + new Route('api_get_entries', [], $absolute = true) + ); + + $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); return new Response($json, 200, array('application/json')); } -- cgit v1.2.3