/** * Handle delete entity object. * * @param RelationIdentifier $id * @param ApiEntityManager $manager * * @throws EntityNotFoundException if an entity with the given id does not exist * @throws ForbiddenException if a delete operation is forbidden */ public function handleDelete($id, ApiEntityManager $manager) { $em = $manager->getObjectManager(); /** @var ActivityInterface $entity */ $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId()); if (!$entity) { throw new EntityNotFoundException(); } $this->checkPermissions($entity, $em); $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId()); if (!$targetEntity) { throw new EntityNotFoundException(); } $this->checkPermissionsForTargetEntity($targetEntity, $em); $this->activityManager->removeActivityTarget($entity, $targetEntity); $em->flush(); }
/** * Handle delete entity object. * * @param RelationIdentifier $id * @param ApiEntityManager $manager * * @throws EntityNotFoundException if an entity with the given id does not exist * @throws ForbiddenException if a delete operation is forbidden */ public function handleDelete($id, ApiEntityManager $manager) { $em = $manager->getObjectManager(); /** @var ActivityInterface $entity */ $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId()); if (!$entity) { throw new EntityNotFoundException(); } if (!$this->securityFacade->isGranted('EDIT', $entity)) { throw new ForbiddenException('has no edit permissions for activity entity'); } $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId()); if (!$targetEntity) { throw new EntityNotFoundException(); } if (!$this->securityFacade->isGranted('VIEW', $targetEntity)) { throw new ForbiddenException('has no view permissions for related entity'); } $this->activityManager->removeActivityTarget($entity, $targetEntity); $em->flush(); }