mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Removed logic from persistence layer
This commit is contained in:
parent
1fa93e577a
commit
43761e472f
@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use App\Entity\Attribut\RightsAttribute;
|
use App\Entity\Attribut\RightsAttribute;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use App\Entity\Attribut\RelationAttribut;
|
use App\Entity\Attribut\RelationAttribut;
|
||||||
use App\Entity\Source\SourceInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -25,27 +24,7 @@ final class Law extends AbstractMeta implements LawInterface
|
|||||||
protected $rights;
|
protected $rights;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
|
||||||
$this->initAllRights();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initAllRights(): void
|
|
||||||
{
|
{
|
||||||
$this->rights = new ArrayCollection();
|
$this->rights = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isGranted(SourceInterface $source, string $layer, string $right): bool
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* @var RightInterface
|
|
||||||
*/
|
|
||||||
foreach ($this->rights->toArray() as $right) {
|
|
||||||
if ($right->isGranted($relation, $layer, $right)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
namespace App\Entity\Meta;
|
namespace App\Entity\Meta;
|
||||||
|
|
||||||
use App\Entity\Attribut\RightsAttributInterface;
|
use App\Entity\Attribut\RightsAttributInterface;
|
||||||
use App\Entity\Method\GrantedInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface LawInterface extends RightsAttributInterface, GrantedInterface, MetaInterface
|
interface LawInterface extends RightsAttributInterface, MetaInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use App\Entity\Source\SourceInterface;
|
use App\Entity\Source\SourceInterface;
|
||||||
use App\Entity\Attribut\RightAttribut;
|
use App\Entity\Attribut\RightAttribut;
|
||||||
use App\Entity\Attribut\CollectionAttribut;
|
use App\Entity\Attribut\CollectionAttribut;
|
||||||
use App\Entity\Method\CollectionDimensionHelperMethod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -16,7 +15,7 @@ use App\Entity\Method\CollectionDimensionHelperMethod;
|
|||||||
*/
|
*/
|
||||||
class Reciever extends AbstractMeta implements RecieverInterface
|
class Reciever extends AbstractMeta implements RecieverInterface
|
||||||
{
|
{
|
||||||
use RightAttribut, CollectionAttribut,CollectionDimensionHelperMethod;
|
use RightAttribut, CollectionAttribut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The right which the reciever group belongs to.
|
* The right which the reciever group belongs to.
|
||||||
|
@ -4,13 +4,12 @@ namespace App\Entity\Meta;
|
|||||||
|
|
||||||
use App\Entity\Attribut\RightAttributInterface;
|
use App\Entity\Attribut\RightAttributInterface;
|
||||||
use App\Entity\Attribut\CollectionAttributInterface;
|
use App\Entity\Attribut\CollectionAttributInterface;
|
||||||
use App\Helper\DimensionHelperInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's neccessary to have an own reciever class, because if you would use a GroupSource it would lead to an infinite loop.
|
* It's neccessary to have an own reciever class, because if you would use a GroupSource it would lead to an infinite loop.
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface RecieverInterface extends MetaInterface, RightAttributInterface, CollectionAttributInterface, DimensionHelperInterface
|
interface RecieverInterface extends MetaInterface, RightAttributInterface, CollectionAttributInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ use App\Entity\Attribut\ConditionAttribut;
|
|||||||
use App\Entity\Attribut\RecieverAttribut;
|
use App\Entity\Attribut\RecieverAttribut;
|
||||||
use App\Entity\Attribut\LayerAttribut;
|
use App\Entity\Attribut\LayerAttribut;
|
||||||
use App\Entity\Attribut\RelationAttribut;
|
use App\Entity\Attribut\RelationAttribut;
|
||||||
use App\Entity\Source\SourceInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -79,27 +78,4 @@ final class Right extends AbstractMeta implements RightInterface
|
|||||||
$this->reciever = new Reciever();
|
$this->reciever = new Reciever();
|
||||||
$this->reciever->setRight($this);
|
$this->reciever->setRight($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isGranted(SourceInterface $source, string $layer, string $right): bool
|
|
||||||
{
|
|
||||||
if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($relation) && $this->getConditionBoolOrTrue()) {
|
|
||||||
return $this->grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !($this->grant);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getConditionBoolOrTrue(): bool
|
|
||||||
{
|
|
||||||
if ($this->hasCondition()) {
|
|
||||||
return $this->condition->getResult()->getBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkIfNodeIsReciever(RelationInterface $relation): bool
|
|
||||||
{
|
|
||||||
return $this->recieverGroup->getAllRecievers()->contains($relation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,11 @@ use App\Entity\Attribut\RecieverAttributInterface;
|
|||||||
use App\Entity\Attribut\GrantAttributInterface;
|
use App\Entity\Attribut\GrantAttributInterface;
|
||||||
use App\Entity\Attribut\ConditionAttributInterface;
|
use App\Entity\Attribut\ConditionAttributInterface;
|
||||||
use App\Entity\Attribut\LayerAttributInterface;
|
use App\Entity\Attribut\LayerAttributInterface;
|
||||||
use App\Entity\Method\GrantedInterface;
|
|
||||||
use App\Entity\Attribut\RelationAttributInterface;
|
use App\Entity\Attribut\RelationAttributInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantedInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface
|
interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity\Method;
|
|
||||||
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use App\Helper\DimensionHelper;
|
|
||||||
use App\Helper\DimensionHelperInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Create test for trait!
|
|
||||||
*
|
|
||||||
* @author kevinfrantz
|
|
||||||
*/
|
|
||||||
trait CollectionDimensionHelperMethod
|
|
||||||
{
|
|
||||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
|
|
||||||
{
|
|
||||||
$dimensionHelper = new DimensionHelper(__FUNCTION__, DimensionHelperInterface::class, $this, 'collection');
|
|
||||||
|
|
||||||
return $dimensionHelper->getDimensions($dimension, $elements);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity\Method;
|
|
||||||
|
|
||||||
use App\Entity\Source\SourceInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author kevinfrantz
|
|
||||||
*/
|
|
||||||
interface GrantedInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns true if the source is granted access to the layer with the requested right.
|
|
||||||
*
|
|
||||||
* @param SourceInterface $source
|
|
||||||
* @param string $right
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isGranted(SourceInterface $source, string $layer, string $right): bool;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity\Source\Collection\Queue;
|
|
||||||
|
|
||||||
use App\Entity\Source\Collection\CollectionSourceInterface;
|
|
||||||
use App\Entity\Source\SourceInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement integration test for two user accessing queue! Check if log works!
|
|
||||||
*
|
|
||||||
* @author kevinfrantz
|
|
||||||
*/
|
|
||||||
interface QueueSourceInterface extends CollectionSourceInterface
|
|
||||||
{
|
|
||||||
public function getPointerPosition(): int;
|
|
||||||
|
|
||||||
public function getNextElement(): SourceInterface;
|
|
||||||
}
|
|
@ -3,8 +3,6 @@
|
|||||||
namespace App\Entity\Source\Collection;
|
namespace App\Entity\Source\Collection;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use App\Entity\Attribut\MembersAttribut;
|
|
||||||
use App\Entity\Method\CollectionDimensionHelperMethod;
|
|
||||||
use App\Entity\Attribut\CollectionAttribut;
|
use App\Entity\Attribut\CollectionAttribut;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,5 +15,4 @@ use App\Entity\Attribut\CollectionAttribut;
|
|||||||
class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface
|
class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface
|
||||||
{
|
{
|
||||||
use CollectionAttribut;
|
use CollectionAttribut;
|
||||||
use CollectionDimensionHelperMethod;
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Entity\Source\Collection;
|
namespace App\Entity\Source\Collection;
|
||||||
|
|
||||||
use App\Helper\DimensionHelperInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
interface TreeCollectionSourceInterface extends CollectionSourceInterface, DimensionHelperInterface
|
interface TreeCollectionSourceInterface extends CollectionSourceInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ use App\Exception\NotDefinedException;
|
|||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
* @ORM\Table(name="source_operation_and")
|
* @ORM\Table(name="source_operation_and")
|
||||||
* @ORM\Entity()
|
* @ORM\Entity()
|
||||||
|
*
|
||||||
|
* @todo move to the logic level!
|
||||||
*/
|
*/
|
||||||
final class AndOperation extends AbstractOperation
|
final class AndOperation extends AbstractOperation
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use FOS\UserBundle\Model\User as BaseUser;
|
use FOS\UserBundle\Model\User as BaseUser;
|
||||||
use App\Entity\Attribut\SourceAttribut;
|
use App\Entity\Attribut\SourceAttribut;
|
||||||
use App\Entity\Attribut\IdAttribut;
|
use App\Entity\Attribut\IdAttribut;
|
||||||
use App\Creator\Modificator\Entity\LawModificator;
|
|
||||||
use App\Entity\Source\Data\UserSourceInterface;
|
use App\Entity\Source\Data\UserSourceInterface;
|
||||||
use App\Entity\Source\Data\UserSource;
|
use App\Entity\Source\Data\UserSource;
|
||||||
use App\Entity\Attribut\VersionAttribut;
|
use App\Entity\Attribut\VersionAttribut;
|
||||||
@ -55,6 +54,5 @@ class User extends BaseUser implements UserInterface
|
|||||||
$this->isActive = true;
|
$this->isActive = true;
|
||||||
$this->source = new UserSource();
|
$this->source = new UserSource();
|
||||||
$this->source->setUser($this);
|
$this->source->setUser($this);
|
||||||
//LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use App\Entity\Meta\Reciever;
|
use App\Entity\Meta\Reciever;
|
||||||
use App\Entity\Meta\RecieverInterface;
|
use App\Entity\Meta\RecieverInterface;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use App\Entity\Source\Data\UserSource;
|
|
||||||
use App\Entity\Source\Collection\TreeCollectionSource;
|
|
||||||
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
|
||||||
use App\Entity\Source\Data\UserSourceInterface;
|
|
||||||
|
|
||||||
class RecieverTest extends TestCase
|
class RecieverTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -29,40 +25,4 @@ class RecieverTest extends TestCase
|
|||||||
$this->expectException(\TypeError::class);
|
$this->expectException(\TypeError::class);
|
||||||
$this->reciever->getRight();
|
$this->reciever->getRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDimensions(): void
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|UserSourceInterface
|
|
||||||
*/
|
|
||||||
$user1 = new UserSource();
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|UserSourceInterface
|
|
||||||
*/
|
|
||||||
$user2 = new UserSource();
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|UserSourceInterface
|
|
||||||
*/
|
|
||||||
$user3 = new UserSource();
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|TreeCollectionSourceInterface
|
|
||||||
*/
|
|
||||||
$group1 = new TreeCollectionSource();
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|TreeCollectionSourceInterface
|
|
||||||
*/
|
|
||||||
$group2 = new TreeCollectionSource();
|
|
||||||
/**
|
|
||||||
* @var \PHPUnit\Framework\MockObject\MockObject|TreeCollectionSourceInterface
|
|
||||||
*/
|
|
||||||
$group3 = new TreeCollectionSource();
|
|
||||||
$group1->getCollection()->add($user1);
|
|
||||||
$group1->getCollection()->add($group2);
|
|
||||||
$group2->getCollection()->add($user2);
|
|
||||||
$group2->getCollection()->add($user3);
|
|
||||||
$group2->getCollection()->add($group3);
|
|
||||||
$this->reciever->getCollection()->add($group1);
|
|
||||||
$this->assertEquals($group1, $this->reciever->getCollection()->get(0));
|
|
||||||
$this->assertEquals(6, $this->reciever->getDimensions()->count());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Entity\Method;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use App\Entity\Method\CollectionDimensionHelperMethod;
|
|
||||||
use App\Helper\DimensionHelperInterface;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
use App\Entity\Attribut\CollectionAttribut;
|
|
||||||
use App\Entity\Attribut\CollectionAttributInterface;
|
|
||||||
|
|
||||||
class CollectionDimensionHelperMethodTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var DimensionHelperInterface|CollectionAttributInterface
|
|
||||||
*/
|
|
||||||
protected $method;
|
|
||||||
|
|
||||||
private function getClassMock(): object
|
|
||||||
{
|
|
||||||
return new class() implements DimensionHelperInterface, CollectionAttributInterface {
|
|
||||||
use CollectionDimensionHelperMethod,CollectionAttribut;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->collection = new ArrayCollection();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
$this->method = $this->getClassMock();
|
|
||||||
$clone1 = $this->getClassMock();
|
|
||||||
$clone2 = $this->getClassMock();
|
|
||||||
$clone3 = $this->getClassMock();
|
|
||||||
$clone1->getCollection()->add($clone2);
|
|
||||||
$clone2->getCollection()->add($clone3);
|
|
||||||
$this->method->getCollection()->add($clone1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTestSetUp(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(1, $this->method->getCollection()->count());
|
|
||||||
$this->assertEquals(1, $this->method->getCollection()->get(0)->getCollection()->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThatZeroAndOneDimensionAreUnique(): void
|
|
||||||
{
|
|
||||||
$this->assertFalse($this->method->getDimensions(0)->count() == $this->method->getDimensions(1)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testZeroDimension(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(0, $this->method->getDimensions(0)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFirstDimension(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(1, $this->method->getDimensions(1)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSecondDimensionl(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(2, $this->method->getDimensions(2)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThirdtDimension(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(3, $this->method->getDimensions(3)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInfiniteDimension(): void
|
|
||||||
{
|
|
||||||
$this->assertEquals(3, $this->method->getDimensions()->count());
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,6 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
use App\Entity\Source\AbstractSource;
|
use App\Entity\Source\AbstractSource;
|
||||||
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
||||||
use App\Entity\Source\Collection\TreeCollectionSource;
|
use App\Entity\Source\Collection\TreeCollectionSource;
|
||||||
use App\Helper\DimensionHelperInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -29,7 +28,6 @@ class TreeCollectionSourceTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertInstanceOf(Collection::class, $this->tree->getCollection());
|
$this->assertInstanceOf(Collection::class, $this->tree->getCollection());
|
||||||
$this->assertInstanceOf(TreeCollectionSourceInterface::class, $this->tree);
|
$this->assertInstanceOf(TreeCollectionSourceInterface::class, $this->tree);
|
||||||
$this->assertInstanceOf(DimensionHelperInterface::class, $this->tree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessors()
|
public function testAccessors()
|
||||||
|
Loading…
Reference in New Issue
Block a user