Implemented not functional draft for SecureSourceReadService

This commit is contained in:
Kevin Frantz 2019-01-13 16:54:17 +01:00
parent ff95e23859
commit 1a3c9874a4

View File

@ -13,6 +13,7 @@ use App\Domain\SecureCRUDManagement\CRUD\AbstractSecureCRUDService;
use App\Entity\EntityInterface; use App\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use App\Repository\Source\SourceRepository;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -22,7 +23,7 @@ final class SecureSourceReadService extends AbstractSecureCRUDService //implemen
/** /**
* @todo It would be better to specify the type * @todo It would be better to specify the type
* *
* @var ObjectRepository * @var SourceRepository
*/ */
private $sourceRepository; private $sourceRepository;
@ -39,18 +40,6 @@ final class SecureSourceReadService extends AbstractSecureCRUDService //implemen
return $requestedRight; return $requestedRight;
} }
/**
* @return SourceInterface
*/
private function loadSource(): SourceInterface
{
try {
return $this->sourceRepository->find($this->requestedRight->getSource()->getId());
} catch (\Error $error) {
return $this->sourceRepository->findOneBySlug($this->requestedRight->getSource()->getSlug());
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
@ -63,13 +52,14 @@ final class SecureSourceReadService extends AbstractSecureCRUDService //implemen
} }
/** /**
* @todo This will not work! Change interface to requested right!
* @param RightInterface $requestedRight * @param RightInterface $requestedRight
* *
* @return EntityInterface * @return EntityInterface
*/ */
public function read(RightInterface $requestedRight): EntityInterface public function read(RightInterface $requestedRight): EntityInterface
{ {
$source = $this->loadSource(); $source = $requestedRight->getSource();
$requestedRight = $this->getClonedRightWithModifiedSource($source, $requestedRight); $requestedRight = $this->getClonedRightWithModifiedSource($source, $requestedRight);
$secureSourceChecker = new SecureSourceChecker($source); $secureSourceChecker = new SecureSourceChecker($source);
if ($secureSourceChecker->hasPermission($requestedRight)) { if ($secureSourceChecker->hasPermission($requestedRight)) {