mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
Fixed: [budget] Fix voter on household's budget
This commit is contained in:
@@ -20,7 +20,7 @@ use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
use function in_array;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
@@ -68,12 +68,29 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return (in_array($attribute, self::ROLES, true) && $subject instanceof AbstractElement)
|
||||
|| (($subject instanceof Person || $subject instanceof Household) && in_array($attribute, [self::SEE, self::CREATE], true));
|
||||
return $this->voter->supports($attribute, $subject);
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
return $this->voter->voteOnAttribute($attribute, $subject, $token);
|
||||
if (
|
||||
$subject instanceof Person
|
||||
|| ($subject instanceof AbstractElement && null !== $person = $subject->getPerson())) {
|
||||
return $this->voter->voteOnAttribute($attribute, $person ?? $subject, $token);
|
||||
}
|
||||
|
||||
if (
|
||||
$subject instanceof Household
|
||||
|| ($subject instanceof AbstractElement && null !== $household = $subject->getHousehold())) {
|
||||
foreach (($household ?? $subject)->getCurrentPersons() as $person) {
|
||||
if ($this->voter->voteOnAttribute($attribute, $person, $token)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('This subject is not supported, or is an element not associated with person or household');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user