Allowed guest users to access impressum

This commit is contained in:
Kevin Frantz 2019-01-01 22:36:55 +01:00
parent 3efa57f29a
commit 130682ef6c
3 changed files with 57 additions and 31 deletions

View File

@ -9,36 +9,65 @@ use App\Entity\Source\Primitive\Text\TextSourceInterface;
use App\DBAL\Types\SystemSlugType; use App\DBAL\Types\SystemSlugType;
use App\Entity\Source\Complex\UserSource; use App\Entity\Source\Complex\UserSource;
use App\Entity\Source\Complex\UserSourceInterface; use App\Entity\Source\Complex\UserSourceInterface;
use App\Entity\Meta\Right;
use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType;
use App\Entity\Meta\RightInterface;
/**
* @author kevinfrantz
*
* @todo Create a collection class for all users
*/
class SourceFixtures extends Fixture class SourceFixtures extends Fixture
{ {
/**
* @var TextSourceInterface The example source for the impressum
*/
private $impressumSource;
/**
* @var UserSourceInterface The UserSource which should be used for the anonymous user
*/
private $guestUserSource;
public function load(ObjectManager $manager) public function load(ObjectManager $manager)
{ {
$manager->persist($this->getImpressum()); $this->setGuestUserSource();
$manager->persist($this->getGuestUser()); $this->setImpressumSource();
$manager->persist($this->impressumSource);
$manager->persist($this->getImpressumRight());
$manager->persist($this->guestUserSource);
$manager->flush(); $manager->flush();
} }
/** private function setImpressumSource(): void
* @return TextSourceInterface The example source for the impressum
*/
private function getImpressum(): TextSourceInterface
{ {
$source = new TextSource(); $this->impressumSource = new TextSource();
$source->setText('Example Impressum'); $this->impressumSource->setText('Example Impressum');
$source->setSlug(SystemSlugType::IMPRINT); $this->impressumSource->setSlug(SystemSlugType::IMPRINT);
return $source;
} }
/** /**
* @return UserSourceInterface The UserSource which should be used for the anonymous user * @todo Implement that right gets automaticly created by persisting of law
*
* @return RightInterface
*/ */
private function getGuestUser(): UserSourceInterface private function getImpressumRight(): RightInterface
{ {
$source = new UserSource(); $right = new Right();
$source->setSlug(SystemSlugType::GUEST_USER); $right->setSource($this->impressumSource);
$right->setLaw($this->impressumSource->getLaw());
$right->setLayer(LayerType::SOURCE);
$right->setType(RightType::READ);
$right->setReciever($this->guestUserSource);
return $source; return $right;
}
private function setGuestUserSource(): void
{
$this->guestUserSource = new UserSource();
$this->guestUserSource->setSlug(SystemSlugType::GUEST_USER);
} }
} }

View File

@ -55,16 +55,16 @@ class SecureSourceLoaderTest extends KernelTestCase
$secureSourceLoader->getSource(); $secureSourceLoader->getSource();
} }
// public function testGranted(): void public function testGranted(): void
// { {
// $requestedSource = new TextSource(); $requestedSource = new TextSource();
// $requestedSource->setSlug(SystemSlugType::IMPRINT); $requestedSource->setSlug(SystemSlugType::IMPRINT);
// $requestedRight = new Right(); $requestedRight = new Right();
// $requestedRight->setSource($requestedSource); $requestedRight->setSource($requestedSource);
// $requestedRight->setLayer(LayerType::SOURCE); $requestedRight->setLayer(LayerType::SOURCE);
// $requestedRight->setType(RightType::READ); $requestedRight->setType(RightType::READ);
// $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER])); $requestedRight->setReciever($this->sourceRepository->findOneBy(['slug' => SystemSlugType::GUEST_USER]));
// $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight); $secureSourceLoader = new SecureSourceLoader($this->sourceRepository, $requestedRight);
// $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource()); $this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource());
// } }
} }

View File

@ -67,9 +67,6 @@ class RightRepositoryTest extends KernelTestCase
$this->entityManager->persist($this->right); $this->entityManager->persist($this->right);
$this->entityManager->flush(); $this->entityManager->flush();
$rightId = $this->right->getId(); $rightId = $this->right->getId();
/*
* @var RightInterface
*/
$this->loadedRight = $this->rightRepository->find($rightId); $this->loadedRight = $this->rightRepository->find($rightId);
$this->assertEquals($rightId, $this->loadedRight->getId()); $this->assertEquals($rightId, $this->loadedRight->getId());
$this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority()); $this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority());