This commit is contained in:
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,23 +322,23 @@ 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());
$accompanyingCourse->setConfidential(!$accompanyingCourse->isConfidential());
$errors = $this->validator->validate($accompanyingCourse);
$errors = $this->validator->validate($accompanyingCourse);
if ($errors->count() > 0) {
return $this->json($errors, 422);
} else {
$this->getDoctrine()->getManager()->flush();
}
if ($errors->count() > 0) {
return $this->json($errors, 422);
}
$this->getDoctrine()->getManager()->flush();
}
return $this->json($accompanyingCourse->isConfidential(), Response::HTTP_OK, [], ['groups' => ['read']]);
}