This commit is contained in:
Julie Lenaerts 2022-02-17 09:43:49 +01:00
parent c8922a6a82
commit 9861e3fe1c
5 changed files with 15 additions and 21 deletions

View File

@ -31,7 +31,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateInterval;
use DateTimeImmutable;
use JsonSchema\Exception\ValidationException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
@ -323,11 +322,12 @@ final class AccompanyingCourseApiController extends ApiController
/**
* @Route("/api/1.0/person/accompanying-course/{id}/confidential.json", name="chill_api_person_accompanying_period_confidential")
* @ParamConverter("accompanyingCourse", options={"id": "id"})
*
* @param mixed $id
*/
public function toggleConfidentialApi(AccompanyingPeriod $accompanyingCourse, $id, Request $request)
{
if ($request->getMethod() == 'POST') {
if ($request->getMethod() === 'POST') {
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::TOGGLE_CONFIDENTIAL, $accompanyingCourse);
$accompanyingCourse->setConfidential(!$accompanyingCourse->isConfidential());
@ -336,9 +336,8 @@ final class AccompanyingCourseApiController extends ApiController
if ($errors->count() > 0) {
return $this->json($errors, 422);
} else {
$this->getDoctrine()->getManager()->flush();
}
$this->getDoctrine()->getManager()->flush();
}
return $this->json($accompanyingCourse->isConfidential(), Response::HTTP_OK, [], ['groups' => ['read']]);

View File

@ -38,7 +38,6 @@ use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSchema\Exception\ValidationException;
use LogicException;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;

View File

@ -11,12 +11,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @internal

View File

@ -18,12 +18,12 @@ use Symfony\Component\Validator\Constraint;
*/
class AccompanyingPeriodValidity extends Constraint
{
public $messageSocialIssueCannotBeDeleted = 'The social %name% issue cannot be deleted because it is associated with an activity or an action';
public $messageReferrerIsCurrentUser = 'Only the referrer can change the confidentiality of a parcours';
public $messageReferrerIsNull = 'A confidential parcours must have a referrer';
public $messageSocialIssueCannotBeDeleted = 'The social %name% issue cannot be deleted because it is associated with an activity or an action';
public function getTargets()
{
return self::CLASS_CONSTRAINT;

View File

@ -97,12 +97,12 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
$user = $period->getUser();
$currentUser = $this->token->getToken()->getUser();
if ($user && ($user != $currentUser) && $period->isConfidential() == true) {
if ($user && ($user !== $currentUser) && $period->isConfidential() === true) {
$this->context->buildViolation($constraint->messageReferrerIsCurrentUser)
->addViolation();
}
if ($user == null && $period->isConfidential() == true) {
if (null === $user && $period->isConfidential() === true) {
$this->context->buildViolation($constraint->messageReferrerIsNull)
->addViolation();
}