Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MenuBundle] fix Pimcore 10.6 compatibility issue #2292

Merged
merged 4 commits into from
May 24, 2023
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
25 changes: 23 additions & 2 deletions src/CoreShop/Bundle/MenuBundle/Guard/PimcoreGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
use Knp\Menu\ItemInterface;
use Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver;
use Pimcore\Model\User;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class PimcoreGuard
{
public function __construct(
private TokenStorageUserResolver $tokenStorageUserResolver,
private TokenStorageInterface $tokenStorage
) {
}

Expand All @@ -35,7 +36,27 @@ public function matchItem(ItemInterface $item): bool
return true;
}

$user = $this->tokenStorageUserResolver->getUser();
$token = $this->tokenStorage->getToken();

if (null === $token) {
return false;
}

$user = $token->getUser();

if (class_exists(\Pimcore\Security\User\User::class) && $user instanceof \Pimcore\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
}

if (class_exists(\Pimcore\Bundle\AdminBundle\Security\User\User::class) && $user instanceof \Pimcore\Bundle\AdminBundle\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
}

if ($user instanceof User) {
return $user->isAllowed((string) $item->getAttribute('permission'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:

CoreShop\Bundle\MenuBundle\Guard\PimcoreGuard:
arguments:
- '@Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver'
- '@security.token_storage'

coreshop.menu_provider.lazy_provider:
class: Knp\Menu\Provider\LazyProvider
Expand Down