Block not active snip version editing

This commit is contained in:
Tim 2025-04-23 23:47:14 +02:00
parent bf55e069e0
commit d906b980c4
2 changed files with 17 additions and 0 deletions

View File

@ -81,6 +81,15 @@ class SnipController extends AbstractController
{ {
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
/**
* Temporary solution to prevent editing of old versions
* It technically fully works, but rendering the version history needs an update first
*/
$isLatest = $snip->getActiveVersion() === $snip->getLatestVersion();
if(!$isLatest) {
$this->addFlash('error', 'Snip is not the latest version, changes will not be saved.');
}
$form = $this->createForm(SnipType::class, $snip); $form = $this->createForm(SnipType::class, $snip);
$form->add('Save', SubmitType::class); $form->add('Save', SubmitType::class);
if ($snip->getId()) { if ($snip->getId()) {
@ -89,6 +98,11 @@ class SnipController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
if (!$isLatest) {
return $this->redirectToRoute('snip_single', [
'snip' => $snip->getId(),
]);
}
$this->repository->save($snip); $this->repository->save($snip);
$this->contentService->update($snip, $form->get('content')->getData()); $this->contentService->update($snip, $form->get('content')->getData());

View File

@ -35,6 +35,9 @@ class SnipTwigExtension extends AbstractExtension
function snipLink(int $id): string function snipLink(int $id): string
{ {
$snip = $this->snipRepo->find($id); $snip = $this->snipRepo->find($id);
if ($snip === null) {
throw new \Exception(sprintf('Snip not found with id: %d', $id));
}
return sprintf('<a class="btn btn-sm btn-primary" href="%s">%s</a>', $this->snipPath($id), $snip); return sprintf('<a class="btn btn-sm btn-primary" href="%s">%s</a>', $this->snipPath($id), $snip);
} }
} }