From 3efa57f29a11d96f4f17c1d924c2b982ad0a220a Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 1 Jan 2019 21:33:13 +0100 Subject: [PATCH] Added default grant value for law --- .../LawManagement/LawPermissionCheckerService.php | 2 +- application/src/Entity/Meta/Law.php | 11 ++++++++++- application/src/Entity/Meta/LawInterface.php | 3 ++- .../Domain/LawManagement/LawPermissionCheckerTest.php | 7 +++++++ application/tests/Unit/Entity/Meta/LawTest.php | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/application/src/Domain/LawManagement/LawPermissionCheckerService.php b/application/src/Domain/LawManagement/LawPermissionCheckerService.php index 1e52bfa..9c30e65 100644 --- a/application/src/Domain/LawManagement/LawPermissionCheckerService.php +++ b/application/src/Domain/LawManagement/LawPermissionCheckerService.php @@ -134,7 +134,7 @@ final class LawPermissionCheckerService implements LawPermissionCheckerServiceIn private function isGranted(Collection $rights, RightInterface $client): bool { if (0 === $rights->count()) { - return false; + return $this->law->getGrant(); } $right = $rights[0]; $rightChecker = new RightChecker($right); diff --git a/application/src/Entity/Meta/Law.php b/application/src/Entity/Meta/Law.php index d2121f9..c3c80f1 100644 --- a/application/src/Entity/Meta/Law.php +++ b/application/src/Entity/Meta/Law.php @@ -7,6 +7,7 @@ use App\Entity\Attribut\RightsAttribute; use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attribut\RelationAttribut; use App\Entity\Source\SourceInterface; +use App\Entity\Attribut\GrantAttribut; /** * @author kevinfrantz @@ -15,7 +16,14 @@ use App\Entity\Source\SourceInterface; */ class Law extends AbstractMeta implements LawInterface { - use RightsAttribute, RelationAttribut; + use RightsAttribute, RelationAttribut, GrantAttribut; + + /** + * @ORM\Column(type="boolean",name="`grant`") + * + * @var bool the standart grant value + */ + protected $grant; /** * @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"}) @@ -36,5 +44,6 @@ class Law extends AbstractMeta implements LawInterface { parent::__construct(); $this->rights = new ArrayCollection(); + $this->grant = false; } } diff --git a/application/src/Entity/Meta/LawInterface.php b/application/src/Entity/Meta/LawInterface.php index 80a9321..03f67c9 100644 --- a/application/src/Entity/Meta/LawInterface.php +++ b/application/src/Entity/Meta/LawInterface.php @@ -3,10 +3,11 @@ namespace App\Entity\Meta; use App\Entity\Attribut\RightsAttributInterface; +use App\Entity\Attribut\GrantAttributInterface; /** * @author kevinfrantz */ -interface LawInterface extends RightsAttributInterface, MetaInterface +interface LawInterface extends RightsAttributInterface, MetaInterface, GrantAttributInterface { } diff --git a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php index 0977cbc..6b144a7 100644 --- a/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php +++ b/application/tests/Unit/Domain/LawManagement/LawPermissionCheckerTest.php @@ -202,4 +202,11 @@ class LawPermissionCheckerTest extends TestCase ])); $this->assertTrue($this->checkClientPermission()); } + + public function testGrant(): void + { + $this->assertFalse($this->checkClientPermission()); + $this->law->setGrant(true); + $this->assertTrue($this->checkClientPermission()); + } } diff --git a/application/tests/Unit/Entity/Meta/LawTest.php b/application/tests/Unit/Entity/Meta/LawTest.php index 0187fdc..3a6d4fe 100644 --- a/application/tests/Unit/Entity/Meta/LawTest.php +++ b/application/tests/Unit/Entity/Meta/LawTest.php @@ -23,6 +23,7 @@ class LawTest extends TestCase public function testConstruct(): void { + $this->assertFalse($this->law->getGrant()); $this->assertInstanceOf(Collection::class, $this->law->getRights()); }