mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Validation of confidential toggle added to accompanyingPeriod validator
This commit is contained in:
@@ -327,19 +327,19 @@ final class AccompanyingCourseApiController extends ApiController
|
||||
public function toggleConfidentialApi(AccompanyingPeriod $accompanyingCourse, $id, Request $request)
|
||||
{
|
||||
if ($request->getMethod() == 'POST') {
|
||||
|
||||
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::TOGGLE_CONFIDENTIAL, $accompanyingCourse);
|
||||
|
||||
if (null != $accompanyingCourse->getUser() && $this->getUser() == $accompanyingCourse->getUser()) {
|
||||
$accompanyingCourse->setConfidential(!$accompanyingCourse->isConfidential());
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
} else {
|
||||
if ($accompanyingCourse->getUser() == null) {
|
||||
throw new ValidationException("The parcours must have a referrer to be set to confidential");
|
||||
}
|
||||
throw new ValidationException("Only the referrer can set a parcours to confidential");
|
||||
}
|
||||
|
||||
}
|
||||
$errors = $this->validator->validate($accompanyingCourse);
|
||||
|
||||
if ($errors->count() > 0) {
|
||||
return $this->json($errors, 422);
|
||||
} else {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json($accompanyingCourse->isConfidential(), Response::HTTP_OK, [], ['groups' => ['read']]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user