Allow deleting snips (including git repo)
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Form\ConfirmationType;
|
||||
use App\Form\SnipType;
|
||||
use App\Repository\SnipRepository;
|
||||
use App\Security\Voter\SnipVoter;
|
||||
@ -96,7 +97,7 @@ class SnipController extends AbstractController
|
||||
$this->repository->save($snip);
|
||||
$this->snipServiceFactory->create($snip)->update($form->get('content')->getData());
|
||||
|
||||
$this->addFlash('success', sprintf('Snip "%s" saved successfully', $snip));
|
||||
$this->addFlash('success', sprintf('Snip "%s" saved', $snip));
|
||||
|
||||
return $this->redirectToRoute('snip_single', [
|
||||
'snip' => $snip->getId(),
|
||||
@ -118,4 +119,24 @@ class SnipController extends AbstractController
|
||||
|
||||
return $this->edit($snip, $request);
|
||||
}
|
||||
|
||||
#[Route('/delete/{snip}', name: '_delete')]
|
||||
public function delete(Snip $snip, Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
|
||||
|
||||
$form = $this->createForm(ConfirmationType::class);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->snipServiceFactory->create($snip)->deleteRepo();
|
||||
$this->repository->remove($snip);
|
||||
$this->addFlash('success', sprintf('Snip "%s" deleted', $snip));
|
||||
return $this->redirectToRoute('snip_index');
|
||||
}
|
||||
|
||||
return $this->render('form.html.twig', [
|
||||
'message' => sprintf('Do you really want to delete "%s"?', $snip),
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user