Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ services:
tags:
- { name: security.voter }

Pimcore\Bundle\StudioBackendBundle\Security\CacheClearer\UserPermissionCacheClearer:
tags:
- { name: kernel.cache_clearer }

Pimcore\Bundle\StudioBackendBundle\Security\Voter\HasOneOfUserPermissionVoter:
tags:
- { name: security.voter }
Expand Down
38 changes: 38 additions & 0 deletions src/Security/CacheClearer/UserPermissionCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Security\CacheClearer;

use Pimcore\Bundle\StaticResolverBundle\Lib\CacheResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\CacheKeys;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;

/**
* Drops the cached list of permission definitions on cache:clear, which also runs after
* pimcore:bundle:install, so permissions created by a bundle installer are picked up
* by the UserPermissionVoter.
*
* @internal
*/
final readonly class UserPermissionCacheClearer implements CacheClearerInterface
{
public function __construct(
private CacheResolverInterface $cacheResolver
) {
}

public function clear(string $cacheDir): void
{
$this->cacheResolver->remove(CacheKeys::USER_PERMISSIONS->value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Tests\Unit\Security\CacheClearer;

use Codeception\Test\Unit;
use Pimcore\Bundle\StaticResolverBundle\Lib\CacheResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Security\CacheClearer\UserPermissionCacheClearer;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\CacheKeys;

/**
* @internal
*/
final class UserPermissionCacheClearerTest extends Unit
{
public function testClearRemovesTheCachedPermissionDefinitions(): void
{
$cacheResolver = $this->createMock(CacheResolverInterface::class);
$cacheResolver->expects($this->once())
->method('remove')
->with(CacheKeys::USER_PERMISSIONS->value);

(new UserPermissionCacheClearer($cacheResolver))->clear('/tmp/cache');
}
}
Loading