/**
  * @param OrmResultBefore $event
  */
 public function onResultBefore(OrmResultBefore $event)
 {
     // listener logic is applied only to frontend part of application
     if ($this->securityFacade->getLoggedUser() instanceof User) {
         return;
     }
     $config = $event->getDatagrid()->getConfig();
     $query = $event->getQuery();
     /** @var Subselect|SelectStatement $select */
     $select = $query->getAST();
     $fromClause = $select instanceof SelectStatement ? $select->fromClause : $select->subselectFromClause;
     $skipAclCheck = true;
     /** @var IdentificationVariableDeclaration $identificationVariableDeclaration */
     foreach ($fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) {
         $entityName = $identificationVariableDeclaration->rangeVariableDeclaration->abstractSchemaName;
         $metadata = $this->metadataProvider->getMetadata($entityName);
         if ($metadata->hasOwner()) {
             $skipAclCheck = false;
             break;
         }
     }
     if ($skipAclCheck) {
         $config->offsetSetByPath(Builder::DATASOURCE_SKIP_ACL_CHECK, true);
     }
 }
 public function testOnResultBeforeSkipForBackendUser()
 {
     $this->securityfacade->expects($this->once())->method('getLoggedUser')->willReturn(new User());
     $this->event->expects($this->never())->method('getQuery');
     $this->event->expects($this->never())->method('getDatagrid');
     $this->metadataProvider->expects($this->never())->method('getMetadata');
     $this->listener->onResultBefore($this->event);
 }
Example #3
0
 /**
  * Gets organization of the given entity
  *
  * @param mixed $object
  * @return mixed
  * @throws InvalidEntityException     If entity is not an object
  * @throws \InvalidArgumentException  If owner property path is not defined
  */
 public function getOrganization($object)
 {
     if (!is_object($object)) {
         throw new InvalidEntityException('$object must be an object.');
     }
     $metadata = $this->metadataProvider->getMetadata(ClassUtils::getRealClass($object));
     if ($metadata->getGlobalOwnerFieldName()) {
         return $this->getValue($object, $metadata->getGlobalOwnerFieldName());
     }
     return null;
 }
 /**
  * Gets organization of the given entity
  *
  * @param $object
  * @return object|null
  * @throws InvalidEntityException
  */
 public function getOrganization($object)
 {
     if (!is_object($object)) {
         throw new InvalidEntityException('$object must be an object.');
     }
     $result = null;
     $metadata = $this->metadataProvider->getMetadata(ClassUtils::getRealClass($object));
     if ($metadata->getGlobalOwnerFieldName()) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $result = $accessor->getValue($object, $metadata->getGlobalOwnerFieldName());
     }
     return $result;
 }
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('extend');
     if (null === $config || $event->isFieldConfig()) {
         return;
     }
     $className = $config->getId()->getClassName();
     $this->provider->clearCache($className);
     $changeSet = $event->getConfigManager()->getConfigChangeSet($config);
     $isDeleted = isset($changeSet['state']) && $changeSet['state'][1] === ExtendScope::STATE_DELETE;
     if (!$isDeleted) {
         $this->provider->warmUpCache($className);
     }
 }
 /**
  * @param PersistConfigEvent $event
  */
 public function prePersistEntityConfig(PersistConfigEvent $event)
 {
     $config = $event->getConfig();
     $configId = $config->getId();
     if ($configId->getScope() !== 'extend') {
         return;
     }
     $className = $configId->getClassName();
     $this->provider->clearCache($className);
     $change = $event->getConfigManager()->getConfigChangeSet($config);
     $isDeleted = isset($change['state']) && $change['state'][1] === ExtendScope::STATE_DELETE;
     if (!$isDeleted) {
         $this->provider->warmUpCache($className);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function warmUpCache($className = null)
 {
     foreach ($this->providers as $provider) {
         $provider->warmUpCache($className);
     }
     if ($this->defaultProvider) {
         $this->defaultProvider->warmUpCache($className);
     }
 }
 /**
  * @param PersistConfigEvent $event
  */
 public function prePersistEntityConfig(PersistConfigEvent $event)
 {
     $event->getConfigManager()->calculateConfigChangeSet($event->getConfig());
     $changes = $event->getConfigManager()->getConfigChangeSet($event->getConfig());
     $isDeleted = false;
     // Now if you press delete entity button, in state variable, in 1st position will be "Deleted" string.
     // If you press restore entity, then "Deleted" string will be at 0 position.
     if (isset($changes['state']) && $changes['state'][1] === 'Deleted') {
         $isDeleted = true;
     }
     $cp = $event->getConfigManager()->getProvider('ownership');
     $className = $event->getConfig()->getId()->getClassName();
     if ($cp->hasConfig($className)) {
         $this->provider->clearCache($className);
         if (!$isDeleted) {
             $this->provider->warmUpCache($className);
         }
     }
 }
 /**
  * Gets the id of logged in user
  *
  * @return int|string
  */
 public function getUserId()
 {
     $token = $this->getSecurityContext()->getToken();
     if (!$token) {
         return null;
     }
     $user = $token->getUser();
     if (!is_object($user) || !is_a($user, $this->metadataProvider->getBasicLevelClass())) {
         return null;
     }
     return $this->objectIdAccessor->getId($user);
 }
 /**
  * {@inheritdoc}
  */
 public function clear($cacheDir)
 {
     $this->provider->clearCache();
 }
Example #11
0
 /**
  * Gets metadata for the given object
  *
  * @param mixed $object
  *
  * @return OwnershipMetadataInterface
  */
 protected function getMetadata($object)
 {
     return $this->metadataProvider->getMetadata($this->getObjectClassName($object));
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $this->provider->warmUpCache();
 }