Skip to content

Commit

Permalink
Merge branch hotfix/v2.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Mar 7, 2024
1 parent be780e6 commit 1cf960e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
parameters:
roadiz_core.cms_version: '2.2.7'
roadiz_core.cms_version: '2.2.8'
roadiz_core.cms_version_prefix: 'main'
env(APP_NAMESPACE): "roadiz"
env(APP_VERSION): "0.1.0"
Expand Down
26 changes: 15 additions & 11 deletions src/Realm/RealmResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\RealmVoter;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\String\Slugger\AsciiSlugger;

final class RealmResolver implements RealmResolverInterface
{
private ManagerRegistry $managerRegistry;
private Security $security;
private CacheItemPoolInterface $cache;

public function __construct(ManagerRegistry $managerRegistry, Security $security, CacheItemPoolInterface $cache)
{
$this->managerRegistry = $managerRegistry;
$this->security = $security;
$this->cache = $cache;
public function __construct(
private readonly ManagerRegistry $managerRegistry,
private readonly Security $security,
private readonly CacheItemPoolInterface $cache
) {
}

public function getRealms(?Node $node): array
Expand All @@ -49,9 +46,16 @@ public function denyUnlessGranted(RealmInterface $realm): void
}
}

private function getUserCacheKey(): string
{
return (new AsciiSlugger())
->slug($this->security->getUser()?->getUserIdentifier() ?? 'anonymous')
->__toString();
}

public function getGrantedRealms(): array
{
$cacheItem = $this->cache->getItem('granted_realms');
$cacheItem = $this->cache->getItem('granted_realms_' . $this->getUserCacheKey());
if (!$cacheItem->isHit()) {
$allRealms = $this->managerRegistry->getRepository(Realm::class)->findBy([]);
$cacheItem->set(array_filter($allRealms, fn(RealmInterface $realm) => $this->isGranted($realm)));
Expand All @@ -63,7 +67,7 @@ public function getGrantedRealms(): array

public function getDeniedRealms(): array
{
$cacheItem = $this->cache->getItem('denied_realms');
$cacheItem = $this->cache->getItem('denied_realms_' . $this->getUserCacheKey());
if (!$cacheItem->isHit()) {
$allRealms = $this->managerRegistry->getRepository(Realm::class)->findBy([]);
$cacheItem->set(array_filter($allRealms, fn(RealmInterface $realm) => !$this->isGranted($realm)));
Expand Down

0 comments on commit 1cf960e

Please sign in to comment.