diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php index 43d35934b..3dceba5be 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php @@ -133,7 +133,7 @@ class HouseholdCompositionController extends AbstractController */ public function index(Household $household, Request $request): Response { - if (!$this->security->isGranted(HouseholdVoter::SEE, $household)) { + if (!$this->security->isGranted(HouseholdVoter::EDIT, $household)) { throw new AccessDeniedException('not allowed to edit a household'); } diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index ba7c78f65..a8453cf5c 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -24,6 +24,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\SerializerInterface; @@ -123,7 +124,9 @@ class HouseholdController extends AbstractController */ public function addressEdit(Request $request, Household $household) { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::EDIT, $household)) { + throw new AccessDeniedException('You are not allowed to edit a household address'); + } $address_id = $request->query->get('address_id'); $address = $this->getDoctrine()->getManager() @@ -149,7 +152,9 @@ class HouseholdController extends AbstractController */ public function addresses(Request $request, Household $household) { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::SEE, $household)) { + throw new AccessDeniedException('You have no access to this household\'s details'); + } //TODO put these lines into a validator constraint on household->getAddress $addresses = $household->getAddresses(); @@ -179,7 +184,9 @@ class HouseholdController extends AbstractController */ public function addressMove(Request $request, Household $household) { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::EDIT, $household)) { + throw new AccessDeniedException('You are not allowed to edit this household'); + } return $this->render( '@ChillPerson/Household/address_move.html.twig', @@ -255,7 +262,10 @@ class HouseholdController extends AbstractController */ public function editHouseholdMetadata(Request $request, Household $household) { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::EDIT, $household)) { + throw new AccessDeniedException('not allowed to edit a household'); + } + $form = $this->createMetadataForm($household); $form->handleRequest($request); @@ -311,7 +321,9 @@ class HouseholdController extends AbstractController */ public function summary(Request $request, Household $household) { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::SEE, $household)) { + throw new AccessDeniedException('not allowed to edit a household'); + } $positions = $this->positionRepository ->findByActiveOrdered(); diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index d286cb270..26d040692 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -19,12 +19,15 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Form\HouseholdMemberType; use Chill\PersonBundle\Household\MembersEditor; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; +use Chill\PersonBundle\Security\Authorization\HouseholdVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; +use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\Exception; use Symfony\Contracts\Translation\TranslatorInterface; @@ -38,14 +41,18 @@ class HouseholdMemberController extends ApiController private TranslatorInterface $translator; + private Security $security; + public function __construct( UrlGeneratorInterface $generator, TranslatorInterface $translator, - AccompanyingPeriodRepository $periodRepository + AccompanyingPeriodRepository $periodRepository, + Security $security ) { $this->generator = $generator; $this->translator = $translator; $this->periodRepository = $periodRepository; + $this->security = $security; } /** @@ -56,7 +63,9 @@ class HouseholdMemberController extends ApiController */ public function editMembership(Request $request, HouseholdMember $member): Response { - // TODO ACL + if (!$this->security->isGranted(HouseholdVoter::EDIT, $member->getHousehold())) { + throw new AccessDeniedException('You are not allowed to edit this household'); + } $form = $this->createForm(HouseholdMemberType::class, $member, [ 'validation_groups' => ['household_memberships'], diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig index fdd1e0717..07c83e18b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig @@ -30,12 +30,13 @@ {{ customButtons['before'] }} {% endif %} -
{{ 'household_composition.Since'|trans({'startDate': currentComposition.startDate}) }}
- + {% if is_granted('CHILL_PERSON_HOUSEHOLD_EDIT', household) %} + + {% endif %} {% else %}{{ 'household_composition.Currently no composition'|trans }}
- + {% if is_granted('CHILL_PERSON_HOUSEHOLD_EDIT', household) %} + + {% endif %}