oroinc / platform

Main OroPlatform package with core functionality.
Other
627 stars 351 forks source link

Query hints are not being applied after "oro_datagrid.orm_datasource.result.before" event #1018

Open hvanoch opened 4 years ago

hvanoch commented 4 years ago

Summary
Query hints are applied before the "oro_datagrid.orm_datasource.result.before" is being called. (see src/Oro/Bundle/DataGridBundle/Datasource/Orm/OrmDatasource.php) That way if we add other stuff like the OrmDatasourceAclListener, which adds query hints for applying ACL rules, the hints are not rewalked again.

If this as expected? We override the OrmDatasourceAclListener to apply more strict rules based on custom datagrid options. But since the query hints are resolved before the dispatch of the event, they are never applied. This how it is now.

        $query = $this->qb->getQuery();
        $this->queryHintResolver->resolveHints($query, $this->queryHints ?? []);

        $this->eventDispatcher->dispatch(
            OrmResultBefore::NAME,
            new OrmResultBefore($this->datagrid, $query)
        );

        $rows = $this->queryExecutor->execute($this->datagrid, $query);

How I believe it should be:

        $query = $this->qb->getQuery();

        $this->eventDispatcher->dispatch(
            OrmResultBefore::NAME,
            new OrmResultBefore($this->datagrid, $query)
        );

        $this->queryHintResolver->resolveHints($query, $this->queryHints ?? []);

        $rows = $this->queryExecutor->execute($this->datagrid, $query);

Steps to reproduce

  1. Create a ORMResultBeforeListener which applies a walker, like the \Oro\Bundle\SecurityBundle\ORM\Walker\AclHelper
  2. Load the datagrid.

Actual Result The ACLs did not apply

Expected Result
ACLs being applied

Details about your environment