]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Provide a way to delete tagging rules
authorKévin Gomez <contact@kevingomez.fr>
Sun, 25 Oct 2015 09:45:15 +0000 (10:45 +0100)
committerKévin Gomez <contact@kevingomez.fr>
Wed, 11 Nov 2015 15:27:19 +0000 (16:27 +0100)
src/Wallabag/CoreBundle/Controller/ConfigController.php
src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig

index 24b86344b25aa8073442a91fcc86df51677bb4cd..de1536c91d92cbdccece2b5a3d065d069e032243 100644 (file)
@@ -188,6 +188,33 @@ class ConfigController extends Controller
         return $request->headers->get('referer') ? $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('config');
     }
 
+    /**
+     * Deletes a tagging rule and redirect to the config homepage.
+     *
+     * @param TaggingRule $rule
+     *
+     * @Route("/tagging-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_tagging_rule")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function deleteTaggingRule(TaggingRule $rule)
+    {
+        if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) {
+            throw $this->createAccessDeniedException('You can not access this tagging ryle.');
+        }
+
+        $em = $this->getDoctrine()->getManager();
+        $em->remove($rule);
+        $em->flush();
+
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            'Tagging rule deleted'
+        );
+
+        return $this->redirect($this->generateUrl('config'));
+    }
+
     /**
      * Retrieve config for the current user.
      * If no config were found, create a new one.
index 993c58265eff76373779a7511e9f27798978d464..1457fe51eb486eaca51c2c7192a66880e0b45e7d 100644 (file)
                                     {% for tagging_rule in app.user.config.taggingRules %}
                                     <li>
                                         if « {{ tagging_rule.rule }} » then tag as « {{ tagging_rule.tags|join(', ') }} »
+                                        <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{% trans %}Delete{% endtrans %}">
+                                            <i class="tool grey-text delete mdi-action-delete"></i>
+                                        </a>
                                     </li>
                                     {% endfor %}
                                 </ul>