Updated registration process

This commit is contained in:
Kevin Frantz 2018-09-21 19:43:48 +02:00
parent fcfe1ce9d7
commit f919b0e02c
8 changed files with 45 additions and 36 deletions

View File

@ -7,6 +7,10 @@ use App\DBAL\Types\RightType;
use App\Entity\NodeInterface;
use App\Entity\Right;
use App\Entity\LawInterface;
use App\DBAL\Types\RecieverType;
use App\Entity\RightInterface;
use App\Entity\RecieverGroupInterface;
use App\Entity\RecieverGroup;
/**
* @author kevinfrantz
@ -17,13 +21,30 @@ abstract class LawModificator
{
foreach (LayerType::getChoices() as $layerKey => $layerValue) {
foreach (RightType::getChoices() as $rightKey => $rightValue) {
$right = new Right();
$right->setType($rightKey);
$right->setLaw($this);
$right->setLayer($layerKey);
$right->setNode($node);
$right = self::createRight($law, $node, $rightKey, $layerKey);
$right->setRecieverGroup(self::createRecieverGroup($node, RecieverType::NODE));
$law->getRights()->add($right);
}
}
}
public static function createRight(LawInterface $law, NodeInterface $node, string $type, string $layer): RightInterface
{
$right = new Right();
$right->setType($type);
$right->setLaw($law);
$right->setLayer($layer);
$right->setNode($node);
return $right;
}
public static function createRecieverGroup(NodeInterface $node, string $reciever): RecieverGroupInterface
{
$recieverGroup = new RecieverGroup();
$recieverGroup->setNode($node);
$recieverGroup->setReciever($reciever);
return $recieverGroup;
}
}

View File

@ -21,8 +21,8 @@ class AbstractEntity
*/
protected $id;
protected function __construct()
public function __construct()
{
$this->id = 0;
//$this->id = 0;
}
}

View File

@ -4,10 +4,11 @@ namespace App\Entity;
use App\Entity\Attribut\RightsAttributInterface;
use App\Entity\Method\NodeGrantedInterface;
use App\Entity\Attribut\NodeAttributInterface;
/**
* @author kevinfrantz
*/
interface LawInterface extends RightsAttributInterface, NodeGrantedInterface
interface LawInterface extends RightsAttributInterface, NodeGrantedInterface, NodeAttributInterface
{
}

View File

@ -8,6 +8,7 @@ use App\Entity\Attribut\SourceAttribut;
use App\Entity\Attribut\ParentsAttribut;
use App\Entity\Attribut\ChildsAttribut;
use App\Entity\Attribut\LawAttribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @author kevinfrantz
@ -41,20 +42,8 @@ class Node extends AbstractEntity implements NodeInterface
public function __construct()
{
$this->law = new Law();
$this->parents = new ArrayCollection();
$this->childs = new ArrayCollection();
$this->law->setNode($this);
$this->initPermissions();
}
private function initPermissions(): void
{
/*
* @var RightInterface
*/
foreach ($this->law->getRights()->toArray() as $right) {
$permission = new Permission();
$permission->setNode($this);
$permission->setRight($right);
$right->addPermission($permission);
}
}
}

View File

@ -8,9 +8,7 @@ use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttribut;
use App\DBAL\Types\LayerType;
use App\DBAL\Types\RightType;
use App\Entity\Attribut\PermissionsAttribut;
use App\Entity\Attribut\NodeAttribut;
use App\Entity\Attribut\RecieverAttribut;
use App\Entity\Attribut\GrantAttribut;
use App\Logic\Operation\OperationInterface;
use App\Entity\Attribut\ConditionAttribut;
@ -24,7 +22,7 @@ use App\Entity\Attribut\LayerAttribut;
*/
class Right extends AbstractEntity implements RightInterface
{
use TypeAttribut,LawAttribut,PermissionsAttribut, NodeAttribut, RecieverAttribut,GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut;
use TypeAttribut,LawAttribut, NodeAttribut, GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut;
/**
* @ORM\ManyToOne(targetEntity="Law", inversedBy="rights")
@ -75,7 +73,8 @@ class Right extends AbstractEntity implements RightInterface
/**
* @ORM\OneToOne(targetEntity="AbstractOperation",cascade={"persist"})
* @ORM\Column(nullable=true)
* @ORM\JoinColumn(name="operation_id", referencedColumnName="id",nullable=true)
*
* @var OperationInterface
*/
protected $condition;
@ -84,7 +83,8 @@ class Right extends AbstractEntity implements RightInterface
{
parent::__construct();
$this->grant = true;
$this->recieverGroup = new RecieverGroup();
//$this->node = new Node();
//$this->recieverGroup = new RecieverGroup();
}
public function isGranted(NodeInterface $node, string $layer, string $right): bool

View File

@ -43,5 +43,6 @@ class User extends BaseUser implements SourceAttributInterface
$this->isActive = true;
$this->source = new UserSource();
LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode());
//var_dump($this->source->getNode()->getLaw()->getRights()->get(0));
}
}

View File

@ -3,7 +3,6 @@
namespace App\Tests\Unit\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use App\Controller\DefaultControllerInterface;
use App\Controller\DefaultController;
/**

View File

@ -1,4 +1,5 @@
<?php
namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase;
@ -8,18 +9,15 @@ use App\Entity\UserSource;
use App\Entity\Node;
/**
*
* @author kevinfrantz
*/
class UserTest extends TestCase
{
const PASSWORD = '12345678';
const USERNAME = 'tester';
/**
*
* @var User
*/
protected $user;
@ -40,19 +38,19 @@ class UserTest extends TestCase
$this->user->setPassword(self::PASSWORD);
$this->assertEquals(self::PASSWORD, $this->user->getPassword());
}
public function testSource(): void
{
$this->assertInstanceOf(UserSource::class,$this->user->getSource());
$this->assertInstanceOf(UserSource::class, $this->user->getSource());
}
public function testNode(): void
{
$this->assertInstanceOf(Node::class,$this->user->getSource()->getNode());
$this->assertInstanceOf(Node::class, $this->user->getSource()->getNode());
}
public function testLaw(): void
{
$this->assertInstanceOf(Law::class,$this->user->getSource()->getNode()->getLaw());
$this->assertInstanceOf(Law::class, $this->user->getSource()->getNode()->getLaw());
}
}