From f919b0e02c3eec9508b119a5f8e4a3436d716fd4 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 21 Sep 2018 19:43:48 +0200 Subject: [PATCH] Updated registration process --- .../Modificator/Entity/LawModificator.php | 31 ++++++++++++++++--- application/src/Entity/AbstractEntity.php | 4 +-- application/src/Entity/LawInterface.php | 3 +- application/src/Entity/Node.php | 17 ++-------- application/src/Entity/Right.php | 10 +++--- application/src/Entity/User.php | 1 + .../unit/Controller/DefaultControllerTest.php | 1 - application/tests/unit/Entity/UserTest.php | 14 ++++----- 8 files changed, 45 insertions(+), 36 deletions(-) diff --git a/application/src/Creator/Modificator/Entity/LawModificator.php b/application/src/Creator/Modificator/Entity/LawModificator.php index b3bccf8..597a8b8 100644 --- a/application/src/Creator/Modificator/Entity/LawModificator.php +++ b/application/src/Creator/Modificator/Entity/LawModificator.php @@ -7,6 +7,10 @@ use App\DBAL\Types\RightType; use App\Entity\NodeInterface; use App\Entity\Right; use App\Entity\LawInterface; +use App\DBAL\Types\RecieverType; +use App\Entity\RightInterface; +use App\Entity\RecieverGroupInterface; +use App\Entity\RecieverGroup; /** * @author kevinfrantz @@ -17,13 +21,30 @@ abstract class LawModificator { foreach (LayerType::getChoices() as $layerKey => $layerValue) { foreach (RightType::getChoices() as $rightKey => $rightValue) { - $right = new Right(); - $right->setType($rightKey); - $right->setLaw($this); - $right->setLayer($layerKey); - $right->setNode($node); + $right = self::createRight($law, $node, $rightKey, $layerKey); + $right->setRecieverGroup(self::createRecieverGroup($node, RecieverType::NODE)); $law->getRights()->add($right); } } } + + public static function createRight(LawInterface $law, NodeInterface $node, string $type, string $layer): RightInterface + { + $right = new Right(); + $right->setType($type); + $right->setLaw($law); + $right->setLayer($layer); + $right->setNode($node); + + return $right; + } + + public static function createRecieverGroup(NodeInterface $node, string $reciever): RecieverGroupInterface + { + $recieverGroup = new RecieverGroup(); + $recieverGroup->setNode($node); + $recieverGroup->setReciever($reciever); + + return $recieverGroup; + } } diff --git a/application/src/Entity/AbstractEntity.php b/application/src/Entity/AbstractEntity.php index 15090ff..d234338 100644 --- a/application/src/Entity/AbstractEntity.php +++ b/application/src/Entity/AbstractEntity.php @@ -21,8 +21,8 @@ class AbstractEntity */ protected $id; - protected function __construct() + public function __construct() { - $this->id = 0; + //$this->id = 0; } } diff --git a/application/src/Entity/LawInterface.php b/application/src/Entity/LawInterface.php index de3d74e..8ade9fe 100644 --- a/application/src/Entity/LawInterface.php +++ b/application/src/Entity/LawInterface.php @@ -4,10 +4,11 @@ namespace App\Entity; use App\Entity\Attribut\RightsAttributInterface; use App\Entity\Method\NodeGrantedInterface; +use App\Entity\Attribut\NodeAttributInterface; /** * @author kevinfrantz */ -interface LawInterface extends RightsAttributInterface, NodeGrantedInterface +interface LawInterface extends RightsAttributInterface, NodeGrantedInterface, NodeAttributInterface { } diff --git a/application/src/Entity/Node.php b/application/src/Entity/Node.php index d755a38..2a63e78 100644 --- a/application/src/Entity/Node.php +++ b/application/src/Entity/Node.php @@ -8,6 +8,7 @@ use App\Entity\Attribut\SourceAttribut; use App\Entity\Attribut\ParentsAttribut; use App\Entity\Attribut\ChildsAttribut; use App\Entity\Attribut\LawAttribut; +use Doctrine\Common\Collections\ArrayCollection; /** * @author kevinfrantz @@ -41,20 +42,8 @@ class Node extends AbstractEntity implements NodeInterface public function __construct() { $this->law = new Law(); + $this->parents = new ArrayCollection(); + $this->childs = new ArrayCollection(); $this->law->setNode($this); - $this->initPermissions(); - } - - private function initPermissions(): void - { - /* - * @var RightInterface - */ - foreach ($this->law->getRights()->toArray() as $right) { - $permission = new Permission(); - $permission->setNode($this); - $permission->setRight($right); - $right->addPermission($permission); - } } } diff --git a/application/src/Entity/Right.php b/application/src/Entity/Right.php index ab81f3b..6691e57 100644 --- a/application/src/Entity/Right.php +++ b/application/src/Entity/Right.php @@ -8,9 +8,7 @@ use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; use App\Entity\Attribut\LawAttribut; use App\DBAL\Types\LayerType; use App\DBAL\Types\RightType; -use App\Entity\Attribut\PermissionsAttribut; use App\Entity\Attribut\NodeAttribut; -use App\Entity\Attribut\RecieverAttribut; use App\Entity\Attribut\GrantAttribut; use App\Logic\Operation\OperationInterface; use App\Entity\Attribut\ConditionAttribut; @@ -24,7 +22,7 @@ use App\Entity\Attribut\LayerAttribut; */ class Right extends AbstractEntity implements RightInterface { - use TypeAttribut,LawAttribut,PermissionsAttribut, NodeAttribut, RecieverAttribut,GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut; + use TypeAttribut,LawAttribut, NodeAttribut, GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut; /** * @ORM\ManyToOne(targetEntity="Law", inversedBy="rights") @@ -75,7 +73,8 @@ class Right extends AbstractEntity implements RightInterface /** * @ORM\OneToOne(targetEntity="AbstractOperation",cascade={"persist"}) - * @ORM\Column(nullable=true) + * @ORM\JoinColumn(name="operation_id", referencedColumnName="id",nullable=true) + * * @var OperationInterface */ protected $condition; @@ -84,7 +83,8 @@ class Right extends AbstractEntity implements RightInterface { parent::__construct(); $this->grant = true; - $this->recieverGroup = new RecieverGroup(); + //$this->node = new Node(); + //$this->recieverGroup = new RecieverGroup(); } public function isGranted(NodeInterface $node, string $layer, string $right): bool diff --git a/application/src/Entity/User.php b/application/src/Entity/User.php index d2338f7..0fd8b77 100644 --- a/application/src/Entity/User.php +++ b/application/src/Entity/User.php @@ -43,5 +43,6 @@ class User extends BaseUser implements SourceAttributInterface $this->isActive = true; $this->source = new UserSource(); LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode()); + //var_dump($this->source->getNode()->getLaw()->getRights()->get(0)); } } diff --git a/application/tests/unit/Controller/DefaultControllerTest.php b/application/tests/unit/Controller/DefaultControllerTest.php index f863382..e67400b 100644 --- a/application/tests/unit/Controller/DefaultControllerTest.php +++ b/application/tests/unit/Controller/DefaultControllerTest.php @@ -3,7 +3,6 @@ namespace App\Tests\Unit\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use App\Controller\DefaultControllerInterface; use App\Controller\DefaultController; /** diff --git a/application/tests/unit/Entity/UserTest.php b/application/tests/unit/Entity/UserTest.php index 81944cb..8db4a8e 100644 --- a/application/tests/unit/Entity/UserTest.php +++ b/application/tests/unit/Entity/UserTest.php @@ -1,4 +1,5 @@ user->setPassword(self::PASSWORD); $this->assertEquals(self::PASSWORD, $this->user->getPassword()); } - + public function testSource(): void { - $this->assertInstanceOf(UserSource::class,$this->user->getSource()); + $this->assertInstanceOf(UserSource::class, $this->user->getSource()); } - + public function testNode(): void { - $this->assertInstanceOf(Node::class,$this->user->getSource()->getNode()); + $this->assertInstanceOf(Node::class, $this->user->getSource()->getNode()); } public function testLaw(): void { - $this->assertInstanceOf(Law::class,$this->user->getSource()->getNode()->getLaw()); + $this->assertInstanceOf(Law::class, $this->user->getSource()->getNode()->getLaw()); } }