diff --git a/application/src/Domain/RightManagement/RightChecker.php b/application/src/Domain/RightManagement/RightChecker.php new file mode 100644 index 0000000..651fbd4 --- /dev/null +++ b/application/src/Domain/RightManagement/RightChecker.php @@ -0,0 +1,63 @@ +right->getSource()); + $this->allSourcesToWhichRightApplies = clone ($rightSourceMemberInformation->getAllMembers()); + $this->allSourcesToWhichRightApplies->add($this->right->getSource()); + } + + private function hasSource(SourceInterface $source): bool + { + return $this->allSourcesToWhichRightApplies->contains($source); + } + + private function isLayerEqual(string $layer):bool{ + return ($this->right->getLayer() === $layer); + } + + private function isTypeEqual(string $type):bool{ + return ($this->right->getType() === $type); + } + + private function checkPermission():bool{ + return $this->right->getGrant(); + } + + public function __construct(RightInterface $right) + { + $this->right = $right; + $this->setAllSourcesToWhichRightApplies(); + } + + public function isGranted(string $layer, string $type, SourceInterface $source): bool + { + return ($this->isLayerEqual($layer) && $this->isTypeEqual($type) && $this->hasSource($source) && $this->checkPermission()); + } +} diff --git a/application/src/Domain/RightManagement/RightCheckerInterface.php b/application/src/Domain/RightManagement/RightCheckerInterface.php new file mode 100644 index 0000000..bc00fdb --- /dev/null +++ b/application/src/Domain/RightManagement/RightCheckerInterface.php @@ -0,0 +1,10 @@ +right = new Right(); + $this->source = $this->getSourceMock(); + $this->right->setSource($this->source); + $this->rightManager = new RightChecker($this->right); + } + + public function testFirstDimension():void{ + $layer = LayerType::RELATION; + $type = RightType::READ; + $this->right->setType($type); + $this->right->setLayer($layer); + $granted = $this->rightManager->isGranted($layer, $type, $this->source); + $this->assertTrue($granted); + $notGranted = $this->rightManager->isGranted(LayerType::SOURCE, $type, $this->source); + $this->assertFalse($notGranted); + $notGranted2 = $this->rightManager->isGranted($layer, RightType::WRITE, $this->source); + $this->assertFalse($notGranted2); + $this->right->setGrant(false); + $notGranted3 = $this->rightManager->isGranted($layer, $type, $this->source); + $this->assertFalse($notGranted3); + } + +// public function testSecondDimension():void{ + +// } +} \ No newline at end of file