unpin comment is possible + delete and edit by all users that can edit period

This commit is contained in:
2022-04-25 10:28:51 +02:00
parent 83dd8f810c
commit 09503768f5
3 changed files with 35 additions and 4 deletions

View File

@@ -84,7 +84,7 @@ class AccompanyingCourseCommentController extends AbstractController
}
if (isset($commentEdited)) {
$this->denyAccessUnlessGranted(AccompanyingPeriodCommentVoter::EDIT, $commentEdited);
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $commentEdited->getAccompanyingPeriod());
} else {
throw new LogicException('at this step, commentEdited should be set');
}
@@ -135,7 +135,7 @@ class AccompanyingCourseCommentController extends AbstractController
*/
public function deleteAction(AccompanyingPeriod\Comment $comment, Request $request): Response
{
$this->denyAccessUnlessGranted(AccompanyingPeriodCommentVoter::DELETE, $comment);
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $comment->getAccompanyingPeriod());
$form = $this->createForm(FormType::class, []);
$form->add('submit', SubmitType::class, ['label' => 'Confirm']);
@@ -186,6 +186,24 @@ class AccompanyingCourseCommentController extends AbstractController
]);
}
/**
* @Route("/{_locale}/parcours/comment/{id}/unpin", name="chill_person_accompanying_period_comment_unpin")
*/
public function unpinComment(AccompanyingPeriod\Comment $comment): Response
{
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $comment->getAccompanyingPeriod());
$comment->getAccompanyingPeriod()->setPinnedComment(null);
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans('accompanying_course.comment is unpinned'));
return $this->redirectToRoute('chill_person_accompanying_period_comment_list', [
'accompanying_period_id' => $comment->getAccompanyingPeriod()->getId(),
]);
}
private function createCommentForm(AccompanyingPeriod\Comment $comment, string $step): FormInterface
{
return $this->formFactory->createNamed($step, AccompanyingCourseCommentType::class, $comment);