/** * 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.'); } }
/** * 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 RedirectResponse */ public function deleteTaggingRuleAction(TaggingRule $rule) { if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { throw $this->createAccessDeniedException('You can not access this tagging rule.'); } $em = $this->getDoctrine()->getManager(); $em->remove($rule); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'flashes.config.notice.tagging_rules_deleted'); return $this->redirect($this->generateUrl('config') . '#set5'); }