mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
voter updates
This commit is contained in:
parent
51d1e5422b
commit
2684345981
@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Controller;
|
|||||||
|
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
|
use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter;
|
||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
@ -83,7 +84,7 @@ class AccompanyingCourseCommentController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($commentEdited)) {
|
if (isset($commentEdited)) {
|
||||||
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $commentEdited->getAccompanyingPeriod());
|
$this->denyAccessUnlessGranted(AccompanyingPeriodCommentVoter::EDIT, $commentEdited);
|
||||||
} else {
|
} else {
|
||||||
throw new LogicException('at this step, commentEdited should be set');
|
throw new LogicException('at this step, commentEdited should be set');
|
||||||
}
|
}
|
||||||
@ -134,7 +135,7 @@ class AccompanyingCourseCommentController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function deleteAction(AccompanyingPeriod\Comment $comment, Request $request): Response
|
public function deleteAction(AccompanyingPeriod\Comment $comment, Request $request): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $comment->getAccompanyingPeriod());
|
$this->denyAccessUnlessGranted(AccompanyingPeriodCommentVoter::DELETE, $comment);
|
||||||
|
|
||||||
$form = $this->createForm(FormType::class, []);
|
$form = $this->createForm(FormType::class, []);
|
||||||
$form->add('submit', SubmitType::class, ['label' => 'Confirm']);
|
$form->add('submit', SubmitType::class, ['label' => 'Confirm']);
|
||||||
|
@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Security\Authorization;
|
|||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
use UnexpectedValueException;
|
use UnexpectedValueException;
|
||||||
|
|
||||||
class AccompanyingPeriodCommentVoter extends Voter
|
class AccompanyingPeriodCommentVoter extends Voter
|
||||||
@ -22,6 +23,13 @@ class AccompanyingPeriodCommentVoter extends Voter
|
|||||||
|
|
||||||
public const EDIT = 'CHILL_PERSON_ACCOMPANYING_PERIOD_COMMENT_EDIT';
|
public const EDIT = 'CHILL_PERSON_ACCOMPANYING_PERIOD_COMMENT_EDIT';
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
|
public function __construct(Security $security)
|
||||||
|
{
|
||||||
|
$this->security = $security;
|
||||||
|
}
|
||||||
|
|
||||||
protected function supports($attribute, $subject)
|
protected function supports($attribute, $subject)
|
||||||
{
|
{
|
||||||
return $subject instanceof Comment;
|
return $subject instanceof Comment;
|
||||||
@ -32,9 +40,9 @@ class AccompanyingPeriodCommentVoter extends Voter
|
|||||||
/** @var Comment $subject */
|
/** @var Comment $subject */
|
||||||
switch ($attribute) {
|
switch ($attribute) {
|
||||||
case self::EDIT:
|
case self::EDIT:
|
||||||
|
return $this->security->isGranted(AccompanyingPeriodVoter::EDIT, $subject->getAccompanyingPeriod());
|
||||||
case self::DELETE:
|
case self::DELETE:
|
||||||
return $subject->getCreator() === $token->getUser();
|
return $this->security->isGranted(AccompanyingPeriodVoter::EDIT, $subject->getAccompanyingPeriod());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new UnexpectedValueException("This attribute {$attribute} is not supported");
|
throw new UnexpectedValueException("This attribute {$attribute} is not supported");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user