diff --git a/application/src/DBAL/Types/LayerType.php b/application/src/DBAL/Types/LayerType.php index 71dae8c..0c458dc 100644 --- a/application/src/DBAL/Types/LayerType.php +++ b/application/src/DBAL/Types/LayerType.php @@ -12,12 +12,12 @@ final class LayerType extends AbstractEnumType public const NODE = 'node'; public const SOURCE = 'source'; - + public const LAW = 'law'; protected static $choices = [ self::NODE => 'node', - self::LAW =>'law', + self::LAW => 'law', self::SOURCE => 'source', ]; } diff --git a/application/src/DBAL/Types/RecieverType.php b/application/src/DBAL/Types/RecieverType.php index 07f3611..3a42b4f 100644 --- a/application/src/DBAL/Types/RecieverType.php +++ b/application/src/DBAL/Types/RecieverType.php @@ -15,9 +15,12 @@ final class RecieverType extends AbstractEnumType public const CHILDREN = 'children'; + public const SIBLINGS = 'siblings'; + protected static $choices = [ self::NODE => 'node', self::PARENTS => 'parents', self::CHILDREN => 'children', + self::SIBLINGS => 'siblings', ]; } diff --git a/application/src/Entity/AbstractOperation.php b/application/src/Entity/AbstractOperation.php index 880e2c6..782a640 100644 --- a/application/src/Entity/AbstractOperation.php +++ b/application/src/Entity/AbstractOperation.php @@ -1,38 +1,42 @@ result; } - + public function setOperators(ArrayCollection $operands): void { $this->operands = $operands; } } - diff --git a/application/src/Entity/AbstractSource.php b/application/src/Entity/AbstractSource.php index 80d1d71..fe4c460 100644 --- a/application/src/Entity/AbstractSource.php +++ b/application/src/Entity/AbstractSource.php @@ -11,6 +11,7 @@ use JMS\Serializer\Annotation\Exclude; * * @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/inheritance-mapping.html * @ORM\Entity + * @ORM\Table(name="source") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") * @ORM\DiscriminatorMap({"user" = "UserSource","name" = "NameSource"}) diff --git a/application/src/Entity/AndOperation.php b/application/src/Entity/AndOperation.php index e8a1c54..a5d727d 100644 --- a/application/src/Entity/AndOperation.php +++ b/application/src/Entity/AndOperation.php @@ -1,32 +1,34 @@ operands->isEmpty()){ - throw new \Exception("Operands must be defined!"); + if ($this->operands->isEmpty()) { + throw new \Exception('Operands must be defined!'); } $this->result = new Result(); /** - * @var OperandInterface $operand + * @var OperandInterface */ - foreach ($this->operands->toArray() as $operand){ - if(!$operand->getResult()->getBool()){ + foreach ($this->operands->toArray() as $operand) { + if (!$operand->getResult()->getBool()) { $this->result->setAll(false); + return; } } $this->result->setAll(true); } } - diff --git a/application/src/Entity/Attribut/ConditionAttribut.php b/application/src/Entity/Attribut/ConditionAttribut.php new file mode 100644 index 0000000..e0eac6e --- /dev/null +++ b/application/src/Entity/Attribut/ConditionAttribut.php @@ -0,0 +1,31 @@ +condition; + } + + public function setCondition(OperationInterface $condition): void + { + $this->condition = $condition; + } + + public function hasCondition(): bool + { + return $this->condition; + } +} diff --git a/application/src/Entity/Attribut/ConditionAttributInterface.php b/application/src/Entity/Attribut/ConditionAttributInterface.php new file mode 100644 index 0000000..1c60971 --- /dev/null +++ b/application/src/Entity/Attribut/ConditionAttributInterface.php @@ -0,0 +1,17 @@ +layer = $layer; + } + + public function getLayer(): string + { + return $this->layer; + } +} diff --git a/application/src/Entity/Attribut/LayerAttributInterface.php b/application/src/Entity/Attribut/LayerAttributInterface.php new file mode 100644 index 0000000..9c8db65 --- /dev/null +++ b/application/src/Entity/Attribut/LayerAttributInterface.php @@ -0,0 +1,13 @@ +recieverGroup = $recieverGroup; + } + + public function getRecieverGroup(): RecieverGroupInterface + { + return $this->recieverGroup; + } +} diff --git a/application/src/Entity/Attribut/RecieverGroupAttributInterface.php b/application/src/Entity/Attribut/RecieverGroupAttributInterface.php new file mode 100644 index 0000000..6027fcc --- /dev/null +++ b/application/src/Entity/Attribut/RecieverGroupAttributInterface.php @@ -0,0 +1,15 @@ +rights = new ArrayCollection(); - foreach (RightType::getChoices() as $key => $value) { - $right = new Right(); - $right->setType($value); - $right->setLaw($this); - $this->rights->set($key, $right); + foreach (LayerType::getChoices() as $layerKey => $layerValue) { + foreach (RightType::getChoices() as $rightKey => $rightValue) { + $right = new Right(); + $right->setType($rightKey); + $right->setLaw($this); + $right->setLayer($layerKey); + $this->rights->add($right); + } } } + + public function isGranted(NodeInterface $node, string $layer, string $right): bool + { + /** + * @var RightInterface + */ + foreach ($this->rights->toArray() as $right) { + if ($right->isGranted($node, $layer, $right)) { + return true; + } + } + + return false; + } } diff --git a/application/src/Entity/LawInterface.php b/application/src/Entity/LawInterface.php index 1fb1975..de3d74e 100644 --- a/application/src/Entity/LawInterface.php +++ b/application/src/Entity/LawInterface.php @@ -3,10 +3,11 @@ namespace App\Entity; use App\Entity\Attribut\RightsAttributInterface; +use App\Entity\Method\NodeGrantedInterface; /** * @author kevinfrantz */ -interface LawInterface extends RightsAttributInterface +interface LawInterface extends RightsAttributInterface, NodeGrantedInterface { } diff --git a/application/src/Entity/Method/NodeGrantedInterface.php b/application/src/Entity/Method/NodeGrantedInterface.php new file mode 100644 index 0000000..b89bdc5 --- /dev/null +++ b/application/src/Entity/Method/NodeGrantedInterface.php @@ -0,0 +1,13 @@ +reciever = RecieverType::NODE; - $this->grant = true; - } -} diff --git a/application/src/Entity/PermissionInterface.php b/application/src/Entity/PermissionInterface.php deleted file mode 100644 index 0818bad..0000000 --- a/application/src/Entity/PermissionInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -reciever) { + case RecieverType::PARENTS: + return $this->node->getParents(); + case RecieverType::NODE: + return new ArrayCollection([$this->node]); + case RecieverType::CHILDREN: + return $this->node->getChilds(); + } + throw new NotImplementedException('Reciever '.$this->reciever.' not implemented.'); + } +} diff --git a/application/src/Entity/RecieverGroupInterface.php b/application/src/Entity/RecieverGroupInterface.php new file mode 100644 index 0000000..532d1c3 --- /dev/null +++ b/application/src/Entity/RecieverGroupInterface.php @@ -0,0 +1,15 @@ +permissions = new ArrayCollection(); + $this->grant = true; + } + + public function isGranted(NodeInterface $node, string $layer, string $right): bool + { + if ($this->layer == $layer && $this->type == $right && $this->checkIfNodeIsReciever($node) && $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(NodeInterface $node): bool + { + return $this->recieverGroup->getAllRecievers()->contains($node); } } diff --git a/application/src/Entity/RightInterface.php b/application/src/Entity/RightInterface.php index 998fb87..db106db 100644 --- a/application/src/Entity/RightInterface.php +++ b/application/src/Entity/RightInterface.php @@ -4,12 +4,16 @@ namespace App\Entity; use App\Entity\Attribut\TypeAttributInterface; use App\Entity\Attribut\LawAttributInterface; -use App\Entity\Attribut\PermissionsAttributInterface; +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; /** * @author kevinfrantz */ -interface RightInterface extends TypeAttributInterface, LawAttributInterface, PermissionsAttributInterface +interface RightInterface extends TypeAttributInterface, LawAttributInterface, NodeGrantedInterface, GrantAttributInterface, RecieverGroupAttributInterface, NodeAttributInterface, ConditionAttributInterface, LayerAttributInterface { - public function isGranted(NodeInterface $node): bool; } diff --git a/application/src/Logic/Operation/OperandInterface.php b/application/src/Logic/Operation/OperandInterface.php index 5cb19f6..8ce4d8d 100644 --- a/application/src/Logic/Operation/OperandInterface.php +++ b/application/src/Logic/Operation/OperandInterface.php @@ -1,19 +1,18 @@ bool; } - + public function setBool(bool $bool): void { $this->bool = $bool; @@ -38,12 +38,10 @@ class Result implements ResultInterface { $this->value = $value; } - + public function setAll($value): void { - $this->bool = (bool)$value; + $this->bool = (bool) $value; $this->value = $value; } - } - diff --git a/application/src/Logic/Result/ResultInterface.php b/application/src/Logic/Result/ResultInterface.php index 73958ce..54fcf12 100644 --- a/application/src/Logic/Result/ResultInterface.php +++ b/application/src/Logic/Result/ResultInterface.php @@ -1,39 +1,41 @@