-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate acl_user_manager without implementing AdminAclUserManagerIn…
…terface It also deprecates to not explicitly configuring acl_user_manager service when using ACL because if you use "friendsofsymfony/user-bundle", it adds "fos_user_manager" as "acl_user_manager" automatically. After this, this service MUST implements AdminAclUserManagerInterface allowing us to have an API for retrieving users when using ACL.
- Loading branch information
Showing
8 changed files
with
272 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/DependencyInjection/Compiler/CheckAclUserManagerCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\DependencyInjection\Compiler; | ||
|
||
use Sonata\AdminBundle\Util\AdminAclUserManagerInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this class. | ||
* | ||
* @internal | ||
*/ | ||
final class CheckAclUserManagerCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasParameter('sonata.admin.security.acl_user_manager') | ||
|| !$container->hasParameter('sonata.admin.security.fos_user_autoconfigured')) { | ||
return; | ||
} | ||
|
||
$userManagerServiceName = $container->getParameter('sonata.admin.security.acl_user_manager'); | ||
|
||
if (null === $userManagerServiceName | ||
|| !$container->hasDefinition($userManagerServiceName) | ||
|| $container->getParameter('sonata.admin.security.fos_user_autoconfigured')) { | ||
return; | ||
} | ||
|
||
$userManagerDefinition = $container->findDefinition($userManagerServiceName); | ||
|
||
if (!is_a($userManagerDefinition->getClass(), AdminAclUserManagerInterface::class, true)) { | ||
@trigger_error(sprintf( | ||
'Configuring a service in sonata_admin.security.acl_user_manager without implementing "%s"' | ||
.' is deprecated since sonata-project/admin-bundle 3.x and will throw an "%s" exception in 4.0.', | ||
AdminAclUserManagerInterface::class, | ||
\InvalidArgumentException::class | ||
), E_USER_DEPRECATED); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Util; | ||
|
||
/** | ||
* @author Mathieu Petrini <[email protected]> | ||
*/ | ||
interface AdminAclUserManagerInterface | ||
{ | ||
/** | ||
* Batch configure the ACLs for all objects handled by an Admin. | ||
*/ | ||
public function findUsers(): iterable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/DependencyInjection/Compiler/CheckAclUserManagerCompilerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sonata\AdminBundle\DependencyInjection\Compiler\CheckAclUserManagerCompilerPass; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this test. | ||
* | ||
* @group legacy | ||
*/ | ||
final class CheckAclUserManagerCompilerPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
public function testTriggersADeprecationIfItAclUserManagerIsNotProperlyConfigured(): void | ||
{ | ||
$aclUserManager = new Definition(\stdClass::class); | ||
$this->setDefinition('acl_user_manager', $aclUserManager); | ||
$this->setParameter('sonata.admin.security.acl_user_manager', 'acl_user_manager'); | ||
$this->setParameter('sonata.admin.security.fos_user_autoconfigured', false); | ||
|
||
$this->expectDeprecation('Configuring a service in sonata_admin.security.acl_user_manager without implementing "Sonata\AdminBundle\Util\AdminAclUserManagerInterface" is deprecated since sonata-project/admin-bundle 3.x and will throw an "InvalidArgumentException" exception in 4.0.'); | ||
|
||
$this->compile(); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$container->addCompilerPass(new CheckAclUserManagerCompilerPass()); | ||
} | ||
} |