Implemented Permission draft

This commit is contained in:
Kevin Frantz 2018-09-13 16:51:58 +02:00
parent 92886a14ce
commit 69f2beac72
28 changed files with 203 additions and 143 deletions

View File

@ -1,25 +1,23 @@
<?php
namespace App\DBAL\Types;
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
/**
*
* @author kevinfrantz
*
*/
final class RightType extends AbstractEnumType
{
public const ADMINISTRATION = 'administration';
public const READ = 'read';
public const WRITE = 'write';
protected static $choices = [
self::ADMINISTRATION => 'administration',
self::READ => 'read',
self::WRITE=>'write',
self::WRITE => 'write',
];
}

View File

@ -1,24 +1,23 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\IdAttribut;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @author kevinfrantz
*
*/
class AbstractEntity
{
use IdAttribut;
/**
* @ORM\Id()
* @ORM\GeneratedValue
* @ORM\Column(type="integer")(strategy="AUTO")
*
* @var int
*/
protected $id;
}

View File

@ -17,15 +17,16 @@ use Doctrine\ORM\Mapping as ORM;
abstract class AbstractSource extends AbstractEntity implements SourceInterface
{
use NodeAttribut;
/**
* @var NodeInterface
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
*/
protected $node;
public function __construct(){
public function __construct()
{
$this->node = new Node();
$this->node->setSource($this);
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
trait BlacklistAttribut
{
/**
* @var bool
*/
protected $blacklist;
public function setBlacklist(?bool $value): void
{
$this->blacklist = $value;
}
public function getBlacklist(): ?bool
{
return $this->blacklist;
}
}

View File

@ -1,10 +1,9 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface BlacklistAttributInterface
{
@ -12,4 +11,3 @@ interface BlacklistAttributInterface
public function getBlacklist(): ?bool;
}

View File

@ -1,26 +1,26 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\LawInterface;
/**
*
* @author kevinfrantz
*
*/
trait LawAttribut {
/**
trait LawAttribut
{
/**
* @var LawInterface
*/
protected $law;
public function setLaw(LawInterface $law):void{
public function setLaw(LawInterface $law): void
{
$this->law = $law;
}
public function getLaw(): LawInterface{
public function getLaw(): LawInterface
{
return $this->law;
}
}

View File

@ -1,18 +1,15 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\LawInterface;
/**
*
* @author kevinfrantz
*
*/
interface LawAttributInterface
{
public function setLaw(LawInterface $law):void;
public function setLaw(LawInterface $law): void;
public function getLaw(): LawInterface;
}

View File

@ -1,17 +1,15 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\RightInterface;
/**
*
* @author kevinfrantz
*
*/
interface RightAttributInterface
{
public function setRight(RightInterface $right):void;
public function getRight():RightInterface;
}
public function setRight(RightInterface $right): void;
public function getRight(): RightInterface;
}

View File

@ -1,17 +1,15 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
interface RightsAttributInterface
{
public function setRights(ArrayCollection $rights):void;
public function getRights():ArrayCollection;
}
public function setRights(ArrayCollection $rights): void;
public function getRights(): ArrayCollection;
}

View File

@ -1,26 +1,26 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
trait RightsAttribute {
trait RightsAttribute
{
/**
* @var ArrayCollection
*/
protected $rights;
public function setRights(ArrayCollection $rights):void{
public function setRights(ArrayCollection $rights): void
{
$this->rights = $rights;
}
public function getRights():ArrayCollection{
public function getRights(): ArrayCollection
{
return $this->rights;
}
}

View File

@ -1,24 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
trait TypeAttribut {
trait TypeAttribut
{
/**
*
* @var string
*/
protected $type;
public function setType(string $type):void{
public function setType(string $type): void
{
$this->type = $type;
}
public function getType():string{
public function getType(): string
{
return $this->type;
}
}

View File

@ -1,15 +1,13 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface TypeAttributInterface
{
public function setType(string $type):void;
public function getType():string;
}
public function setType(string $type): void;
public function getType(): string;
}

View File

@ -1,26 +1,26 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\User;
/**
*
* @author kevinfrantz
*
*/
trait UserAttribut {
trait UserAttribut
{
/**
* @var User
*/
protected $user;
public function setUser(User $user):void{
public function setUser(User $user): void
{
$this->user = $user;
}
public function getUser():User{
public function getUser(): User
{
return $this->user;
}
}

View File

@ -1,17 +1,15 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\User;
/**
*
* @author kevinfrantz
*
*/
interface UserAttributInterface
{
public function setUser(User $user):void;
public function getUser():User;
}
public function setUser(User $user): void;
public function getUser(): User;
}

View File

@ -1,28 +1,28 @@
<?php
namespace Entity\Attribut;
use App\Entity\UserSourceInterface;
/**
*
* @author kevinfrantz
*
*/
trait UserSource {
trait UserSource
{
/**
*
* @var UserSourceInterface
* @ORM\OneToOne(targetEntity="UserSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id")
*/
protected $userSource;
public function setUserSource(UserSourceInterface $userSource):void{
public function setUserSource(UserSourceInterface $userSource): void
{
$this->user = $userSource;
}
public function getUserSource():UserSourceInterface{
public function getUserSource(): UserSourceInterface
{
return $this->userSource;
}
}

View File

@ -1,17 +1,15 @@
<?php
namespace Entity\Attribut;
use App\Entity\UserSourceInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserSourceAttributInterface
{
public function setUserSource(UserSourceInterface $user):void;
public function getUserSource():UserSourceInterface;
}
public function setUserSource(UserSourceInterface $user): void;
public function getUserSource(): UserSourceInterface;
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
* @author kevinfrantz
*/
trait WhitelistAttribut
{
/**
* @var bool
*/
protected $whitelist;
public function setWhitelist(?bool $value): void
{
$this->whitelist = $value;
}
public function getWhitelist(): ?bool
{
return $this->whitelist;
}
}

View File

@ -1,15 +1,13 @@
<?php
namespace Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface WhitelistAttributInterface
{
public function setWhitelist(?bool $value): void;
public function getWhitelist(): ?bool;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -8,7 +9,6 @@ use App\DBAL\Types\RightType;
use App\Entity\Attribut\NodeAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="law")
* @ORM\Entity(repositoryClass="App\Repository\LawRepository")
@ -18,8 +18,8 @@ class Law extends AbstractEntity implements LawInterface
use RightsAttribute, NodeAttribut;
/**
*
* @ORM\OneToMany(targetEntity="Right", mappedBy="id", cascade={"persist", "remove"})
*
* @var ArrayCollection
*/
protected $rights;
@ -27,10 +27,11 @@ class Law extends AbstractEntity implements LawInterface
/**
* @ORM\OneToOne(targetEntity="Node",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="node_id", referencedColumnName="id")
*
* @var NodeInterface
*/
protected $node;
public function __construct()
{
$this->initAllRights();
@ -39,13 +40,11 @@ class Law extends AbstractEntity implements LawInterface
private function initAllRights(): void
{
$this->rights = new ArrayCollection();
foreach (RightType::getChoices() as $key=>$value){
foreach (RightType::getChoices() as $key => $value) {
$right = new Right();
$right->setType($value);
$right->setLaw($this);
$this->rights->set($key, $right);
}
}
}

View File

@ -1,15 +1,12 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\RightsAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface LawInterface extends RightsAttributInterface
{
}

View File

@ -21,22 +21,25 @@ class Node extends AbstractEntity implements NodeInterface
ParentAttribut,
LawAttribut,
ChildsAttribut;
/**
* @ORM\OneToOne(targetEntity="AbstractSource",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
*
* @var SourceInterface
*/
protected $source;
/**
* @ORM\OneToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
*
* @var LawInterface
*/
protected $law;
public function __construct(){
public function __construct()
{
$this->law = new Law();
$this->law->setNode($this);
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\BlacklistAttribut;
use App\Entity\Attribut\WhitelistAttribut;
/**
* @author kevinfrantz
* @ORM\Table(name="permission")
* @ORM\Entity(repositoryClass="App\Repository\PermissionRepository")
*/
class Permission extends AbstractEntity implements PermissionInterface
{
use BlacklistAttribut,WhitelistAttribut;
/**
* @ORM\Column(type="boolean")
*
* @var bool
*/
protected $blacklist;
/**
* @ORM\Column(type="boolean")
*
* @var bool
*/
protected $whitelist;
}

View File

@ -1,16 +1,13 @@
<?php
namespace Entity;
namespace App\Entity;
use App\Entity\Attribut\BlacklistAttributInterface;
use Entity\Attribut\WhitelistAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface PermissionInterface extends BlacklistAttributInterface, WhitelistAttributInterface
{
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
@ -6,11 +7,9 @@ use App\Entity\Attribut\TypeAttribut;
use App\DBAL\Types\RightType;
use Doctrine\ORM\Mapping as ORM;
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\LawAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="`right`")
* @ORM\Entity(repositoryClass="App\Repository\RightRepository")
@ -18,26 +17,35 @@ use App\Entity\Attribut\LawAttribut;
class Right extends AbstractEntity implements RightInterface
{
use TypeAttribut,LawAttribut;
/**
* @ORM\ManyToOne(targetEntity="Law",cascade={"persist", "remove"})
* @ORM\JoinColumn(name="law_id", referencedColumnName="id")
*
* @var LawInterface
*/
protected $law;
/**
* @ORM\Column(name="type", type="RightType", nullable=false)
* @DoctrineAssert\Enum(entity="App\DBAL\Types\RightType")
*
* @var string
*/
protected $type;
/**
* @ORM\OneToMany(targetEntity="Right", mappedBy="id", cascade={"persist", "remove"})
*
* @var ArrayCollection
*/
protected $permissions;
public function isGranted(NodeInterface $node): bool
{}
{
}
public function setPermissions(ArrayCollection $permissions): void
{}
{
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
@ -6,14 +7,11 @@ use App\Entity\Attribut\TypeAttributInterface;
use App\Entity\Attribut\LawAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface RightInterface extends TypeAttributInterface, LawAttributInterface
{
public function isGranted(NodeInterface $node): bool;
public function setPermissions(ArrayCollection $permissions):void;
}
public function setPermissions(ArrayCollection $permissions): void;
}

View File

@ -23,7 +23,7 @@ class User extends BaseUser implements SourceAttributInterface
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id")
*/
protected $source;
/**
* @ORM\Column(name="is_active", type="boolean")
*/

View File

@ -1,11 +1,11 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\UserAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="source_user")
* @ORM\Entity(repositoryClass="App\Repository\UserSourceRepository")
@ -13,12 +13,12 @@ use App\Entity\Attribut\UserAttribut;
class UserSource extends AbstractSource implements UserSourceInterface
{
use UserAttribut;
/**
* @ORM\OneToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*
* @var User
*/
protected $user;
}

View File

@ -1,14 +1,12 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\UserAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserSourceInterface extends SourceInterface, UserAttributInterface
{
}