]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Introduce validateRuleAction
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 1 Oct 2016 15:24:24 +0000 (17:24 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 1 Oct 2016 15:24:24 +0000 (17:24 +0200)
src/Wallabag/CoreBundle/Controller/ConfigController.php

index 28e33998d12a63f82cf688f3f7c3c5dbedc4181b..4dd4e40cae93fcc1484f2ced5f98d5f4307e4a03 100644 (file)
@@ -219,9 +219,7 @@ class ConfigController extends Controller
      */
     public function deleteTaggingRuleAction(TaggingRule $rule)
     {
-        if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) {
-            throw $this->createAccessDeniedException('You can not access this tagging rule.');
-        }
+        $this->validateRuleAction($rule);
 
         $em = $this->getDoctrine()->getManager();
         $em->remove($rule);
@@ -245,12 +243,22 @@ class ConfigController extends Controller
      * @return RedirectResponse
      */
     public function editTaggingRuleAction(TaggingRule $rule)
+    {
+        $this->validateRuleAction($rule);
+
+        return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5');
+    }
+
+    /**
+     * Validate that a rule can be edited/deleted by the current user
+     *
+     * @param  TaggingRule $rule
+     */
+    private function validateRuleAction(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');
     }
 
     /**