Example #1
0
 /**
  * Apply ACL to search Query.
  * Removes all entities of the request to which the user has no access
  *
  * @param Query $query
  */
 protected function applyAclToQuery(Query $query)
 {
     $allowedEntities = $this->getAllowedEntitiesListAliases();
     $queryFromEntities = $query->getFrom();
     $entitiesList = array_values($allowedEntities);
     // in query, from record !== '*'
     if (!empty($queryFromEntities) && $queryFromEntities[0] !== '*') {
         foreach ($queryFromEntities as $key => $fromEntityAlias) {
             if (!in_array($fromEntityAlias, $entitiesList)) {
                 unset($queryFromEntities[$key]);
             }
         }
         $query->from($queryFromEntities);
     } elseif ($allowedEntities != $this->mapper->getEntitiesListAliases()) {
         $query->from($allowedEntities);
     }
 }
Example #2
0
 /**
  * Apply special behavior of class inheritance processing
  *
  * @param Query $query
  */
 protected function applyModesBehavior(Query $query)
 {
     // process abstract indexes
     // make hashes increasing performance
     $fromParts = (array) $query->getFrom();
     $fromHash = array_combine($fromParts, $fromParts);
     $aliases = $this->mapper->getEntitiesListAliases();
     $aliasesHash = array_flip($aliases);
     if (!isset($fromHash['*'])) {
         foreach ($fromParts as $part) {
             $entityName = $part;
             $isAlias = false;
             if (isset($aliasesHash[$part])) {
                 // find real name by alias
                 $entityName = $aliasesHash[$part];
                 $isAlias = true;
             }
             $mode = $this->mapper->getEntityModeConfig($entityName);
             $descendants = $this->mapper->getRegisteredDescendants($entityName);
             if (false !== $descendants) {
                 // add descendants to from clause
                 foreach ($descendants as $fromPart) {
                     if ($isAlias) {
                         $fromPart = $aliases[$fromPart];
                     }
                     if (!isset($fromHash[$fromPart])) {
                         $fromHash[$fromPart] = $fromPart;
                     }
                 }
             }
             if ($mode === Mode::ONLY_DESCENDANTS) {
                 unset($fromHash[$part]);
             }
         }
     }
     $collectedParts = array_values($fromHash);
     if ($collectedParts !== $fromParts) {
         $query->from($collectedParts);
     }
 }
 /**
  * Get array with mapped entities
  *
  * @return array
  */
 public function getEntitiesListAliases()
 {
     return $this->mapper->getEntitiesListAliases();
 }
Example #4
0
 public function testGetEntitiesListAliases()
 {
     $data = $this->mapper->getEntitiesListAliases();
     $this->assertEquals('test_product', $data[self::ENTITY_PRODUCT]);
 }
 public function testGetEntitiesListAliases()
 {
     $data = $this->mapper->getEntitiesListAliases();
     $this->assertEquals('test_product', $data['Oro\\Bundle\\SearchBundle\\Tests\\Unit\\Fixture\\Entity\\Product']);
 }