Skip to content

Commit

Permalink
Merge pull request #2 from curiosity26/develop
Browse files Browse the repository at this point in the history
A better solution to preventing unwanted comparisons
  • Loading branch information
curiosity26 authored Nov 12, 2018
2 parents d7f8838 + 5e97fc9 commit 4672a2e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 84 deletions.
19 changes: 1 addition & 18 deletions DependencyInjection/Curiosity26AclHelperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

namespace Curiosity26\AclHelperBundle\DependencyInjection;

use Oro\ORM\Query\AST\Functions\Cast;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class Curiosity26AclHelperExtension extends Extension implements PrependExtensionInterface
class Curiosity26AclHelperExtension extends Extension
{
/**
* @param array $configs
Expand All @@ -28,19 +26,4 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new YamlFileLoader($container, new FileLocator([__DIR__.'/../Resources/config/']));
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container)
{
$configs = $container->getExtensionConfig('doctrine');

if (!empty($configs) && array_key_exists('orm', $configs[0])) {
$config = $configs[0];
$default = array_key_exists(
'default_entity_manager',
$config['orm']
) ? $config['orm']['default_entity_manager'] : 'default';
$config['orm']['entity_managers'][$default]['dql']['string_functions']['cast'] = Cast::class;
$container->prependExtensionConfig('doctrine', $config);
}
}
}
10 changes: 2 additions & 8 deletions QueryBuilder/AclHelperQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function buildAclQuery($strategy = PermissionGrantingStrategy::ANY)
$expr = $q->expr()
->andX($q->expr()->eq('acl_c.classType', ':class_type'))
->add($q->expr()->in('acl_s.identifier', ':identities'))
->add($q->expr()->neq('acl_o.objectIdentifier', "'class'"))
;

switch ($strategy) {
Expand All @@ -102,15 +103,8 @@ public function buildAclQuery($strategy = PermissionGrantingStrategy::ANY)
$expr->add($q->expr()->neq('BIT_AND(acl_e.mask, :mask)', 0));
}

$platform = $manager->getConnection()->getDatabasePlatform();

if ($platform instanceof PostgreSqlPlatform) {
$q->select('CAST(acl_o.objectIdentifier as int)');
} else {
$q->select('acl_o.objectIdentifier');
}

$q
->select('acl_o.objectIdentifier')
->distinct()
->from(ObjectIdentity::class, 'acl_o')
->innerJoin(AclClass::class, 'acl_c', Join::WITH, 'acl_c.id = acl_o.classId')
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"symfony/acl-bundle": "^1.0",
"doctrine/doctrine-bundle": "^1.9",
"doctrine/orm": "^2.6",
"symfony/class-loader": "^3.4",
"oro/doctrine-extensions": "^1.2"
"symfony/class-loader": "^3.4"
},
"require-dev": {
"phpunit/phpunit": "^7.4",
Expand Down
57 changes: 1 addition & 56 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4672a2e

Please sign in to comment.