Commit d77a81de authored by Emma's avatar Emma 🦉

Merge branch 'fix-phantom-parent' into 'master'

make reply to non-existent post 404 - fixes #10

Closes #10

See merge request edgyemma/Postmill!45
parents 33c028de 5ebaaaf6
Pipeline #21386814 passed with stage
in 5 minutes and 22 seconds
......@@ -26,7 +26,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* @Entity("forum", expr="repository.findOneOrRedirectToCanonical(forum_name, 'forum_name')")
* @Entity("submission", expr="repository.findOneBy({forum: forum, id: submission_id})")
* @Entity("comment", expr="repository.findOneBy({submission: submission, id: comment_id})")
* @Entity("comment", expr="repository.findOneBySubmissionAndIdOr404(submission, comment_id)")
*/
final class CommentController extends AbstractController {
public function list(CommentRepository $repository, int $page) {
......@@ -79,9 +79,9 @@ final class CommentController extends AbstractController {
* @param EntityManager $em
* @param Forum $forum
* @param Submission $submission
* @param Comment|null $comment
* @param Request $request
* @param EventDispatcherInterface $dispatcher
* @param Comment|null $comment
*
* @return Response
*/
......@@ -89,9 +89,9 @@ final class CommentController extends AbstractController {
EntityManager $em,
Forum $forum,
Submission $submission,
?Comment $comment,
Request $request,
EventDispatcherInterface $dispatcher,
Comment $comment = null
EventDispatcherInterface $dispatcher
) {
$data = new CommentData($submission);
......@@ -118,7 +118,7 @@ final class CommentController extends AbstractController {
'form' => $form->createView(),
'forum' => $forum,
'submission' => $submission,
'comment' => $comment,
'parent' => $comment,
]);
}
......@@ -221,7 +221,7 @@ final class CommentController extends AbstractController {
if (strpos($request->headers->get('Referer'), $commentUrl) === 0) {
// redirect to forum since redirect to referrer will 404
return $this->redirectToRoute('forum', [
'forum_name' => $forum->getName()
'forum_name' => $forum->getName(),
]);
}
}
......
......@@ -3,17 +3,44 @@
namespace App\Repository;
use App\Entity\Comment;
use App\Entity\Submission;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Persistence\ManagerRegistry;
use Pagerfanta\Adapter\DoctrineSelectableAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CommentRepository extends ServiceEntityRepository {
public function __construct(ManagerRegistry $registry) {
parent::__construct($registry, Comment::class);
}
/**
* @param Submission|null $submission
* @param int|null $id
*
* @return Comment
*
* @throws NotFoundHttpException if no such comment
*/
public function findOneBySubmissionAndIdOr404(
?Submission $submission,
?int $id
): ?Comment {
if (!$submission || !$id) {
return null;
}
$comment = $this->findOneBy(['submission' => $submission, 'id' => $id]);
if (!$comment) {
throw new NotFoundHttpException('No such comment');
}
return $comment;
}
/**
* @param int $page
* @param int $maxPerPage
......
......@@ -8,7 +8,7 @@
{{- block('comment') -}}
{% endmacro %}
{% macro comment_form(submission, comment) %}
{% macro comment_form(submission, parent) %}
{% if submission.locked and not is_granted('ROLE_ADMIN') %}
<div class="alert alert--notice submission-locked-notice">
<p>{{ 'flash.submission_is_locked'|trans }}</p>
......@@ -17,7 +17,7 @@
{{ render(controller('App\\Controller\\CommentController::commentForm', {
forumName: submission.forum.name,
submissionId: submission.id,
commentId: comment.id|default(null)
commentId: parent.id ?? null
})) }}
{% else %}
<div class="alert alert--notice">
......
......@@ -19,10 +19,9 @@
<h1 class="page-heading">{{ block('title') }}</h1>
{% if comment %}
{{ comment(comment, {recurse: false}) }}
{% if parent %}
{{ comment(parent, {recurse: false}) }}
{% endif %}
{% include 'comment/_form.html.twig' with { form: form } only %}
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment