Skip to content

Commit

Permalink
Merge pull request #5 from curiosity26/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
curiosity26 committed Nov 28, 2018
2 parents 6612967 + 415ccf1 commit 126ec65
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 91 deletions.
36 changes: 18 additions & 18 deletions Entity/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
class Entry
{
private $id;
private $classId;
private $objectIdentityId;
private $securityIdentityId;
private $class;
private $objectIdentity;
private $securityIdentity;
private $fieldName;
private $aceOrder;
private $mask;
Expand Down Expand Up @@ -41,49 +41,49 @@ public function setId($id)
/**
* @return mixed
*/
public function getClassId()
public function getClass()
{
return $this->classId;
return $this->class;
}

/**
* @param mixed $classId
* @param mixed $class
*/
public function setClassId($classId)
public function setClass(AclClass $class)
{
$this->classId = $classId;
$this->class = $class;
}

/**
* @return mixed
*/
public function getObjectIdentityId()
public function getObjectIdentity()
{
return $this->objectIdentityId;
return $this->objectIdentity;
}

/**
* @param mixed $object_entity_id
* @param ObjectIdentity $object_entity_id
*/
public function setObjectIdentityId($objectIdentityId)
public function setObjectIdentity(ObjectIdentity $objectIdentity)
{
$this->objectIdentityId = $objectIdentityId;
$this->objectIdentity = $objectIdentity;
}

/**
* @return mixed
*/
public function getSecurityIdentityId()
public function getSecurityIdentity()
{
return $this->securityIdentityId;
return $this->securityIdentity;
}

/**
* @param mixed $securityIdentityId
* @param mixed $securityIdentity
*/
public function setSecurityIdentityId($securityIdentityId)
public function setSecurityIdentity(SecurityIdentity $securityIdentity)
{
$this->securityIdentityId = $securityIdentityId;
$this->securityIdentity = $securityIdentity;
}

/**
Expand Down
66 changes: 54 additions & 12 deletions Entity/ObjectIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
class ObjectIdentity
{
private $id;
private $parentObjectIdentityId;
private $classId;
private $parentObjectIdentity;
private $parent;
private $ancestor;
private $class;
private $objectIdentifier;
private $entriesInheriting;

Expand All @@ -35,33 +37,33 @@ public function setId($id)
/**
* @return mixed
*/
public function getParentObjectIdentityId()
public function getParentObjectIdentity()
{
return $this->parentObjectIdentityId;
return $this->parentObjectIdentity;
}

/**
* @param mixed $parentObjectIdentityId
* @param mixed $parentObjectIdentity
*/
public function setParentObjectIdentityId($parentObjectIdentityId)
public function setParentObjectIdentity($parentObjectIdentity)
{
$this->parentObjectIdentityId = $parentObjectIdentityId;
$this->parentObjectIdentity = $parentObjectIdentity;
}

/**
* @return mixed
*/
public function getClassId()
public function getClass()
{
return $this->classId;
return $this->class;
}

/**
* @param mixed $classId
* @param mixed $class
*/
public function setClassId($classId)
public function setClass($class)
{
$this->classId = $classId;
$this->class = $class;
}

/**
Expand Down Expand Up @@ -95,4 +97,44 @@ public function setEntriesInheriting($entriesInheriting)
{
$this->entriesInheriting = $entriesInheriting;
}

/**
* @return mixed
*/
public function getParent()
{
return $this->parent;
}

/**
* @param mixed $parent
*
* @return ObjectIdentity
*/
public function setParent(ObjectIdentity $parent)
{
$this->parent = $parent;

return $this;
}

/**
* @return mixed
*/
public function getAncestor()
{
return $this->ancestor;
}

/**
* @param mixed $ancestor
*
* @return ObjectIdentity
*/
public function setAncestor(ObjectIdentity $ancestor)
{
$this->ancestor = $ancestor;

return $this;
}
}
34 changes: 34 additions & 0 deletions EventListener/AclSchemaListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: alex.boyce
* Date: 11/28/18
* Time: 10:13 AM
*/

namespace Curiosity26\AclHelperBundle\EventListener;

use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Symfony\Component\Security\Acl\Dbal\Schema;

class AclSchemaListener
{
private $schema;

public function __construct(Schema $schema)
{
$this->schema = $schema;
}

public function postGenerateSchema(GenerateSchemaEventArgs $args)
{
$schema = $args->getSchema();

foreach ($schema->getTableNames() as $tableName) {
if (false != preg_match('/^acl_/', $tableName)) {
$this->schema->addToSchema($schema);
break;
}
}
}
}
16 changes: 10 additions & 6 deletions Helper/AclHelperAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ public function findBy(

if (!empty($criteria)) {
$predicates = $builder->expr()->andX();

foreach ($criteria as $field => $criterion) {
$predicates->add(
is_array($criterion)
? $builder->expr()->in("e,$field", ":$field")
: $builder->expr()->eq("e.$field", ":$field")
);
$builder->setParameter(":$field", $criterion);
if (is_array($criterion)) {
$predicates->add($builder->expr()->in("e.$field", ":$field"));
$builder->setParameter(":$field", $criterion);
} elseif (null !== $criterion) {
$predicates->add($builder->expr()->eq("e.$field", ":$field"));
$builder->setParameter(":$field", $criterion);
} else {
$predicates->add($builder->expr()->isNull("e.$field"));
}
}

$builder->where($predicates);
Expand Down
6 changes: 3 additions & 3 deletions QueryBuilder/AclHelperQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ public function buildAclQuery($strategy = PermissionGrantingStrategy::ANY)
->select('INT(acl_o.objectIdentifier)')
->distinct()
->from(ObjectIdentity::class, 'acl_o')
->innerJoin(AclClass::class, 'acl_c', Join::WITH, 'acl_c.id = acl_o.classId')
->innerJoin(AclClass::class, 'acl_c', Join::WITH, 'acl_c.id = acl_o.class')
->leftJoin(
Entry::class,
'acl_e',
Join::WITH,
'acl_e.objectIdentityId = acl_o.id OR acl_e.objectIdentityId IS NULL'
'acl_e.objectIdentity = acl_o.id OR acl_e.objectIdentity IS NULL'
)
->leftJoin(
SecurityIdentity::class,
'acl_s',
Join::WITH,
'acl_e.securityIdentityId = acl_s.id'
'acl_e.securityIdentity = acl_s.id'
)
->where(
$expr
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/doctrine/AclClass.orm.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Curiosity26\AclHelperBundle\Entity\AclClass:
table: "acl_classes"
type: entity
read-only: true
readOnly: true
id:
id:
type: integer
Expand Down
34 changes: 15 additions & 19 deletions Resources/config/doctrine/Entry.orm.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
Curiosity26\AclHelperBundle\Entity\Entry:
table: "acl_entries"
type: entity
read-only: true
readOnly: true
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
classId:
name: class_id
type: integer
options:
unsigned: true
objectIdentityId:
name: object_identity_id
type: integer
options:
unsigned: true
securityIdentityId:
name: security_identity_id
type: integer
options:
unsigned: true
fieldName:
name: field_name
type: string
length: 50
nullable: true
aceOrder:
name: ace_order
type: smallint
default: 0
options:
unsigned: true
mask:
Expand All @@ -39,9 +24,20 @@ Curiosity26\AclHelperBundle\Entity\Entry:
name: granting_strategy
type: string
length: 30
default: 'all'
auditSuccess:
name: audit_success
type: boolean
auditFailure:
name: audit_failure
type: boolean
type: boolean
manyToOne:
class:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\AclClass'
cascade: ["persist"]
objectIdentity:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\ObjectIdentity'
casade: ['persist']
securityIdentity:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\SecurityIdentity'
cascade: ["persist"]
36 changes: 25 additions & 11 deletions Resources/config/doctrine/ObjectIdentity.orm.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
Curiosity26\AclHelperBundle\Entity\ObjectIdentity:
table: "acl_object_identities"
type: entity
read-only: true
readOnly: true
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
parentObjectIdentityId:
name: parent_object_identity_id
type: integer
options:
unsigned: true
classId:
name: class_id
parentObjectIdentity:
column: parent_object_identity_id
type: integer
nullable: true
options:
unsigned: true
objectIdentifier:
name: object_identifier
type: string
length: 100
entriesInheriting:
name: entries_inheriting
type: boolean
type: boolean
manyToOne:
class:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\AclClass'
cascade: ["persist"]
manyToMany:
parent:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\ObjectIdentity'
mappedBy: ancestor
ancestor:
targetEntity: 'Curiosity26\AclHelperBundle\Entity\ObjectIdentity'
inversedBy: parentObjectIdentity
joinTable:
name: acl_object_identity_ancestors
inversedJoinColumns:
object_identity_id:
referencedColumnName: id
joinColumns:
ancestor_id:
referencedColumnName: id

2 changes: 1 addition & 1 deletion Resources/config/doctrine/SecurityIdentity.orm.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Curiosity26\AclHelperBundle\Entity\SecurityIdentity:
table: "acl_security_identities"
type: entity
read_only: true
readOnly: true
id:
id:
type: integer
Expand Down
Loading

0 comments on commit 126ec65

Please sign in to comment.