Renamed TypeAttribut to CrudAttribut

This commit is contained in:
Kevin Frantz 2019-01-16 21:22:18 +01:00
parent 665f0044cc
commit 93bf246915
28 changed files with 113 additions and 107 deletions

View File

@ -68,7 +68,7 @@ class SourceApiController extends AbstractAPIController
// // $requestedRight = new Right();
// // $requestedRight->setSource($requestedSource);
// // $requestedRight->setLayer(LayerType::SOURCE);
// // $requestedRight->setType(CRUDType::READ);
// // $requestedRight->setCrud(CRUDType::READ);
// // $sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler());
// // return $sourceResponseManager->getResponse();

View File

@ -32,7 +32,7 @@ final class DefaultController extends AbstractController
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setCrud(CRUDType::READ);
$sourceResponseManager = new SourceRESTResponseManager($this->getUser(), $entityManager, $requestedRight, $this->getViewHandler());
return $sourceResponseManager->getResponse();

View File

@ -65,7 +65,7 @@ class SourceFixtures extends Fixture
$sourceRightManager = new SourceRightManager($this->impressumSource);
$sourceRightManager->addRight($right);
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::READ);
$right->setCrud(CRUDType::READ);
$right->setReciever($this->guestUserSource);
return $right;

View File

@ -49,9 +49,9 @@ final class LawPermissionCheckerService implements LawPermissionCheckerServiceIn
*
* @return Collection|RightInterface[]
*/
private function getRightsByType(Collection $rights, string $type): Collection
private function getRightsByCrud(Collection $rights, string $type): Collection
{
return $this->getFilteredRights($rights, $type, 'Type');
return $this->getFilteredRights($rights, $type, 'Crud');
}
/**
@ -139,7 +139,7 @@ final class LawPermissionCheckerService implements LawPermissionCheckerServiceIn
$right = $rights[0];
$rightChecker = new RightChecker($right);
return $rightChecker->isGranted($client->getLayer(), $client->getType(), $client->getReciever());
return $rightChecker->isGranted($client->getLayer(), $client->getCrud(), $client->getReciever());
}
public function __construct(LawInterface $law)
@ -150,7 +150,7 @@ final class LawPermissionCheckerService implements LawPermissionCheckerServiceIn
public function hasPermission(RightInterface $clientRight): bool
{
$rights = clone $this->law->getRights();
$rights = $this->getRightsByType($rights, $clientRight->getType());
$rights = $this->getRightsByCrud($rights, $clientRight->getCrud());
$rights = $this->getRightsByLayer($rights, $clientRight->getLayer());
$rights = $this->getRightsByReciever($rights, $clientRight->getReciever());
$rights = $this->sortByPriority($rights);

View File

@ -3,7 +3,7 @@
namespace App\Domain\RequestManagement;
use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\TypeAttribut;
use App\Entity\Attribut\CrudAttribut;
use App\Entity\Attribut\LayerAttribut;
use App\Entity\Attribut\RecieverAttribut;
use App\Exception\PreconditionFailedException;
@ -17,7 +17,7 @@ use App\Repository\Source\SourceRepositoryInterface;
*/
class RequestedRight implements RequestedRightInterface
{
use TypeAttribut, LayerAttribut, RecieverAttribut;
use CrudAttribut, LayerAttribut, RecieverAttribut;
/**
* @var SourceRepositoryInterface

View File

@ -2,7 +2,7 @@
namespace App\Domain\RequestManagement;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\CrudAttributInterface;
use App\Entity\Attribut\RecieverAttributInterface;
use App\Entity\Attribut\LayerAttributInterface;
use App\Entity\Source\SourceInterface;
@ -10,7 +10,7 @@ use App\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
*/
interface RequestedRightInterface extends TypeAttributInterface, RecieverAttributInterface, LayerAttributInterface
interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface
{
/**
* @param RequestedSourceInterface $requestedSource

View File

@ -63,11 +63,11 @@ final class RequestedUserRightFacade implements RequestedUserRightFacadeInterfac
/**
* {@inheritdoc}
*
* @see \App\Entity\Attribut\TypeAttributInterface::getType()
* @see \App\Entity\Attribut\CrudAttributInterface::getCrud()
*/
public function getType(): string
public function getCrud(): string
{
return $this->requestedRight->getType();
return $this->requestedRight->getCrud();
}
/**
@ -93,11 +93,11 @@ final class RequestedUserRightFacade implements RequestedUserRightFacadeInterfac
/**
* {@inheritdoc}
*
* @see \App\Entity\Attribut\TypeAttributInterface::setType()
* @see \App\Entity\Attribut\CrudAttributInterface::setCrud()
*/
public function setType(string $type): void
public function setCrud(string $type): void
{
$this->requestedRight->setType($type);
$this->requestedRight->setCrud($type);
}
/**

View File

@ -45,7 +45,7 @@ final class RightChecker implements RightCheckerInterface
private function isTypeEqual(string $type): bool
{
return $this->right->getType() === $type;
return $this->right->getCrud() === $type;
}
private function checkPermission(): bool

View File

@ -51,7 +51,7 @@ final class SecureCRUDFactoryService extends AbstractSecureCRUDService implement
*/
public function create(RightInterface $requestedRight): SecureCRUDServiceInterface
{
$namespace = $this->getCRUDNamespace($requestedRight->getLayer(), $requestedRight->getType());
$namespace = $this->getCRUDNamespace($requestedRight->getLayer(), $requestedRight->getCrud());
return new $namespace($this->requestStack, $this->security, $this->entityManager);
}

View File

@ -119,9 +119,9 @@ final class TemplatePathInformation implements TemplatePathInformationInterface
/**
* {@inheritdoc}
*
* @see \App\Domain\TemplateManagement\TemplatePathInformationInterface::getType()
* @see \App\Domain\TemplateManagement\TemplatePathInformationInterface::getCrud()
*/
public function getType(): string
public function getCrud(): string
{
return $this->type;
}

View File

@ -26,5 +26,5 @@ interface TemplatePathInformationInterface extends ReloadTypeInterface
*
* @return string Type of the template
*/
public function getType(): string;
public function getCrud(): string;
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Entity\Attribut;
/**
* @todo Implement a trait for crud which substitute this one.
*
* @author kevinfrantz
*/
trait CrudAttribut
{
/**
* @var string
*/
protected $crud;
/**
* @param string $crud
*/
public function setCrud(string $crud): void
{
$this->crud = $crud;
}
/**
* @return string
*/
public function getCrud(): string
{
return $this->crud;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
interface CrudAttributInterface
{
public function setCrud(string $crud): void;
public function getCrud(): string;
}

View File

@ -1,26 +0,0 @@
<?php
namespace App\Entity\Attribut;
/**
* @todo Implement a trait for crud which substitute this one.
*
* @author kevinfrantz
*/
trait TypeAttribut
{
/**
* @var string
*/
protected $type;
public function setType(string $type): void
{
$this->type = $type;
}
public function getType(): string
{
return $this->type;
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
interface TypeAttributInterface
{
public function setType(string $type): void;
public function getType(): string;
}

View File

@ -2,7 +2,7 @@
namespace App\Entity\Meta;
use App\Entity\Attribut\TypeAttribut;
use App\Entity\Attribut\CrudAttribut;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttribut;
@ -27,7 +27,7 @@ use App\DBAL\Types\Meta\Right\CRUDType;
*/
class Right extends AbstractMeta implements RightInterface
{
use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut,PriorityAttribut;
use CrudAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut,PriorityAttribut;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
@ -77,12 +77,12 @@ class Right extends AbstractMeta implements RightInterface
protected $grant;
/**
* @ORM\Column(name="type", type="CRUDType", nullable=false)
* @ORM\Column(name="crud", type="CRUDType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\Meta\Right\CRUDType")
*
* @var string
*/
protected $type;
protected $crud;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Source\Operation\AbstractOperation",cascade={"persist"})
@ -102,14 +102,14 @@ class Right extends AbstractMeta implements RightInterface
/**
* {@inheritdoc}
*
* @see \App\Entity\Attribut\TypeAttributInterface::setType()
* @see \App\Entity\Attribut\CrudAttributInterface::setCrud()
*/
public function setType(string $type): void
public function setCrud(string $crud): void
{
if (!array_key_exists($type, CRUDType::getChoices())) {
if (!array_key_exists($crud, CRUDType::getChoices())) {
throw new NoValidChoiceException();
}
$this->type = $type;
$this->crud = $crud;
}
/**

View File

@ -2,7 +2,7 @@
namespace App\Entity\Meta;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\CrudAttributInterface;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\RecieverAttributInterface;
use App\Entity\Attribut\GrantAttributInterface;
@ -14,6 +14,6 @@ use App\Entity\Attribut\PriorityAttributInterface;
/**
* @author kevinfrantz
*/
interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface
interface RightInterface extends CrudAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface
{
}

View File

@ -87,7 +87,7 @@ class LawPermissionCheckerTest extends TestCase
{
$this->clientRight = new Right();
$this->clientRight->setLayer(LayerType::SOURCE);
$this->clientRight->setType(CRUDType::READ);
$this->clientRight->setCrud(CRUDType::READ);
$this->clientRight->setReciever($this->clientSource);
$this->clientRight->setSource($this->source);
}
@ -107,7 +107,7 @@ class LawPermissionCheckerTest extends TestCase
{
$this->law->getRights()->add($this->getClonedClientRight());
$this->assertTrue($this->checkClientPermission());
$this->clientRight->setType(CRUDType::UPDATE);
$this->clientRight->setCrud(CRUDType::UPDATE);
$this->assertFalse($this->checkClientPermission());
}
@ -142,10 +142,10 @@ class LawPermissionCheckerTest extends TestCase
public function testGetRightsByType(): void
{
$right = $this->getClonedClientRight();
$right->setType(CRUDType::UPDATE);
$right->setCrud(CRUDType::UPDATE);
$this->law->getRights()->add($right);
$this->assertFalse($this->checkClientPermission());
$right->setType(CRUDType::READ);
$right->setCrud(CRUDType::READ);
$this->assertTrue($this->checkClientPermission());
}

View File

@ -44,11 +44,11 @@ class RequestedUserRightFacadeTest extends TestCase
$userSourceDirector->method('getUser')->willReturn($user);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedRight->method('getLayer')->willReturn($layer);
$requestedRight->method('getType')->willReturn($type);
$requestedRight->method('getCrud')->willReturn($type);
$requestedRight->method('getSource')->willReturn($source);
$requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
$this->assertEquals($layer, $requestedUserRightFacade->getLayer());
$this->assertEquals($type, $requestedUserRightFacade->getType());
$this->assertEquals($type, $requestedUserRightFacade->getCrud());
$this->assertEquals($source, $requestedUserRightFacade->getSource());
$this->assertEquals($reciever, $requestedUserRightFacade->getReciever());
}
@ -66,10 +66,10 @@ class RequestedUserRightFacadeTest extends TestCase
$userSourceDirector = new UserSourceDirector($sourceRepository, $user);
$requestedUserRightFacade = new RequestedUserRightFacade($userSourceDirector, $requestedRight);
$this->assertNull($requestedUserRightFacade->setLayer($layer));
$this->assertNull($requestedUserRightFacade->setType($type));
$this->assertNull($requestedUserRightFacade->setCrud($type));
$this->assertNull($requestedUserRightFacade->setRequestedSource($requestedSource));
$this->assertEquals($layer, $requestedRight->getLayer());
$this->assertEquals($type, $requestedRight->getType());
$this->assertEquals($type, $requestedRight->getCrud());
$this->expectException(NotSetException::class);
$this->assertNotInstanceOf(RequestedSourceInterface::class, $requestedRight->getSource());
}

View File

@ -67,7 +67,7 @@ class SourceRESTReponseManagerTest extends KernelTestCase
$requestedRight->setSource($requestedSource);
$requestedRight->setReciever(new PureSource());
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setCrud(CRUDType::READ);
$this->expectException(AllreadyDefinedException::class);
$sourceResponseManager = new SourceRESTResponseManager(null, $this->entityManager, $requestedRight, $this->viewHandler);
$sourceResponseManager->getResponse();

View File

@ -46,7 +46,7 @@ class RightCheckerTest extends TestCase
$this->source = new PureSource();
$this->right = new Right();
$this->right->setReciever($this->source);
$this->right->setType($this->type);
$this->right->setCrud($this->type);
$this->right->setLayer($this->layer);
$this->rightManager = new RightChecker($this->right);
}

View File

@ -54,7 +54,7 @@ class SecureSourceReadServiceTest extends KernelTestCase
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setCrud(CRUDType::READ);
$requestedRight->setReciever(new UserSource());
$this->expectException(AccessDeniedHttpException::class);
$this->secureSourceReadService->read($requestedRight);
@ -67,7 +67,7 @@ class SecureSourceReadServiceTest extends KernelTestCase
$requestedRight = new Right();
$requestedRight->setSource($requestedSource);
$requestedRight->setLayer(LayerType::SOURCE);
$requestedRight->setType(CRUDType::READ);
$requestedRight->setCrud(CRUDType::READ);
$requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
$textSourceResponse = $this->secureSourceReadService->read($requestedRight);
$this->assertInstanceOf(TextSourceInterface::class, $textSourceResponse);

View File

@ -48,7 +48,7 @@ class SecureCRUDFactoryServiceTest extends KernelTestCase
if (!in_array($layer, self::EXCLUDED_TYPES[$crud])) {
$requestedRight = new Right();
$requestedRight->setLayer($layer);
$requestedRight->setType($crud);
$requestedRight->setCrud($crud);
$secureCreator = $this->secureCRUDFactoryService->create($requestedRight);
$this->assertInstanceOf(SecureCRUDServiceInterface::class, $secureCreator);
}

View File

@ -52,13 +52,13 @@ class SecureSourceCheckerTest extends TestCase
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setCrud(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$requestedRight->setType(CRUDType::READ);
$requestedRight->setCrud(CRUDType::READ);
$this->assertFalse($this->securerSourceChecker->hasPermission($requestedRight));
}
@ -66,7 +66,7 @@ class SecureSourceCheckerTest extends TestCase
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setCrud(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
@ -76,7 +76,7 @@ class SecureSourceCheckerTest extends TestCase
$this->source->setSource($attributSource);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$childRight->setType(CRUDType::READ);
$childRight->setCrud(CRUDType::READ);
$this->expectException(SourceAccessDenied::class);
$this->securerSourceChecker->hasPermission($requestedRight);
}
@ -85,7 +85,7 @@ class SecureSourceCheckerTest extends TestCase
{
$right = new Right();
$right->setLayer(LayerType::SOURCE);
$right->setType(CRUDType::UPDATE);
$right->setCrud(CRUDType::UPDATE);
$right->setReciever($this->recieverSource);
$right->setSource($this->source);
$this->source->getLaw()->getRights()->add($right);
@ -98,7 +98,7 @@ class SecureSourceCheckerTest extends TestCase
$attribut1Source->setSource($attribut2Source);
$requestedRight = clone $right;
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
$childRight->setType(CRUDType::READ);
$childRight->setCrud(CRUDType::READ);
$this->expectException(SourceAccessDenied::class);
$this->securerSourceChecker->hasPermission($requestedRight);
}

View File

@ -56,7 +56,7 @@ class TemplatePathInformationTest extends TestCase
$this->templateMeta->reloadType($type);
$this->assertEquals($this->getExpectedPath($type, 'atom'), $this->templateMeta->getAtomTemplatePath());
$this->assertEquals($this->getExpectedPath($type, 'molecule'), $this->templateMeta->getMoleculeTemplatePath());
$this->assertEquals($type, $this->templateMeta->getType());
$this->assertEquals($type, $this->templateMeta->getCrud());
}
}
}

View File

@ -3,36 +3,36 @@
namespace Tests\Unit\Entity\Attribut;
use PHPUnit\Framework\TestCase;
use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\TypeAttribut;
use App\Entity\Attribut\CrudAttributInterface;
use App\Entity\Attribut\CrudAttribut;
/**
* @author kevinfrantz
*/
class TypeAttributTest extends TestCase
class CrudAttributTest extends TestCase
{
/**
* @var TypeAttributInterface
* @var CrudAttributInterface
*/
protected $typeAttribut;
public function setUp(): void
{
$this->typeAttribut = new class() implements TypeAttributInterface {
use TypeAttribut;
$this->typeAttribut = new class() implements CrudAttributInterface {
use CrudAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->typeAttribut->getType();
$this->typeAttribut->getCrud();
}
public function testAccessors(): void
{
$type = 'Hello World!';
$this->assertNull($this->typeAttribut->setType($type));
$this->assertEquals($type, $this->typeAttribut->getType());
$this->assertNull($this->typeAttribut->setCrud($type));
$this->assertEquals($type, $this->typeAttribut->getCrud());
}
}

View File

@ -61,7 +61,7 @@ class RightTest extends TestCase
public function testConstructorType(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getType());
$this->assertNull($this->right->getCrud());
}
public function testLaw(): void
@ -74,11 +74,11 @@ class RightTest extends TestCase
public function testRight(): void
{
foreach (CRUDType::getChoices() as $key => $value) {
$this->assertNull($this->right->setType($key));
$this->assertEquals($key, $this->right->getType());
$this->assertNull($this->right->setCrud($key));
$this->assertEquals($key, $this->right->getCrud());
}
$this->expectException(NoValidChoiceException::class);
$this->right->setType('NoneValidType');
$this->right->setCrud('NoneValidType');
}
public function testLayer(): void
@ -104,13 +104,13 @@ class RightTest extends TestCase
$this->right->setSource($source);
$this->right->setReciever($reciever);
$this->right->setGrant($grant);
$this->right->setType($type);
$this->right->setCrud($type);
$this->right->setLayer($layer);
$rightClone = clone $this->right;
$this->assertEquals($source, $rightClone->getSource());
$this->assertEquals($reciever, $rightClone->getReciever());
$this->assertEquals($grant, $rightClone->getGrant());
$this->assertEquals($type, $rightClone->getType());
$this->assertEquals($type, $rightClone->getCrud());
$this->assertEquals($layer, $rightClone->getLayer());
}
}

View File

@ -56,7 +56,7 @@ class RightRepositoryTest extends KernelTestCase
$this->right = new Right();
$this->right->setPriority(self::PRIORITY);
$this->right->setLayer(LayerType::SOURCE);
$this->right->setType(CRUDType::READ);
$this->right->setCrud(CRUDType::READ);
$this->law = new Law();
$this->entityManager->persist($this->law);
$this->right->setLaw($this->law);