diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 66 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ExceptionController.php | 40 |
2 files changed, 91 insertions, 15 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 4f75511b..f1e212d9 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use FOS\UserBundle\Event\UserEvent; | ||
6 | use FOS\UserBundle\FOSUserEvents; | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 9 | use Symfony\Component\HttpFoundation\JsonResponse; |
@@ -106,7 +108,21 @@ class ConfigController extends Controller | |||
106 | 108 | ||
107 | // handle tagging rule | 109 | // handle tagging rule |
108 | $taggingRule = new TaggingRule(); | 110 | $taggingRule = new TaggingRule(); |
109 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $this->generateUrl('config').'#set5']); | 111 | $action = $this->generateUrl('config').'#set5'; |
112 | |||
113 | if ($request->query->has('tagging-rule')) { | ||
114 | $taggingRule = $this->getDoctrine() | ||
115 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
116 | ->find($request->query->get('tagging-rule')); | ||
117 | |||
118 | if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) { | ||
119 | return $this->redirect($action); | ||
120 | } | ||
121 | |||
122 | $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; | ||
123 | } | ||
124 | |||
125 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); | ||
110 | $newTaggingRule->handleRequest($request); | 126 | $newTaggingRule->handleRequest($request); |
111 | 127 | ||
112 | if ($newTaggingRule->isValid()) { | 128 | if ($newTaggingRule->isValid()) { |
@@ -133,18 +149,11 @@ class ConfigController extends Controller | |||
133 | $newUserForm->handleRequest($request); | 149 | $newUserForm->handleRequest($request); |
134 | 150 | ||
135 | if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { | 151 | if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { |
136 | $userManager->updateUser($newUser, true); | 152 | $userManager->updateUser($newUser); |
137 | |||
138 | $config = new Config($newUser); | ||
139 | $config->setTheme($this->getParameter('wallabag_core.theme')); | ||
140 | $config->setItemsPerPage($this->getParameter('wallabag_core.items_on_page')); | ||
141 | $config->setRssLimit($this->getParameter('wallabag_core.rss_limit')); | ||
142 | $config->setLanguage($this->getParameter('wallabag_core.language')); | ||
143 | $config->setReadingSpeed($this->getParameter('wallabag_core.reading_speed')); | ||
144 | 153 | ||
145 | $em->persist($config); | 154 | // dispatch a created event so the associated config will be created |
146 | 155 | $event = new UserEvent($newUser, $request); | |
147 | $em->flush(); | 156 | $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); |
148 | 157 | ||
149 | $this->get('session')->getFlashBag()->add( | 158 | $this->get('session')->getFlashBag()->add( |
150 | 'notice', | 159 | 'notice', |
@@ -210,9 +219,7 @@ class ConfigController extends Controller | |||
210 | */ | 219 | */ |
211 | public function deleteTaggingRuleAction(TaggingRule $rule) | 220 | public function deleteTaggingRuleAction(TaggingRule $rule) |
212 | { | 221 | { |
213 | if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { | 222 | $this->validateRuleAction($rule); |
214 | throw $this->createAccessDeniedException('You can not access this tagging rule.'); | ||
215 | } | ||
216 | 223 | ||
217 | $em = $this->getDoctrine()->getManager(); | 224 | $em = $this->getDoctrine()->getManager(); |
218 | $em->remove($rule); | 225 | $em->remove($rule); |
@@ -227,6 +234,34 @@ class ConfigController extends Controller | |||
227 | } | 234 | } |
228 | 235 | ||
229 | /** | 236 | /** |
237 | * Edit a tagging rule. | ||
238 | * | ||
239 | * @param TaggingRule $rule | ||
240 | * | ||
241 | * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule") | ||
242 | * | ||
243 | * @return RedirectResponse | ||
244 | */ | ||
245 | public function editTaggingRuleAction(TaggingRule $rule) | ||
246 | { | ||
247 | $this->validateRuleAction($rule); | ||
248 | |||
249 | return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * Validate that a rule can be edited/deleted by the current user. | ||
254 | * | ||
255 | * @param TaggingRule $rule | ||
256 | */ | ||
257 | private function validateRuleAction(TaggingRule $rule) | ||
258 | { | ||
259 | if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { | ||
260 | throw $this->createAccessDeniedException('You can not access this tagging rule.'); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | /** | ||
230 | * Retrieve config for the current user. | 265 | * Retrieve config for the current user. |
231 | * If no config were found, create a new one. | 266 | * If no config were found, create a new one. |
232 | * | 267 | * |
@@ -238,6 +273,7 @@ class ConfigController extends Controller | |||
238 | ->getRepository('WallabagCoreBundle:Config') | 273 | ->getRepository('WallabagCoreBundle:Config') |
239 | ->findOneByUser($this->getUser()); | 274 | ->findOneByUser($this->getUser()); |
240 | 275 | ||
276 | // should NEVER HAPPEN ... | ||
241 | if (!$config) { | 277 | if (!$config) { |
242 | $config = new Config($this->getUser()); | 278 | $config = new Config($this->getUser()); |
243 | } | 279 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php new file mode 100644 index 00000000..abfa9c2f --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php | |||
@@ -0,0 +1,40 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; | ||
6 | use Symfony\Component\HttpFoundation\Request; | ||
7 | |||
8 | /** | ||
9 | * This controller allow us to customize the error template. | ||
10 | * The only modified line from the parent template is for "WallabagCoreBundle". | ||
11 | */ | ||
12 | class ExceptionController extends BaseExceptionController | ||
13 | { | ||
14 | protected function findTemplate(Request $request, $format, $code, $showException) | ||
15 | { | ||
16 | $name = $showException ? 'exception' : 'error'; | ||
17 | if ($showException && 'html' == $format) { | ||
18 | $name = 'exception_full'; | ||
19 | } | ||
20 | |||
21 | // For error pages, try to find a template for the specific HTTP status code and format | ||
22 | if (!$showException) { | ||
23 | $template = sprintf('WallabagCoreBundle:Exception:%s.%s.twig', $name, $format); | ||
24 | if ($this->templateExists($template)) { | ||
25 | return $template; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | // try to find a template for the given format | ||
30 | $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); | ||
31 | if ($this->templateExists($template)) { | ||
32 | return $template; | ||
33 | } | ||
34 | |||
35 | // default to a generic HTML exception | ||
36 | $request->setRequestFormat('html'); | ||
37 | |||
38 | return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); | ||
39 | } | ||
40 | } | ||