Fix budget voter for use with household

This commit is contained in:
Julie Lenaerts 2022-02-25 16:40:27 +01:00
parent 2e59c1415b
commit f60f927549
3 changed files with 6 additions and 6 deletions

View File

@ -98,7 +98,7 @@ class ElementController extends AbstractController
*/
public function indexHouseholdAction(Household $household)
{
// $this->denyAccessUnlessGranted(BudgetElementVoter::SEE, $household);
$this->denyAccessUnlessGranted(BudgetElementVoter::SEE, $household);
$charges = $this->em
->getRepository(Charge::class)

View File

@ -282,7 +282,7 @@
{% endif %}
{# {% if is_granted('CHILL_BUDGET_ELEMENT_CREATE', household) %} #}
{% if is_granted('CHILL_BUDGET_ELEMENT_CREATE', household) %}
<ul class="record_actions sticky-form-buttons">
<li>
<a class="btn btn-create" href="{{ path('chill_budget_resource_household_new', { 'id': household.id} ) }}">{{ 'Create new resource'|trans }}</a>
@ -291,7 +291,7 @@
<a class="btn btn-create" href="{{ path('chill_budget_charge_household_new', { 'id': household.id} ) }}">{{ 'Create new charge'|trans }}</a>
</li>
</ul>
{# {% endif %} #}
{% endif %}
{% endif %}
@ -352,7 +352,7 @@
{% endif %}
{% if (resources|length + charges|length) == 0 or futureCharges|length > 0 or futureResources|length > 0 or pastCharges|length > 0 or pastResources|length > 0 %}
{# {% if is_granted('CHILL_BUDGET_ELEMENT_CREATE', household) %} #}
{% if is_granted('CHILL_BUDGET_ELEMENT_CREATE', household) %}
<ul class="record_actions sticky-form-buttons">
<li>
<a class="btn btn-create" href="{{ path('chill_budget_resource_household_new', { 'id': household.id} ) }}">{{ 'Create new resource'|trans }}</a>
@ -361,7 +361,7 @@
<a class="btn btn-create" href="{{ path('chill_budget_charge_household_new', { 'id': household.id} ) }}">{{ 'Create new charge'|trans }}</a>
</li>
</ul>
{# {% endif %} #}
{% endif %}
{% endif %}
{% endblock %}

View File

@ -69,7 +69,7 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar
protected function supports($attribute, $subject)
{
return (in_array($attribute, self::ROLES, true) && $subject instanceof AbstractElement)
|| ($subject instanceof Person && in_array($attribute, [self::SEE, self::CREATE], true));
|| (($subject instanceof Person || $subject instanceof Household) && in_array($attribute, [self::SEE, self::CREATE], true));
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)