mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Expanded rights to also manage actions instead of just a cruds
This commit is contained in:
parent
465d6d6d01
commit
3e91aed050
@ -16,7 +16,7 @@ doctrine:
|
||||
collate: utf8mb4_unicode_ci
|
||||
url: '%env(resolve:DATABASE_URL)%'
|
||||
types:
|
||||
CRUDType: Infinito\DBAL\Types\Meta\Right\CRUDType
|
||||
ActionType: Infinito\DBAL\Types\ActionType
|
||||
LayerType: Infinito\DBAL\Types\Meta\Right\LayerType
|
||||
orm:
|
||||
auto_generate_proxy_classes: '%kernel.debug%'
|
||||
|
@ -4,11 +4,6 @@ namespace Infinito\Controller;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Infinito\Domain\MVCManagement\MVCRoutineServiceInterface;
|
||||
use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
|
||||
/**
|
||||
* This controller offers the standart routes for the template.
|
||||
@ -17,22 +12,6 @@ use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
*/
|
||||
final class DefaultController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @deprecated Use load via source instead of fixed route
|
||||
*
|
||||
* @todo Optimize function!
|
||||
* @Route("/imprint.{_format}", defaults={"_format"="json"}, name="imprint")
|
||||
*/
|
||||
public function imprint(MVCRoutineServiceInterface $mvcRoutineService, RequestedActionServiceInterface $requestedActionService): Response
|
||||
{
|
||||
$requestedActionService->setActionType(ActionType::READ);
|
||||
$requestedActionService->setLayer(LayerType::SOURCE);
|
||||
$requestedActionService->getRequestedEntity()->setSlug(ImpressumFixtureSource::SLUG);
|
||||
$view = $mvcRoutineService->process();
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="homepage")
|
||||
*/
|
||||
|
@ -6,6 +6,8 @@ use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @see https://de.wikipedia.org/wiki/CRUD
|
||||
*/
|
||||
class CRUDType extends AbstractEnumType
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\DBAL\Types\Meta\Right\CRUDType;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -28,7 +28,7 @@ final class ImpressumFixtureSource extends AbstractFixtureSource
|
||||
$right = new Right();
|
||||
$right->setSource($impressumSource);
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::READ);
|
||||
$right->setActionType(ActionType::READ);
|
||||
$right->setLaw($impressumSource->getLaw());
|
||||
$impressumSource->getLaw()->getRights()->add($right);
|
||||
|
||||
|
@ -49,9 +49,9 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
|
||||
*
|
||||
* @return Collection|RightInterface[]
|
||||
*/
|
||||
private function getRightsByCrud(Collection $rights, string $type): Collection
|
||||
private function getRightsByActionType(Collection $rights, string $type): Collection
|
||||
{
|
||||
return $this->getFilteredRights($rights, $type, 'Crud');
|
||||
return $this->getFilteredRights($rights, $type, 'ActionType');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +149,7 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
|
||||
$right = $rights[0];
|
||||
$rightChecker = new RightChecker($right);
|
||||
|
||||
return $rightChecker->isGranted($client->getLayer(), $client->getCrud(), $client->getReciever());
|
||||
return $rightChecker->isGranted($client->getLayer(), $client->getActionType(), $client->getReciever());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +168,7 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
|
||||
public function hasPermission(RightInterface $clientRight): bool
|
||||
{
|
||||
$rights = clone $this->law->getRights();
|
||||
$rights = $this->getRightsByCrud($rights, $clientRight->getCrud());
|
||||
$rights = $this->getRightsByActionType($rights, $clientRight->getActionType());
|
||||
$rights = $this->getRightsByLayer($rights, $clientRight->getLayer());
|
||||
$rights = $this->getRightsByReciever($rights, $clientRight);
|
||||
$rights = $this->sortByPriority($rights);
|
||||
|
@ -51,7 +51,7 @@ class RequestedAction extends RequestedUser implements RequestedActionInterface
|
||||
private function setRequestedRightCrudType(string $actionType): void
|
||||
{
|
||||
$crudType = $this->getCrudType($actionType);
|
||||
$this->requestedRight->setCrud($crudType);
|
||||
$this->requestedRight->setActionType($crudType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,21 +78,21 @@ abstract class AbstractRequestedRightFacade implements RequestedRightInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Attribut\CrudAttributInterface::setCrud()
|
||||
* @see \Infinito\Attribut\ActionTypeAttributInterface::setActionType()
|
||||
*/
|
||||
public function setCrud(string $crud): void
|
||||
public function setActionType(string $actionType): void
|
||||
{
|
||||
$this->requestedRight->setCrud($crud);
|
||||
$this->requestedRight->setActionType($actionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Attribut\CrudAttributInterface::getCrud()
|
||||
* @see \Infinito\Attribut\ActionTypeAttributInterface::getActionType()
|
||||
*/
|
||||
public function getCrud(): string
|
||||
public function getActionType(): string
|
||||
{
|
||||
return $this->requestedRight->getCrud();
|
||||
return $this->requestedRight->getActionType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace Infinito\Domain\RequestManagement\Right;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Attribut\CrudAttribut;
|
||||
use Infinito\Attribut\LayerAttribut;
|
||||
use Infinito\Attribut\RecieverAttribut;
|
||||
use Infinito\Exception\PreconditionFailedException;
|
||||
@ -12,6 +11,7 @@ use Infinito\Attribut\RequestedEntityAttribut;
|
||||
use Infinito\Entity\Meta\MetaInterface;
|
||||
use Infinito\Exception\NotCorrectInstanceException;
|
||||
use Infinito\Domain\RequestManagement\Entity\RequestedEntity;
|
||||
use Infinito\Attribut\ActionTypeAttribut;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -20,7 +20,7 @@ use Infinito\Domain\RequestManagement\Entity\RequestedEntity;
|
||||
*/
|
||||
class RequestedRight implements RequestedRightInterface
|
||||
{
|
||||
use CrudAttribut, LayerAttribut, RecieverAttribut, RequestedEntityAttribut;
|
||||
use ActionTypeAttribut, LayerAttribut, RecieverAttribut, RequestedEntityAttribut;
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace Infinito\Domain\RequestManagement\Right;
|
||||
|
||||
use Infinito\Attribut\CrudAttributInterface;
|
||||
use Infinito\Attribut\RecieverAttributInterface;
|
||||
use Infinito\Attribut\LayerAttributInterface;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Attribut\RequestedEntityAttributInterface;
|
||||
use Infinito\Attribut\ActionTypeAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface, RequestedEntityAttributInterface
|
||||
interface RequestedRightInterface extends ActionTypeAttributInterface, RecieverAttributInterface, LayerAttributInterface, RequestedEntityAttributInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -60,7 +60,7 @@ final class RightChecker implements RightCheckerInterface
|
||||
*/
|
||||
private function isTypeEqual(string $type): bool
|
||||
{
|
||||
return $this->right->getCrud() === $type;
|
||||
return $this->right->getActionType() === $type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Infinito\Entity\Meta;
|
||||
|
||||
use Infinito\Attribut\CrudAttribut;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
|
||||
use Infinito\Attribut\LawAttribut;
|
||||
@ -14,6 +13,7 @@ use Infinito\Attribut\LayerAttribut;
|
||||
use Infinito\Attribut\RelationAttribut;
|
||||
use Infinito\Attribut\PriorityAttribut;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Attribut\ActionTypeAttribut;
|
||||
|
||||
/**
|
||||
* @todo Remove relation attribut!
|
||||
@ -24,7 +24,7 @@ use Infinito\Entity\Source\SourceInterface;
|
||||
*/
|
||||
class Right extends AbstractMeta implements RightInterface
|
||||
{
|
||||
use CrudAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut,PriorityAttribut;
|
||||
use ActionTypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut,PriorityAttribut;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Infinito\Entity\Source\AbstractSource",cascade={"persist", "remove"})
|
||||
@ -74,12 +74,12 @@ class Right extends AbstractMeta implements RightInterface
|
||||
protected $grant;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="crud", type="CRUDType", nullable=false)
|
||||
* @DoctrineAssert\Enum(entity="Infinito\DBAL\Types\Meta\Right\CRUDType")
|
||||
* @ORM\Column(name="action", type="ActionType", nullable=false)
|
||||
* @DoctrineAssert\Enum(entity="Infinito\DBAL\Types\ActionType")
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $crud;
|
||||
protected $actionType;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Infinito\Entity\Source\Operation\AbstractOperation",cascade={"persist"})
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Infinito\Entity\Meta;
|
||||
|
||||
use Infinito\Attribut\CrudAttributInterface;
|
||||
use Infinito\Attribut\LawAttributInterface;
|
||||
use Infinito\Attribut\RecieverAttributInterface;
|
||||
use Infinito\Attribut\GrantAttributInterface;
|
||||
@ -10,10 +9,11 @@ use Infinito\Attribut\ConditionAttributInterface;
|
||||
use Infinito\Attribut\LayerAttributInterface;
|
||||
use Infinito\Attribut\RelationAttributInterface;
|
||||
use Infinito\Attribut\PriorityAttributInterface;
|
||||
use Infinito\Attribut\ActionTypeAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RightInterface extends CrudAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface
|
||||
interface RightInterface extends ActionTypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface
|
||||
{
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Knp\Menu\ItemInterface;
|
||||
use Infinito\Event\Menu\MenuEvent;
|
||||
use Infinito\DBAL\Types\MenuEventType;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
|
||||
|
||||
class UserMenuSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
@ -27,6 +28,9 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MenuEvent $event
|
||||
*/
|
||||
public function onUserMenuConfigure(MenuEvent $event): void
|
||||
{
|
||||
$menu = $event->getItem();
|
||||
@ -38,7 +42,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
||||
]);
|
||||
|
||||
$menu->addChild($this->translator->trans('imprint'), [
|
||||
'route' => 'imprint',
|
||||
'uri' => 'rest/api/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
|
||||
'attributes' => [
|
||||
'icon' => 'fas fa-address-card',
|
||||
],
|
||||
|
@ -30,7 +30,7 @@ class RequestedRightServiceIntegrationTest extends KernelTestCase
|
||||
public function testClassAccessors(): void
|
||||
{
|
||||
$crud = CRUDType::READ;
|
||||
$this->assertNull($this->requestedRightService->setCrud($crud));
|
||||
$this->assertEquals($crud, $this->requestedRightService->getCrud());
|
||||
$this->assertNull($this->requestedRightService->setActionType($crud));
|
||||
$this->assertEquals($crud, $this->requestedRightService->getActionType());
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class RequestedUserServiceIntegrationTest extends KernelTestCase
|
||||
public function testCrudAccessors(): void
|
||||
{
|
||||
$crud = CRUDType::READ;
|
||||
$this->assertNull($this->requestedUserService->setCrud($crud));
|
||||
$this->assertEquals($crud, $this->requestedUserService->getCrud());
|
||||
$this->assertNull($this->requestedUserService->setActionType($crud));
|
||||
$this->assertEquals($crud, $this->requestedUserService->getActionType());
|
||||
}
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ class SecureRequestedRightCheckerServiceIntegrationTest extends KernelTestCase
|
||||
$right = new Right();
|
||||
$right->setSource($source);
|
||||
$right->setLayer($layer);
|
||||
$right->setCrud($crud);
|
||||
$right->setActionType($crud);
|
||||
$right->setReciever($reciever);
|
||||
$source->getLaw()->getRights()->add($right);
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRight->setCrud($crud);
|
||||
$requestedRight->setActionType($crud);
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setReciever($reciever);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
@ -64,11 +64,11 @@ class SecureRequestedRightCheckerServiceIntegrationTest extends KernelTestCase
|
||||
$right = new Right();
|
||||
$right->setSource($source);
|
||||
$right->setLayer($layer);
|
||||
$right->setCrud(CRUDType::CREATE);
|
||||
$right->setActionType(CRUDType::CREATE);
|
||||
$right->setReciever($reciever);
|
||||
$source->getLaw()->getRights()->add($right);
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRight->setCrud($crud);
|
||||
$requestedRight->setActionType($crud);
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setReciever($reciever);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
|
@ -59,7 +59,7 @@ class RightRepositoryIntegrationTest extends KernelTestCase
|
||||
$this->right = new Right();
|
||||
$this->right->setPriority(self::PRIORITY);
|
||||
$this->right->setLayer(LayerType::SOURCE);
|
||||
$this->right->setCrud(CRUDType::READ);
|
||||
$this->right->setActionType(CRUDType::READ);
|
||||
$this->law = new Law();
|
||||
$this->entityManager->persist($this->law);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Infinito\Tests\Unit\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Infinito\Controller\DefaultController;
|
||||
use Infinito\DBAL\Types\RESTResponseType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -30,7 +31,11 @@ class DefaultControllerTest extends WebTestCase
|
||||
public function testImprint(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('GET', '/imprint');
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
// foreach(RESTResponseType::getChoices() as $format){
|
||||
$format = 'html';
|
||||
$url = 'api/rest/source/imprint.'.$format;
|
||||
$client->request('GET', $url);
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Route $url is not reachable.");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class LawPermissionCheckerTest extends TestCase
|
||||
{
|
||||
$this->clientRight = new Right();
|
||||
$this->clientRight->setLayer(LayerType::SOURCE);
|
||||
$this->clientRight->setCrud(CRUDType::READ);
|
||||
$this->clientRight->setActionType(CRUDType::READ);
|
||||
$this->clientRight->setReciever($this->clientSource);
|
||||
$this->clientRight->setSource($this->source);
|
||||
}
|
||||
@ -107,7 +107,7 @@ class LawPermissionCheckerTest extends TestCase
|
||||
{
|
||||
$this->law->getRights()->add($this->getClonedClientRight());
|
||||
$this->assertTrue($this->checkClientPermission());
|
||||
$this->clientRight->setCrud(CRUDType::UPDATE);
|
||||
$this->clientRight->setActionType(CRUDType::UPDATE);
|
||||
$this->assertFalse($this->checkClientPermission());
|
||||
}
|
||||
|
||||
@ -142,10 +142,10 @@ class LawPermissionCheckerTest extends TestCase
|
||||
public function testGetRightsByType(): void
|
||||
{
|
||||
$right = $this->getClonedClientRight();
|
||||
$right->setCrud(CRUDType::UPDATE);
|
||||
$right->setActionType(CRUDType::UPDATE);
|
||||
$this->law->getRights()->add($right);
|
||||
$this->assertFalse($this->checkClientPermission());
|
||||
$right->setCrud(CRUDType::READ);
|
||||
$right->setActionType(CRUDType::READ);
|
||||
$this->assertTrue($this->checkClientPermission());
|
||||
}
|
||||
|
||||
@ -209,13 +209,13 @@ class LawPermissionCheckerTest extends TestCase
|
||||
$clientSource = new PureSource();
|
||||
$clientRight = new Right();
|
||||
$clientRight->setLayer(LayerType::SOURCE);
|
||||
$clientRight->setCrud(CRUDType::READ);
|
||||
$clientRight->setActionType(CRUDType::READ);
|
||||
$clientRight->setSource($this->source);
|
||||
$clientRight->setReciever($clientSource);
|
||||
$this->assertFalse($this->lawPermissionChecker->hasPermission($clientRight));
|
||||
$right = new Right();
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::READ);
|
||||
$right->setActionType(CRUDType::READ);
|
||||
$right->setSource($this->source);
|
||||
$this->law->getRights()->add($right);
|
||||
$this->assertTrue($this->lawPermissionChecker->hasPermission($clientRight));
|
||||
|
@ -52,7 +52,7 @@ class RequestedActionTest extends TestCase
|
||||
$list = ActionType::EXECUTE;
|
||||
$this->action->setActionType($list);
|
||||
$this->assertEquals($list, $this->action->getActionType());
|
||||
$this->assertEquals(CRUDType::READ, $this->requestedRight->getCrud());
|
||||
$this->assertEquals(CRUDType::READ, $this->requestedRight->getActionType());
|
||||
}
|
||||
|
||||
public function testCrud(): void
|
||||
@ -60,7 +60,7 @@ class RequestedActionTest extends TestCase
|
||||
foreach (CRUDType::getChoices() as $crud) {
|
||||
$this->action->setActionType($crud);
|
||||
$this->assertEquals($crud, $this->action->getActionType());
|
||||
$this->assertEquals($crud, $this->requestedRight->getCrud());
|
||||
$this->assertEquals($crud, $this->requestedRight->getActionType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class AbstractRequestedRightFacadeTest extends TestCase
|
||||
$reciever = $this->createMock(AbstractSource::class);
|
||||
$requestedRight = $this->createMock(RequestedRightInterface::class);
|
||||
$requestedRight->method('getLayer')->willReturn($layer);
|
||||
$requestedRight->method('getCrud')->willReturn($type);
|
||||
$requestedRight->method('getActionType')->willReturn($type);
|
||||
$requestedRight->method('getSource')->willReturn($source);
|
||||
$requestedRight->method('getReciever')->willReturn($reciever);
|
||||
$requestedRight->method('getRequestedEntity')->willReturn($requestedEntity);
|
||||
@ -51,7 +51,7 @@ class AbstractRequestedRightFacadeTest extends TestCase
|
||||
$requestedRight->method('hasReciever')->willReturn(true);
|
||||
$requestedRightFacade = $this->getRequestedRightFacade($requestedRight);
|
||||
$this->assertEquals($layer, $requestedRightFacade->getLayer());
|
||||
$this->assertEquals($type, $requestedRightFacade->getCrud());
|
||||
$this->assertEquals($type, $requestedRightFacade->getActionType());
|
||||
$this->assertEquals($source, $requestedRightFacade->getSource());
|
||||
$this->assertEquals($reciever, $requestedRightFacade->getReciever());
|
||||
$this->assertEquals($requestedEntity, $requestedRightFacade->getRequestedEntity());
|
||||
@ -70,11 +70,11 @@ class AbstractRequestedRightFacadeTest extends TestCase
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRightFacade = $this->getRequestedRightFacade($requestedRight);
|
||||
$this->assertNull($requestedRightFacade->setLayer($layer));
|
||||
$this->assertNull($requestedRightFacade->setCrud($type));
|
||||
$this->assertNull($requestedRightFacade->setActionType($type));
|
||||
$this->assertNull($requestedRightFacade->setRequestedEntity($requestedEntity));
|
||||
$this->assertNull($requestedRightFacade->setReciever($reciever));
|
||||
$this->assertEquals($layer, $requestedRight->getLayer());
|
||||
$this->assertEquals($type, $requestedRight->getCrud());
|
||||
$this->assertEquals($type, $requestedRight->getActionType());
|
||||
$this->assertEquals($requestedEntity, $requestedRight->getRequestedEntity());
|
||||
$this->assertEquals($reciever, $requestedRight->getReciever());
|
||||
$this->assertTrue($requestedRight->hasReciever());
|
||||
|
@ -44,11 +44,11 @@ class RequestedUserTest extends TestCase
|
||||
$userSourceDirector->method('getUser')->willReturn($user);
|
||||
$requestedRight = $this->createMock(RequestedRightInterface::class);
|
||||
$requestedRight->method('getLayer')->willReturn($layer);
|
||||
$requestedRight->method('getCrud')->willReturn($type);
|
||||
$requestedRight->method('getActionType')->willReturn($type);
|
||||
$requestedRight->method('getSource')->willReturn($source);
|
||||
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
|
||||
$this->assertEquals($layer, $requestedUserRightFacade->getLayer());
|
||||
$this->assertEquals($type, $requestedUserRightFacade->getCrud());
|
||||
$this->assertEquals($type, $requestedUserRightFacade->getActionType());
|
||||
$this->assertEquals($source, $requestedUserRightFacade->getSource());
|
||||
$this->assertEquals($reciever, $requestedUserRightFacade->getReciever());
|
||||
}
|
||||
@ -66,10 +66,10 @@ class RequestedUserTest extends TestCase
|
||||
$userSourceDirector = new UserSourceDirector($sourceRepository, $user);
|
||||
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
|
||||
$this->assertNull($requestedUserRightFacade->setLayer($layer));
|
||||
$this->assertNull($requestedUserRightFacade->setCrud($type));
|
||||
$this->assertNull($requestedUserRightFacade->setActionType($type));
|
||||
$this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedSource));
|
||||
$this->assertEquals($layer, $requestedRight->getLayer());
|
||||
$this->assertEquals($type, $requestedRight->getCrud());
|
||||
$this->assertEquals($type, $requestedRight->getActionType());
|
||||
$this->expectException(NotCorrectInstanceException::class);
|
||||
$this->assertNotInstanceOf(RequestedEntityInterface::class, $requestedRight->getSource());
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class RightCheckerTest extends TestCase
|
||||
$this->source = new PureSource();
|
||||
$this->right = new Right();
|
||||
$this->right->setReciever($this->source);
|
||||
$this->right->setCrud($this->type);
|
||||
$this->right->setActionType($this->type);
|
||||
$this->right->setLayer($this->layer);
|
||||
$this->rightManager = new RightChecker($this->right);
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ class RightTransformerServiceTest extends TestCase
|
||||
$requestedEntity->method('getEntity')->willReturn($source);
|
||||
$requestedEntity->method('hasRequestedRight')->willReturn(true);
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRight->setCrud($crud);
|
||||
$requestedRight->setActionType($crud);
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setRequestedEntity($requestedEntity);
|
||||
$requestedRight->setReciever($reciever);
|
||||
$transformer = new RightTransformerService();
|
||||
$right = $transformer->transform($requestedRight);
|
||||
$this->assertEquals($crud, $right->getCrud());
|
||||
$this->assertEquals($crud, $right->getActionType());
|
||||
$this->assertEquals($layer, $right->getLayer());
|
||||
$this->assertEquals($reciever, $right->getReciever());
|
||||
$this->assertEquals($source, $right->getSource());
|
||||
|
@ -29,11 +29,11 @@ class SecureRequestedRightCheckerServiceTest extends TestCase
|
||||
$right = new Right();
|
||||
$right->setSource($source);
|
||||
$right->setLayer($layer);
|
||||
$right->setCrud($crud);
|
||||
$right->setActionType($crud);
|
||||
$right->setReciever($reciever);
|
||||
$source->getLaw()->getRights()->add($right);
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRight->setCrud($crud);
|
||||
$requestedRight->setActionType($crud);
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setReciever($reciever);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
@ -57,11 +57,11 @@ class SecureRequestedRightCheckerServiceTest extends TestCase
|
||||
$right = new Right();
|
||||
$right->setSource($source);
|
||||
$right->setLayer($layer);
|
||||
$right->setCrud(CRUDType::CREATE);
|
||||
$right->setActionType(CRUDType::CREATE);
|
||||
$right->setReciever($reciever);
|
||||
$source->getLaw()->getRights()->add($right);
|
||||
$requestedRight = new RequestedRight();
|
||||
$requestedRight->setCrud($crud);
|
||||
$requestedRight->setActionType($crud);
|
||||
$requestedRight->setLayer($layer);
|
||||
$requestedRight->setReciever($reciever);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
@ -83,7 +83,7 @@ class SecureRequestedRightCheckerServiceTest extends TestCase
|
||||
$source = new class() extends AbstractSource {
|
||||
};
|
||||
$requestedRight = $this->createMock(RequestedRightInterface::class);
|
||||
$requestedRight->method('getCrud')->willReturn($crud);
|
||||
$requestedRight->method('getActionType')->willReturn($crud);
|
||||
$requestedRight->method('getLayer')->willReturn($layer);
|
||||
$requestedRight->method('getReciever')->willReturn($reciever);
|
||||
$requestedRight->method('getSource')->willReturn($source);
|
||||
@ -91,7 +91,7 @@ class SecureRequestedRightCheckerServiceTest extends TestCase
|
||||
$secureEntityChecker = new SecureRequestedRightCheckerService($rightTransformerService);
|
||||
$this->assertFalse($secureEntityChecker->check($requestedRight));
|
||||
$right = new Right();
|
||||
$right->setCrud($crud);
|
||||
$right->setActionType($crud);
|
||||
$right->setLayer($layer);
|
||||
$right->setSource($source);
|
||||
$source->getLaw()->getRights()->add($right);
|
||||
|
@ -34,6 +34,9 @@ class SecureSourceCheckerTest extends TestCase
|
||||
*/
|
||||
private $securerSourceChecker;
|
||||
|
||||
/**
|
||||
* @return SourceInterface
|
||||
*/
|
||||
private function createSourceMock(): SourceInterface
|
||||
{
|
||||
return new class() extends AbstractSource implements SourceAttributInterface {
|
||||
@ -52,13 +55,13 @@ class SecureSourceCheckerTest extends TestCase
|
||||
{
|
||||
$right = new Right();
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::UPDATE);
|
||||
$right->setActionType(CRUDType::UPDATE);
|
||||
$right->setReciever($this->recieverSource);
|
||||
$right->setSource($this->source);
|
||||
$this->source->getLaw()->getRights()->add($right);
|
||||
$requestedRight = clone $right;
|
||||
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
|
||||
$requestedRight->setCrud(CRUDType::READ);
|
||||
$requestedRight->setActionType(CRUDType::READ);
|
||||
$this->assertFalse($this->securerSourceChecker->hasPermission($requestedRight));
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ class SecureSourceCheckerTest extends TestCase
|
||||
{
|
||||
$right = new Right();
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::UPDATE);
|
||||
$right->setActionType(CRUDType::UPDATE);
|
||||
$right->setReciever($this->recieverSource);
|
||||
$right->setSource($this->source);
|
||||
$this->source->getLaw()->getRights()->add($right);
|
||||
@ -76,7 +79,7 @@ class SecureSourceCheckerTest extends TestCase
|
||||
$this->source->setSource($attributSource);
|
||||
$requestedRight = clone $right;
|
||||
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
|
||||
$childRight->setCrud(CRUDType::READ);
|
||||
$childRight->setActionType(CRUDType::READ);
|
||||
$this->expectException(SourceAccessDenied::class);
|
||||
$this->securerSourceChecker->hasPermission($requestedRight);
|
||||
}
|
||||
@ -85,7 +88,7 @@ class SecureSourceCheckerTest extends TestCase
|
||||
{
|
||||
$right = new Right();
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::UPDATE);
|
||||
$right->setActionType(CRUDType::UPDATE);
|
||||
$right->setReciever($this->recieverSource);
|
||||
$right->setSource($this->source);
|
||||
$this->source->getLaw()->getRights()->add($right);
|
||||
@ -98,7 +101,7 @@ class SecureSourceCheckerTest extends TestCase
|
||||
$attribut1Source->setSource($attribut2Source);
|
||||
$requestedRight = clone $right;
|
||||
$this->assertTrue($this->securerSourceChecker->hasPermission($requestedRight));
|
||||
$childRight->setCrud(CRUDType::READ);
|
||||
$childRight->setActionType(CRUDType::READ);
|
||||
$this->expectException(SourceAccessDenied::class);
|
||||
$this->securerSourceChecker->hasPermission($requestedRight);
|
||||
}
|
||||
@ -107,13 +110,13 @@ class SecureSourceCheckerTest extends TestCase
|
||||
{
|
||||
$right = new Right();
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setCrud(CRUDType::READ);
|
||||
$right->setActionType(CRUDType::READ);
|
||||
$right->setReciever($this->recieverSource);
|
||||
$right->setSource($this->source);
|
||||
$this->assertFalse($this->securerSourceChecker->hasPermission($right));
|
||||
$requestedRight = new Right();
|
||||
$requestedRight->setLayer(LayerType::SOURCE);
|
||||
$requestedRight->setCrud(CRUDType::READ);
|
||||
$requestedRight->setActionType(CRUDType::READ);
|
||||
$requestedRight->setSource($this->source);
|
||||
$this->source->getLaw()->getRights()->add($requestedRight);
|
||||
$this->assertTrue($this->securerSourceChecker->hasPermission($right));
|
||||
|
@ -61,7 +61,7 @@ class RightTest extends TestCase
|
||||
public function testConstructorType(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->assertNull($this->right->getCrud());
|
||||
$this->assertNull($this->right->getActionType());
|
||||
}
|
||||
|
||||
public function testLaw(): void
|
||||
@ -74,11 +74,11 @@ class RightTest extends TestCase
|
||||
public function testRight(): void
|
||||
{
|
||||
foreach (CRUDType::getChoices() as $enum) {
|
||||
$this->assertNull($this->right->setCrud($enum));
|
||||
$this->assertEquals($enum, $this->right->getCrud());
|
||||
$this->assertNull($this->right->setActionType($enum));
|
||||
$this->assertEquals($enum, $this->right->getActionType());
|
||||
}
|
||||
$this->expectException(NoValidChoiceException::class);
|
||||
$this->right->setCrud('NoneValidType');
|
||||
$this->right->setActionType('NoneValidType');
|
||||
}
|
||||
|
||||
public function testLayer(): void
|
||||
@ -104,13 +104,13 @@ class RightTest extends TestCase
|
||||
$this->right->setSource($source);
|
||||
$this->right->setReciever($reciever);
|
||||
$this->right->setGrant($grant);
|
||||
$this->right->setCrud($type);
|
||||
$this->right->setActionType($type);
|
||||
$this->right->setLayer($layer);
|
||||
$rightClone = clone $this->right;
|
||||
$this->assertEquals($source, $rightClone->getSource());
|
||||
$this->assertEquals($reciever, $rightClone->getReciever());
|
||||
$this->assertEquals($grant, $rightClone->getGrant());
|
||||
$this->assertEquals($type, $rightClone->getCrud());
|
||||
$this->assertEquals($type, $rightClone->getActionType());
|
||||
$this->assertEquals($layer, $rightClone->getLayer());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user