1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-26 18:21:02 +00:00

Add a validator on URL entity

This commit is contained in:
Nicolas Lœuillet 2023-08-29 14:17:53 +02:00 committed by Jeremy Benoist
parent 3f491fe9ca
commit 67c5270fdc
No known key found for this signature in database
GPG key ID: 7168D5DD29F38552
5 changed files with 78 additions and 5 deletions

View file

@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Wallabag\Entity\Entry;
use Wallabag\Entity\Tag;
use Wallabag\Event\EntryDeletedEvent;
@ -716,8 +717,15 @@ class EntryRestController extends WallabagRestController
*
* @return JsonResponse
*/
public function postEntriesAction(Request $request, EntryRepository $entryRepository, ContentProxy $contentProxy, LoggerInterface $logger, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher)
{
public function postEntriesAction(
Request $request,
EntryRepository $entryRepository,
ContentProxy $contentProxy,
LoggerInterface $logger,
TagsAssigner $tagsAssigner,
EventDispatcherInterface $eventDispatcher,
ValidatorInterface $validator
) {
$this->validateAuthentication();
$url = $request->request->get('url');
@ -788,6 +796,16 @@ class EntryRestController extends WallabagRestController
$contentProxy->setDefaultEntryTitle($entry);
}
$errors = $validator->validate($entry);
if (\count($errors) > 0) {
$errorsString = '';
foreach ($errors as $error) {
$errorsString .= $error->getMessage() . "\n";
}
throw new BadRequestHttpException($errorsString);
}
$this->entityManager->persist($entry);
$this->entityManager->flush();

View file

@ -204,6 +204,8 @@ class EntryController extends AbstractController
// entry saved, dispatch event about it!
$this->eventDispatcher->dispatch(new EntrySavedEvent($entry), EntrySavedEvent::NAME);
return $this->redirect($this->generateUrl('homepage'));
} elseif ($form->isSubmitted() && !$form->isValid()) {
return $this->redirect($this->generateUrl('homepage'));
}