Removed logic from persistence layer

This commit is contained in:
Kevin Frantz
2018-11-06 20:30:36 +01:00
parent 1fa93e577a
commit 43761e472f
16 changed files with 7 additions and 241 deletions

View File

@@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\RightsAttribute;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
@@ -25,27 +24,7 @@ final class Law extends AbstractMeta implements LawInterface
protected $rights;
public function __construct()
{
$this->initAllRights();
}
private function initAllRights(): void
{
$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;
}
}

View File

@@ -3,11 +3,10 @@
namespace App\Entity\Meta;
use App\Entity\Attribut\RightsAttributInterface;
use App\Entity\Method\GrantedInterface;
/**
* @author kevinfrantz
*/
interface LawInterface extends RightsAttributInterface, GrantedInterface, MetaInterface
interface LawInterface extends RightsAttributInterface, MetaInterface
{
}

View File

@@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping as ORM;
use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\RightAttribut;
use App\Entity\Attribut\CollectionAttribut;
use App\Entity\Method\CollectionDimensionHelperMethod;
/**
* @author kevinfrantz
@@ -16,7 +15,7 @@ use App\Entity\Method\CollectionDimensionHelperMethod;
*/
class Reciever extends AbstractMeta implements RecieverInterface
{
use RightAttribut, CollectionAttribut,CollectionDimensionHelperMethod;
use RightAttribut, CollectionAttribut;
/**
* The right which the reciever group belongs to.

View File

@@ -4,13 +4,12 @@ namespace App\Entity\Meta;
use App\Entity\Attribut\RightAttributInterface;
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.
*
* @author kevinfrantz
*/
interface RecieverInterface extends MetaInterface, RightAttributInterface, CollectionAttributInterface, DimensionHelperInterface
interface RecieverInterface extends MetaInterface, RightAttributInterface, CollectionAttributInterface
{
}

View File

@@ -14,7 +14,6 @@ use App\Entity\Attribut\ConditionAttribut;
use App\Entity\Attribut\RecieverAttribut;
use App\Entity\Attribut\LayerAttribut;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
@@ -79,27 +78,4 @@ final class Right extends AbstractMeta implements RightInterface
$this->reciever = new Reciever();
$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);
}
}

View File

@@ -8,12 +8,11 @@ use App\Entity\Attribut\RecieverAttributInterface;
use App\Entity\Attribut\GrantAttributInterface;
use App\Entity\Attribut\ConditionAttributInterface;
use App\Entity\Attribut\LayerAttributInterface;
use App\Entity\Method\GrantedInterface;
use App\Entity\Attribut\RelationAttributInterface;
/**
* @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
{
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -3,8 +3,6 @@
namespace App\Entity\Source\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\MembersAttribut;
use App\Entity\Method\CollectionDimensionHelperMethod;
use App\Entity\Attribut\CollectionAttribut;
/**
@@ -17,5 +15,4 @@ use App\Entity\Attribut\CollectionAttribut;
class TreeCollectionSource extends AbstractCollectionSource implements TreeCollectionSourceInterface
{
use CollectionAttribut;
use CollectionDimensionHelperMethod;
}

View File

@@ -2,11 +2,9 @@
namespace App\Entity\Source\Collection;
use App\Helper\DimensionHelperInterface;
/**
* @author kevinfrantz
*/
interface TreeCollectionSourceInterface extends CollectionSourceInterface, DimensionHelperInterface
interface TreeCollectionSourceInterface extends CollectionSourceInterface
{
}

View File

@@ -11,6 +11,8 @@ use App\Exception\NotDefinedException;
* @author kevinfrantz
* @ORM\Table(name="source_operation_and")
* @ORM\Entity()
*
* @todo move to the logic level!
*/
final class AndOperation extends AbstractOperation
{

View File

@@ -6,7 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\IdAttribut;
use App\Creator\Modificator\Entity\LawModificator;
use App\Entity\Source\Data\UserSourceInterface;
use App\Entity\Source\Data\UserSource;
use App\Entity\Attribut\VersionAttribut;
@@ -55,6 +54,5 @@ class User extends BaseUser implements UserInterface
$this->isActive = true;
$this->source = new UserSource();
$this->source->setUser($this);
//LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode());
}
}