aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php16
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php6
-rw-r--r--src/Wallabag/CoreBundle/Controller/SecurityController.php9
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php360
5 files changed, 18 insertions, 375 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 898c291f..62ef3eea 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -133,7 +133,7 @@ class ConfigController extends Controller
133 'rss' => array( 133 'rss' => array(
134 'username' => $user->getUsername(), 134 'username' => $user->getUsername(),
135 'token' => $config->getRssToken(), 135 'token' => $config->getRssToken(),
136 ) 136 ),
137 )); 137 ));
138 } 138 }
139 139
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 8a8f3cd7..7fd982c9 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -50,7 +50,7 @@ class EntryController extends Controller
50 } 50 }
51 51
52 /** 52 /**
53 * Shows unread entries for current user 53 * Shows unread entries for current user.
54 * 54 *
55 * @Route("/unread", name="unread") 55 * @Route("/unread", name="unread")
56 * 56 *
@@ -70,7 +70,7 @@ class EntryController extends Controller
70 } 70 }
71 71
72 /** 72 /**
73 * Shows read entries for current user 73 * Shows read entries for current user.
74 * 74 *
75 * @Route("/archive", name="archive") 75 * @Route("/archive", name="archive")
76 * 76 *
@@ -90,7 +90,7 @@ class EntryController extends Controller
90 } 90 }
91 91
92 /** 92 /**
93 * Shows starred entries for current user 93 * Shows starred entries for current user.
94 * 94 *
95 * @Route("/starred", name="starred") 95 * @Route("/starred", name="starred")
96 * 96 *
@@ -110,7 +110,7 @@ class EntryController extends Controller
110 } 110 }
111 111
112 /** 112 /**
113 * Shows entry content 113 * Shows entry content.
114 * 114 *
115 * @param Entry $entry 115 * @param Entry $entry
116 * 116 *
@@ -129,7 +129,7 @@ class EntryController extends Controller
129 } 129 }
130 130
131 /** 131 /**
132 * Changes read status for an entry 132 * Changes read status for an entry.
133 * 133 *
134 * @param Request $request 134 * @param Request $request
135 * @param Entry $entry 135 * @param Entry $entry
@@ -154,7 +154,7 @@ class EntryController extends Controller
154 } 154 }
155 155
156 /** 156 /**
157 * Changes favorite status for an entry 157 * Changes favorite status for an entry.
158 * 158 *
159 * @param Request $request 159 * @param Request $request
160 * @param Entry $entry 160 * @param Entry $entry
@@ -179,7 +179,7 @@ class EntryController extends Controller
179 } 179 }
180 180
181 /** 181 /**
182 * Deletes entry 182 * Deletes entry.
183 * 183 *
184 * @param Request $request 184 * @param Request $request
185 * @param Entry $entry 185 * @param Entry $entry
@@ -205,7 +205,7 @@ class EntryController extends Controller
205 } 205 }
206 206
207 /** 207 /**
208 * Check if the logged user can manage the given entry 208 * Check if the logged user can manage the given entry.
209 * 209 *
210 * @param Entry $entry 210 * @param Entry $entry
211 */ 211 */
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php
index 14f1dcb2..86754e15 100644
--- a/src/Wallabag/CoreBundle/Controller/RssController.php
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -11,7 +11,7 @@ use Wallabag\CoreBundle\Entity\Entry;
11class RssController extends Controller 11class RssController extends Controller
12{ 12{
13 /** 13 /**
14 * Shows unread entries for current user 14 * Shows unread entries for current user.
15 * 15 *
16 * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) 16 * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"})
17 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") 17 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
@@ -35,7 +35,7 @@ class RssController extends Controller
35 } 35 }
36 36
37 /** 37 /**
38 * Shows read entries for current user 38 * Shows read entries for current user.
39 * 39 *
40 * @Route("/{username}/{token}/archive.xml", name="archive_rss") 40 * @Route("/{username}/{token}/archive.xml", name="archive_rss")
41 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") 41 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
@@ -59,7 +59,7 @@ class RssController extends Controller
59 } 59 }
60 60
61 /** 61 /**
62 * Shows starred entries for current user 62 * Shows starred entries for current user.
63 * 63 *
64 * @Route("/{username}/{token}/starred.xml", name="starred_rss") 64 * @Route("/{username}/{token}/starred.xml", name="starred_rss")
65 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") 65 * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter")
diff --git a/src/Wallabag/CoreBundle/Controller/SecurityController.php b/src/Wallabag/CoreBundle/Controller/SecurityController.php
index fe511db5..a61a898b 100644
--- a/src/Wallabag/CoreBundle/Controller/SecurityController.php
+++ b/src/Wallabag/CoreBundle/Controller/SecurityController.php
@@ -30,9 +30,10 @@ class SecurityController extends Controller
30 } 30 }
31 31
32 /** 32 /**
33 * Request forgot password: show form 33 * Request forgot password: show form.
34 * 34 *
35 * @Route("/forgot-password", name="forgot_password") 35 * @Route("/forgot-password", name="forgot_password")
36 *
36 * @Method({"GET", "POST"}) 37 * @Method({"GET", "POST"})
37 */ 38 */
38 public function forgotPasswordAction(Request $request) 39 public function forgotPasswordAction(Request $request)
@@ -73,9 +74,10 @@ class SecurityController extends Controller
73 } 74 }
74 75
75 /** 76 /**
76 * Tell the user to check his email provider 77 * Tell the user to check his email provider.
77 * 78 *
78 * @Route("/forgot-password/check-email", name="forgot_password_check_email") 79 * @Route("/forgot-password/check-email", name="forgot_password_check_email")
80 *
79 * @Method({"GET"}) 81 * @Method({"GET"})
80 */ 82 */
81 public function checkEmailAction(Request $request) 83 public function checkEmailAction(Request $request)
@@ -93,9 +95,10 @@ class SecurityController extends Controller
93 } 95 }
94 96
95 /** 97 /**
96 * Reset user password 98 * Reset user password.
97 * 99 *
98 * @Route("/forgot-password/{token}", name="forgot_password_reset") 100 * @Route("/forgot-password/{token}", name="forgot_password_reset")
101 *
99 * @Method({"GET", "POST"}) 102 * @Method({"GET", "POST"})
100 */ 103 */
101 public function resetAction(Request $request, $token) 104 public function resetAction(Request $request, $token)
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
deleted file mode 100644
index 14f42c48..00000000
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ /dev/null
@@ -1,360 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Nelmio\ApiDocBundle\Annotation\ApiDoc;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response;
9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\CoreBundle\Service\Extractor;
12use Hateoas\Configuration\Route;
13use Hateoas\Representation\Factory\PagerfantaFactory;
14
15class WallabagRestController extends Controller
16{
17 /**
18 * @param Entry $entry
19 * @param string $tags
20 */
21 private function assignTagsToEntry(Entry $entry, $tags)
22 {
23 foreach (explode(',', $tags) as $label) {
24 $label = trim($label);
25 $tagEntity = $this
26 ->getDoctrine()
27 ->getRepository('WallabagCoreBundle:Tag')
28 ->findOneByLabel($label);
29
30 if (is_null($tagEntity)) {
31 $tagEntity = new Tag($this->getUser());
32 $tagEntity->setLabel($label);
33 }
34
35 // only add the tag on the entry if the relation doesn't exist
36 if (!$entry->getTags()->contains($tagEntity)) {
37 $entry->addTag($tagEntity);
38 }
39 }
40 }
41
42 /**
43 * Retrieve salt for a giver user.
44 *
45 * @ApiDoc(
46 * parameters={
47 * {"name"="username", "dataType"="string", "required"=true, "description"="username"}
48 * }
49 * )
50 * @return array
51 */
52 public function getSaltAction($username)
53 {
54 $user = $this
55 ->getDoctrine()
56 ->getRepository('WallabagCoreBundle:User')
57 ->findOneByUsername($username);
58
59 if (is_null($user)) {
60 throw $this->createNotFoundException();
61 }
62
63 return array($user->getSalt() ?: null);
64 }
65 /**
66 * Retrieve all entries. It could be filtered by many options.
67 *
68 * @ApiDoc(
69 * parameters={
70 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."},
71 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."},
72 * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
73 * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
74 * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
75 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."},
76 * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
77 * }
78 * )
79 * @return Entry
80 */
81 public function getEntriesAction(Request $request)
82 {
83 $isArchived = $request->query->get('archive');
84 $isStarred = $request->query->get('star');
85 $sort = $request->query->get('sort', 'created');
86 $order = $request->query->get('order', 'desc');
87 $page = (int) $request->query->get('page', 1);
88 $perPage = (int) $request->query->get('perPage', 30);
89 $tags = $request->query->get('tags', array());
90
91 $pager = $this
92 ->getDoctrine()
93 ->getRepository('WallabagCoreBundle:Entry')
94 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
95
96 if (0 === $pager->getNbResults()) {
97 throw $this->createNotFoundException();
98 }
99
100 $pager->setCurrentPage($page);
101 $pager->setMaxPerPage($perPage);
102
103 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
104 $paginatedCollection = $pagerfantaFactory->createRepresentation(
105 $pager,
106 new Route('api_get_entries', [], $absolute = true)
107 );
108
109 $json = $this->get('serializer')->serialize($paginatedCollection, 'json');
110
111 return new Response($json, 200, array('application/json'));
112 }
113
114 /**
115 * Retrieve a single entry
116 *
117 * @ApiDoc(
118 * requirements={
119 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
120 * }
121 * )
122 * @return Entry
123 */
124 public function getEntryAction(Entry $entry)
125 {
126 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
127 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
128 }
129
130 $json = $this->get('serializer')->serialize($entry, 'json');
131
132 return new Response($json, 200, array('application/json'));
133 }
134
135 /**
136 * Create an entry
137 *
138 * @ApiDoc(
139 * parameters={
140 * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."},
141 * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."},
142 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
143 * }
144 * )
145 * @return Entry
146 */
147 public function postEntriesAction(Request $request)
148 {
149 $url = $request->request->get('url');
150
151 $content = Extractor::extract($url);
152 $entry = new Entry($this->getUser());
153 $entry->setUrl($url);
154 $entry->setTitle($request->request->get('title') ?: $content->getTitle());
155 $entry->setContent($content->getBody());
156
157 $tags = $request->request->get('tags', '');
158 if (!empty($tags)) {
159 $this->assignTagsToEntry($entry, $tags);
160 }
161
162 $em = $this->getDoctrine()->getManager();
163 $em->persist($entry);
164 $em->flush();
165
166 $json = $this->get('serializer')->serialize($entry, 'json');
167
168 return new Response($json, 200, array('application/json'));
169 }
170
171 /**
172 * Change several properties of an entry
173 *
174 * @ApiDoc(
175 * requirements={
176 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
177 * },
178 * parameters={
179 * {"name"="title", "dataType"="string", "required"=false},
180 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
181 * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."},
182 * {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
183 * }
184 * )
185 * @return Entry
186 */
187 public function patchEntriesAction(Entry $entry, Request $request)
188 {
189 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
190 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
191 }
192
193 $title = $request->request->get("title");
194 $isArchived = $request->request->get("archive");
195 $isStarred = $request->request->get("star");
196
197 if (!is_null($title)) {
198 $entry->setTitle($title);
199 }
200
201 if (!is_null($isArchived)) {
202 $entry->setArchived($isArchived);
203 }
204
205 if (!is_null($isStarred)) {
206 $entry->setStarred($isStarred);
207 }
208
209 $tags = $request->request->get('tags', '');
210 if (!empty($tags)) {
211 $this->assignTagsToEntry($entry, $tags);
212 }
213
214 $em = $this->getDoctrine()->getManager();
215 $em->flush();
216
217 $json = $this->get('serializer')->serialize($entry, 'json');
218
219 return new Response($json, 200, array('application/json'));
220 }
221
222 /**
223 * Delete **permanently** an entry
224 *
225 * @ApiDoc(
226 * requirements={
227 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
228 * }
229 * )
230 * @return Entry
231 */
232 public function deleteEntriesAction(Entry $entry)
233 {
234 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
235 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
236 }
237
238 $em = $this->getDoctrine()->getManager();
239 $em->remove($entry);
240 $em->flush();
241
242 $json = $this->get('serializer')->serialize($entry, 'json');
243
244 return new Response($json, 200, array('application/json'));
245 }
246
247 /**
248 * Retrieve all tags for an entry
249 *
250 * @ApiDoc(
251 * requirements={
252 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
253 * }
254 * )
255 */
256 public function getEntriesTagsAction(Entry $entry)
257 {
258 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
259 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
260 }
261
262 $json = $this->get('serializer')->serialize($entry->getTags(), 'json');
263
264 return new Response($json, 200, array('application/json'));
265 }
266
267 /**
268 * Add one or more tags to an entry
269 *
270 * @ApiDoc(
271 * requirements={
272 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
273 * },
274 * parameters={
275 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
276 * }
277 * )
278 */
279 public function postEntriesTagsAction(Request $request, Entry $entry)
280 {
281 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
282 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
283 }
284
285 $tags = $request->request->get('tags', '');
286 if (!empty($tags)) {
287 $this->assignTagsToEntry($entry, $tags);
288 }
289
290 $em = $this->getDoctrine()->getManager();
291 $em->persist($entry);
292 $em->flush();
293
294 $json = $this->get('serializer')->serialize($entry, 'json');
295
296 return new Response($json, 200, array('application/json'));
297 }
298
299 /**
300 * Permanently remove one tag for an entry
301 *
302 * @ApiDoc(
303 * requirements={
304 * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"},
305 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
306 * }
307 * )
308 */
309 public function deleteEntriesTagsAction(Entry $entry, Tag $tag)
310 {
311 if ($entry->getUser()->getId() != $this->getUser()->getId()) {
312 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$entry->getUser()->getId().', logged user id: '.$this->getUser()->getId());
313 }
314
315 $entry->removeTag($tag);
316 $em = $this->getDoctrine()->getManager();
317 $em->persist($entry);
318 $em->flush();
319
320 $json = $this->get('serializer')->serialize($entry, 'json');
321
322 return new Response($json, 200, array('application/json'));
323 }
324
325 /**
326 * Retrieve all tags
327 *
328 * @ApiDoc()
329 */
330 public function getTagsAction()
331 {
332 $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json');
333
334 return new Response($json, 200, array('application/json'));
335 }
336
337 /**
338 * Permanently remove one tag from **every** entry
339 *
340 * @ApiDoc(
341 * requirements={
342 * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"}
343 * }
344 * )
345 */
346 public function deleteTagAction(Tag $tag)
347 {
348 if ($tag->getUser()->getId() != $this->getUser()->getId()) {
349 throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$tag->getUser()->getId().', logged user id: '.$this->getUser()->getId());
350 }
351
352 $em = $this->getDoctrine()->getManager();
353 $em->remove($tag);
354 $em->flush();
355
356 $json = $this->get('serializer')->serialize($tag, 'json');
357
358 return new Response($json, 200, array('application/json'));
359 }
360}