Optimized right and reciever logic

This commit is contained in:
Kevin Frantz 2018-11-04 15:51:16 +01:00
parent 8f983659bc
commit f634555ed5
7 changed files with 19 additions and 20 deletions

View File

@ -4,10 +4,9 @@ namespace App\Entity\Meta;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\RelationAttribut;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\MembersAttribut; use App\Entity\Attribut\MembersAttribut;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\RightAttribut;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -16,17 +15,17 @@ use App\Entity\Source\SourceInterface;
*/ */
class Reciever extends AbstractMeta implements RecieverInterface class Reciever extends AbstractMeta implements RecieverInterface
{ {
use RelationAttribut, MembersAttribut; use RightAttribut, MembersAttribut;
/** /**
* The node for which the right exists. * The right which the reciever group belongs to.
* *
* @ORM\ManyToOne(targetEntity="Relation") * @ORM\OneToOne(targetEntity="Right",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id") * @ORM\JoinColumn(name="right_id", referencedColumnName="id")
* *
* @var RelationAttributInterface * @var RightInterface
*/ */
protected $relation; protected $right;
/** /**
* @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource") * @ORM\ManyToMany(targetEntity="App\Entity\Source\AbstractSource")

View File

@ -2,14 +2,14 @@
namespace App\Entity\Meta; namespace App\Entity\Meta;
use App\Entity\Attribut\RelationAttributInterface;
use App\Entity\Attribut\MembersAttributInterface; use App\Entity\Attribut\MembersAttributInterface;
use App\Entity\Attribut\RightAttributInterface;
/** /**
* 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 RelationAttributInterface, MetaInterface, MembersAttributInterface interface RecieverInterface extends MetaInterface, MembersAttributInterface, RightAttributInterface
{ {
} }

View File

@ -56,14 +56,6 @@ final class Right extends AbstractMeta implements RightInterface
*/ */
protected $grant; protected $grant;
/**
* @ORM\ManyToOne(targetEntity="Relation")
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
*
* @var RelationInterface
*/
protected $relation;
/** /**
* @ORM\Column(name="type", type="RightType", nullable=false) * @ORM\Column(name="type", type="RightType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType") * @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
@ -84,6 +76,7 @@ final class Right extends AbstractMeta implements RightInterface
{ {
parent::__construct(); parent::__construct();
$this->grant = true; $this->grant = true;
$this->reciever = new Reciever();
} }
public function isGranted(SourceInterface $source, string $layer, string $right): bool public function isGranted(SourceInterface $source, string $layer, string $right): bool

View File

@ -11,8 +11,10 @@ interface GrantedInterface
{ {
/** /**
* Returns true if the source is granted access to the layer with the requested right. * Returns true if the source is granted access to the layer with the requested right.
*
* @param SourceInterface $source * @param SourceInterface $source
* @param string $right * @param string $right
*
* @return bool * @return bool
*/ */
public function isGranted(SourceInterface $source, string $layer, string $right): bool; public function isGranted(SourceInterface $source, string $layer, string $right): bool;

View File

@ -22,5 +22,7 @@ class RecieverTest extends TestCase
public function testConstructor(): void public function testConstructor(): void
{ {
$this->assertInstanceOf(Collection::class, $this->reciever->getMembers()); $this->assertInstanceOf(Collection::class, $this->reciever->getMembers());
$this->expectException(\TypeError::class);
$this->reciever->getRight();
} }
} }

View File

@ -7,6 +7,7 @@ use App\DBAL\Types\RightType;
use App\Entity\Meta\RightInterface; use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
use App\Entity\Meta\Law; use App\Entity\Meta\Law;
use App\Entity\Meta\RecieverInterface;
/** /**
* @todo Implement reciever test * @todo Implement reciever test
@ -27,8 +28,10 @@ class RightTest extends TestCase
public function testConstructor(): void public function testConstructor(): void
{ {
$this->assertInstanceOf(RecieverInterface::class, $this->right->getReciever());
$this->expectException(\TypeError::class); $this->expectException(\TypeError::class);
$this->assertNull($this->right->getLaw()); $this->assertNull($this->right->getLaw());
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getType()); $this->assertNull($this->right->getType());
} }