From bf3dc999e7b25888460faff2251f75e4a79491c4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 16:47:48 +0200 Subject: Add ability to edit a tagging rule --- .../CoreBundle/Controller/ConfigController.php | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 75a9af0b..28e33998 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -108,7 +108,21 @@ class ConfigController extends Controller // handle tagging rule $taggingRule = new TaggingRule(); - $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $this->generateUrl('config').'#set5']); + $action = $this->generateUrl('config').'#set5'; + + if ($request->query->has('tagging-rule')) { + $taggingRule = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:TaggingRule') + ->find($request->query->get('tagging-rule')); + + if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) { + return $this->redirect($action); + } + + $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; + } + + $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); $newTaggingRule->handleRequest($request); if ($newTaggingRule->isValid()) { @@ -221,6 +235,24 @@ class ConfigController extends Controller return $this->redirect($this->generateUrl('config').'#set5'); } + /** + * Edit a tagging rule. + * + * @param TaggingRule $rule + * + * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule") + * + * @return RedirectResponse + */ + public function editTaggingRuleAction(TaggingRule $rule) + { + if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { + throw $this->createAccessDeniedException('You can not access this tagging rule.'); + } + + return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); + } + /** * Retrieve config for the current user. * If no config were found, create a new one. -- cgit v1.2.3