From a95ff0497e55529edb5006d4224ac72f41d00cd5 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sat, 27 Oct 2018 14:56:26 +0200 Subject: [PATCH] Refactored relation and node draft --- .../src/Entity/Attribut/NodeAttribut.php | 26 -------------- .../Entity/Attribut/NodeAttributInterface.php | 15 -------- .../src/Entity/Attribut/RelationAttribut.php | 26 ++++++++++++++ .../Attribut/RelationAttributInterface.php | 15 ++++++++ application/src/Entity/Law.php | 16 ++++----- application/src/Entity/LawInterface.php | 6 ++-- .../Entity/Method/NodeGrantedInterface.php | 13 ------- .../Method/RelationGrantedInterface.php | 13 +++++++ application/src/Entity/RecieverGroup.php | 13 +++---- .../src/Entity/RecieverGroupInterface.php | 4 +-- .../src/Entity/{Node.php => Relation.php} | 29 ++++++++------- ...odeInterface.php => RelationInterface.php} | 2 +- application/src/Entity/Right.php | 24 ++++++------- application/src/Entity/RightInterface.php | 6 ++-- .../src/Entity/Source/AbstractSource.php | 30 ++++++++++------ .../Source/Attribut/GroupSourcesAttribut.php | 36 +++++++++++++++++++ .../GroupSourcesAttributInterface.php | 24 +++++++++++++ .../Source/Attribut/MembersAttribut.php | 30 ++++++++++++++++ ...rface.php => MembersAttributInterface.php} | 9 +++-- .../Source/Attribut/SourcesAttribut.php | 30 ---------------- .../{SourcesSource.php => GroupSource.php} | 10 +++--- ...Interface.php => GroupSourceInterface.php} | 5 ++- .../src/Entity/Source/SourceInterface.php | 4 +-- .../Security/Source/UserSourceFacade.php | 34 ++++++++++++++++++ 24 files changed, 260 insertions(+), 160 deletions(-) delete mode 100644 application/src/Entity/Attribut/NodeAttribut.php delete mode 100644 application/src/Entity/Attribut/NodeAttributInterface.php create mode 100644 application/src/Entity/Attribut/RelationAttribut.php create mode 100644 application/src/Entity/Attribut/RelationAttributInterface.php delete mode 100644 application/src/Entity/Method/NodeGrantedInterface.php create mode 100644 application/src/Entity/Method/RelationGrantedInterface.php rename application/src/Entity/{Node.php => Relation.php} (60%) rename application/src/Entity/{NodeInterface.php => RelationInterface.php} (66%) create mode 100644 application/src/Entity/Source/Attribut/GroupSourcesAttribut.php create mode 100644 application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php create mode 100644 application/src/Entity/Source/Attribut/MembersAttribut.php rename application/src/Entity/Source/Attribut/{SourcesAttributInterface.php => MembersAttributInterface.php} (65%) delete mode 100644 application/src/Entity/Source/Attribut/SourcesAttribut.php rename application/src/Entity/Source/{SourcesSource.php => GroupSource.php} (56%) rename application/src/Entity/Source/{SourcesSourceInterface.php => GroupSourceInterface.php} (50%) diff --git a/application/src/Entity/Attribut/NodeAttribut.php b/application/src/Entity/Attribut/NodeAttribut.php deleted file mode 100644 index ce3b354..0000000 --- a/application/src/Entity/Attribut/NodeAttribut.php +++ /dev/null @@ -1,26 +0,0 @@ -node = $node; - } - - public function getNode(): NodeInterface - { - return $this->node; - } -} diff --git a/application/src/Entity/Attribut/NodeAttributInterface.php b/application/src/Entity/Attribut/NodeAttributInterface.php deleted file mode 100644 index 46217e6..0000000 --- a/application/src/Entity/Attribut/NodeAttributInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -relation = $relation; + } + + public function getRelation(): RelationInterface + { + return $this->relation; + } +} diff --git a/application/src/Entity/Attribut/RelationAttributInterface.php b/application/src/Entity/Attribut/RelationAttributInterface.php new file mode 100644 index 0000000..fba0773 --- /dev/null +++ b/application/src/Entity/Attribut/RelationAttributInterface.php @@ -0,0 +1,15 @@ +rights = new ArrayCollection(); } - public function isGranted(NodeInterface $node, string $layer, string $right): bool + public function isGranted(RelationInterface $relation, string $layer, string $right): bool { /** * @var RightInterface */ foreach ($this->rights->toArray() as $right) { - if ($right->isGranted($node, $layer, $right)) { + if ($right->isGranted($relation, $layer, $right)) { return true; } } diff --git a/application/src/Entity/LawInterface.php b/application/src/Entity/LawInterface.php index 8ade9fe..6de598b 100644 --- a/application/src/Entity/LawInterface.php +++ b/application/src/Entity/LawInterface.php @@ -3,12 +3,12 @@ namespace App\Entity; use App\Entity\Attribut\RightsAttributInterface; -use App\Entity\Method\NodeGrantedInterface; -use App\Entity\Attribut\NodeAttributInterface; +use App\Entity\Attribut\RelationAttributInterface; +use App\Entity\Method\RelationGrantedInterface; /** * @author kevinfrantz */ -interface LawInterface extends RightsAttributInterface, NodeGrantedInterface, NodeAttributInterface +interface LawInterface extends RightsAttributInterface, RelationGrantedInterface, RelationAttributInterface { } diff --git a/application/src/Entity/Method/NodeGrantedInterface.php b/application/src/Entity/Method/NodeGrantedInterface.php deleted file mode 100644 index b89bdc5..0000000 --- a/application/src/Entity/Method/NodeGrantedInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -recieverGroup = new RecieverGroup(); } - public function isGranted(NodeInterface $node, string $layer, string $right): bool + public function isGranted(RelationInterface $relation, string $layer, string $right): bool { - if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($node) && $this->getConditionBoolOrTrue()) { + if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($relation) && $this->getConditionBoolOrTrue()) { return $this->grant; } @@ -109,8 +105,8 @@ class Right extends AbstractEntity implements RightInterface return true; } - private function checkIfNodeIsReciever(NodeInterface $node): bool + private function checkIfNodeIsReciever(RelationInterface $relation): bool { - return $this->recieverGroup->getAllRecievers()->contains($node); + return $this->recieverGroup->getAllRecievers()->contains($relation); } } diff --git a/application/src/Entity/RightInterface.php b/application/src/Entity/RightInterface.php index db106db..43837be 100644 --- a/application/src/Entity/RightInterface.php +++ b/application/src/Entity/RightInterface.php @@ -4,16 +4,16 @@ namespace App\Entity; use App\Entity\Attribut\TypeAttributInterface; use App\Entity\Attribut\LawAttributInterface; -use App\Entity\Method\NodeGrantedInterface; use App\Entity\Attribut\RecieverGroupAttributInterface; use App\Entity\Attribut\GrantAttributInterface; -use App\Entity\Attribut\NodeAttributInterface; use App\Entity\Attribut\ConditionAttributInterface; use App\Entity\Attribut\LayerAttributInterface; +use App\Entity\Method\RelationGrantedInterface; +use App\Entity\Attribut\RelationAttributInterface; /** * @author kevinfrantz */ -interface RightInterface extends TypeAttributInterface, LawAttributInterface, NodeGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, NodeAttributInterface, ConditionAttributInterface, LayerAttributInterface +interface RightInterface extends TypeAttributInterface, LawAttributInterface, RelationGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface { } diff --git a/application/src/Entity/Source/AbstractSource.php b/application/src/Entity/Source/AbstractSource.php index 9702f62..f611190 100644 --- a/application/src/Entity/Source/AbstractSource.php +++ b/application/src/Entity/Source/AbstractSource.php @@ -2,12 +2,14 @@ namespace App\Entity\Source; -use App\Entity\Attribut\NodeAttribut; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation\Exclude; -use App\Entity\NodeInterface; use App\Entity\AbstractEntity; -use App\Entity\Node; +use Doctrine\Common\Collections\Collection; +use App\Entity\Source\Attribut\GroupSourcesAttribut; +use App\Entity\RelationInterface; +use App\Entity\Attribut\RelationAttribut; +use App\Entity\Relation; /** * @author kevinfrantz @@ -17,24 +19,30 @@ use App\Entity\Node; * @ORM\Table(name="source") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") - * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","collection" = "SourcesSource"}) + * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource","group" = "GroupSource"}) */ abstract class AbstractSource extends AbstractEntity implements SourceInterface { - use NodeAttribut; + use RelationAttribut,GroupSourcesAttribut; /** - * @var NodeInterface - * @ORM\OneToOne(targetEntity="App\Entity\Node",cascade={"persist", "remove"}) - * @ORM\JoinColumn(name="node_id", referencedColumnName="id") + * @var RelationInterface + * @ORM\OneToOne(targetEntity="App\Entity\Relation",cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="relation_id", referencedColumnName="id") * @Exclude */ - protected $node; + protected $relation; + /** + * @var Collection|GroupSource[] + * @ORM\ManyToMany(targetEntity="GroupSource") + */ + protected $groups; + public function __construct() { parent::__construct(); - $this->node = new Node(); - $this->node->setSource($this); + $this->relation = new Relation(); + $this->relation->setSource($this); } } diff --git a/application/src/Entity/Source/Attribut/GroupSourcesAttribut.php b/application/src/Entity/Source/Attribut/GroupSourcesAttribut.php new file mode 100644 index 0000000..5877aeb --- /dev/null +++ b/application/src/Entity/Source/Attribut/GroupSourcesAttribut.php @@ -0,0 +1,36 @@ +groups; + } + + /** + * + * @param Collection|GroupSourceInterface[] $groups + */ + public function setGroupSources(Collection $groups):void{ + $this->groups = $groups; + } +} + diff --git a/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php b/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php new file mode 100644 index 0000000..0c40bf2 --- /dev/null +++ b/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php @@ -0,0 +1,24 @@ +members; + } + + public function setMembers(Collection $members): void + { + $this->members = $members; + } +} + diff --git a/application/src/Entity/Source/Attribut/SourcesAttributInterface.php b/application/src/Entity/Source/Attribut/MembersAttributInterface.php similarity index 65% rename from application/src/Entity/Source/Attribut/SourcesAttributInterface.php rename to application/src/Entity/Source/Attribut/MembersAttributInterface.php index 39f5bcd..6f2827c 100644 --- a/application/src/Entity/Source/Attribut/SourcesAttributInterface.php +++ b/application/src/Entity/Source/Attribut/MembersAttributInterface.php @@ -9,17 +9,16 @@ use Doctrine\Common\Collections\Collection; * @author kevinfrantz * */ -interface SourcesAttributInterface +interface MembersAttributInterface { /** * @param Collection $members */ - public function setSources(Collection $sources): void; + public function setMembers(Collection $members): void; /** * @return Collection */ - public function getSources(): Collection; -} - + public function getMembers(): Collection; +} \ No newline at end of file diff --git a/application/src/Entity/Source/Attribut/SourcesAttribut.php b/application/src/Entity/Source/Attribut/SourcesAttribut.php deleted file mode 100644 index c26d275..0000000 --- a/application/src/Entity/Source/Attribut/SourcesAttribut.php +++ /dev/null @@ -1,30 +0,0 @@ -sources; - } - - public function setSources(Collection $sources): void - { - $this->sources = $sources; - } -} - diff --git a/application/src/Entity/Source/SourcesSource.php b/application/src/Entity/Source/GroupSource.php similarity index 56% rename from application/src/Entity/Source/SourcesSource.php rename to application/src/Entity/Source/GroupSource.php index d866035..b79fd00 100644 --- a/application/src/Entity/Source/SourcesSource.php +++ b/application/src/Entity/Source/GroupSource.php @@ -3,8 +3,8 @@ namespace App\Entity\Source; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; -use App\Entity\Attribut\SourceAttribut; -use App\Entity\Source\Attribut\SourcesAttribut; +use App\Entity\Source\Attribut\MembersAttributInterface; +use App\Entity\Source\Attribut\MembersAttribut; /** * @@ -12,15 +12,15 @@ use App\Entity\Source\Attribut\SourcesAttribut; * @ORM\Table(name="source_sources") * @ORM\Entity */ -class SourcesSource extends AbstractSource implements SourcesSourceInterface +class GroupSource extends AbstractSource implements MembersAttributInterface { - use SourcesAttribut; + use MembersAttribut; /** * * @var Collection * @ORM\ManyToMany(targetEntity="AbstractSource") */ - protected $sources; + protected $members; } diff --git a/application/src/Entity/Source/SourcesSourceInterface.php b/application/src/Entity/Source/GroupSourceInterface.php similarity index 50% rename from application/src/Entity/Source/SourcesSourceInterface.php rename to application/src/Entity/Source/GroupSourceInterface.php index 56ab2d8..b60d873 100644 --- a/application/src/Entity/Source/SourcesSourceInterface.php +++ b/application/src/Entity/Source/GroupSourceInterface.php @@ -1,15 +1,14 @@