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:
parent
3f491fe9ca
commit
67c5270fdc
5 changed files with 78 additions and 5 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue