Skip to content

[Bug]: isGranted of PermissionEvent is ignored with NOT_ALLOWED_POLICY_NULL #909

Open
@fmaerkl-sw

Description

@fmaerkl-sw

Expected behavior

Elements where an event handler for PermissionEvents::PRE_CHECK sets isGranted to false should be returned as null or filtered out of the result of a GraphQL query when NOT_ALLOWED_POLICY_NULL is used.
Just like an exception is thrown when NOT_ALLOWED_POLICY_EXCEPTION is used in the same situation.

Actual behavior

The contents of isGranted are completely ignored. It can be easily seen here that the value of $event->isGranted() has no effect if PimcoreDataHubBundle::getNotAllowedPolicy() !== PimcoreDataHubBundle::NOT_ALLOWED_POLICY_EXCEPTION:

$event = new PermissionEvent($element, $type);
/** @var EventDispatcher $eventDispatcher */
$eventDispatcher = \Pimcore::getContainer()->get('event_dispatcher');
$eventDispatcher->dispatch($event, PermissionEvents::PRE_CHECK);
if (!$event->isGranted() && PimcoreDataHubBundle::getNotAllowedPolicy() === PimcoreDataHubBundle::NOT_ALLOWED_POLICY_EXCEPTION) {
throw new ClientSafeException('access for '. $element->getFullPath() . ' denied');
}
$isAllowed = self::isAllowed($element, $configuration, $type);
if (!$isAllowed && PimcoreDataHubBundle::getNotAllowedPolicy() === PimcoreDataHubBundle::NOT_ALLOWED_POLICY_EXCEPTION) {
$elementType = Service::getElementType($element);
throw new ClientSafeException($type . ' access for ' . $elementType . ' ' . $element->getFullPath() . ' denied');
}
return $isAllowed;

Steps to reproduce

Register a handler for PermissionEvent and set isGranted to false:

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Pimcore\Bundle\DataHubBundle\Event\GraphQL\Model\PermissionEvent;
use Pimcore\Bundle\DataHubBundle\Event\GraphQL\PermissionEvents;

class GraphQlSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            PermissionEvents::PRE_CHECK => 'adaptPermissions'
        ];
    }

    public function adaptPermissions(PermissionEvent $event): void
    {
        $event->setIsGranted(false);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions