Validation of confidential toggle added to accompanyingPeriod validator

This commit is contained in:
2022-02-15 14:22:41 +01:00
parent 385664e2bc
commit 4e83e7905a
5 changed files with 35 additions and 15 deletions

View File

@@ -20,6 +20,10 @@ 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 function getTargets()
{
return self::CLASS_CONSTRAINT;

View File

@@ -15,6 +15,7 @@ use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -28,10 +29,13 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
private SocialIssueRender $socialIssueRender;
public function __construct(ActivityRepository $activityRepository, SocialIssueRender $socialIssueRender)
private TokenStorageInterface $token;
public function __construct(ActivityRepository $activityRepository, SocialIssueRender $socialIssueRender, TokenStorageInterface $token)
{
$this->activityRepository = $activityRepository;
$this->socialIssueRender = $socialIssueRender;
$this->token = $token;
}
public function validate($period, Constraint $constraint)
@@ -44,6 +48,7 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
throw new UnexpectedValueException($period, AccompanyingPeriod::class);
}
/** Check if a social issue can be deleted (is not linked to an action or activity within the parcours) */
$socialIssues = [];
$activities = $this->activityRepository->findBy(['accompanyingPeriod' => $period]);
@@ -87,5 +92,19 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
->addViolation();
}
}
/** Check if confidentiality and intensity can be toggled */
$user = $period->getUser();
$currentUser = $this->token->getToken()->getUser();
if ($user && ($user != $currentUser) && $period->isConfidential() == true) {
$this->context->buildViolation($constraint->messageReferrerIsCurrentUser)
->addViolation();
}
if ($user == null && $period->isConfidential() == true) {
$this->context->buildViolation($constraint->messageReferrerIsNull)
->addViolation();
}
}
}