diff --git a/file_entity.module b/file_entity.module index 229617f..53ee333 100644 --- a/file_entity.module +++ b/file_entity.module @@ -1748,7 +1748,7 @@ function file_entity_query_file_access_alter(QueryAlterableInterface $query) { * access conditions are added for field values belonging to files only. */ function file_entity_query_entity_field_access_alter(QueryAlterableInterface $query) { - _file_entity_query_file_entity_access_alter($query, 'entity'); + //_file_entity_query_file_entity_access_alter($query, 'entity'); } /** @@ -1847,42 +1847,42 @@ function _file_entity_query_file_entity_access_alter($query, $type) { foreach ($tables as $falias => $tableinfo) { $table = $tableinfo['table']; if (!($table instanceof SelectQueryInterface) && $table == $base_table) { + $subquery = db_select('file_managed', 'fm_access')->fields('fm_access', array('fid')); + + // Add any applicable access conditions. + // if (!user_access('view own private files')) { + // $subquery->condition("fm_access.uri", db_like('private://') . '%', 'LIKE'); + // $subquery->condition("fm_access.uid", $user->uid, '<>'); + // } + // elseif (!user_access('view own files')) { + // $subquery->condition("fm_access.uid", $user->uid, '<>'); + // } + + foreach (array_keys(file_entity_get_hidden_stream_wrappers()) as $name) { + $subquery->condition("fm_access.uri", $name . '%', 'NOT LIKE'); + } + + $field = 'fid'; // Now handle entities. if ($type == 'entity') { // Set a common alias for entities. $base_alias = $falias; + $field = 'entity_id'; } + $subquery->where("$falias.$field = fm_access.fid"); - if ($base_table != 'file_managed') { - $field = 'fid'; - // Now handle entities. - if ($type == 'entity') { - // Set a common alias for entities. - $base_alias = $falias; - $field = 'entity_id'; - } - $file_managed_alias = $query->join('file_managed', 'fm', "fm.fid = $falias.$field"); + // For an entity query, attach the subquery to entity conditions. + if ($type == 'entity') { + $file_conditions->exists($subquery); } + // Otherwise attach it to the node query itself. else { - $file_managed_alias = $falias; + $query->exists($subquery); } } } - // Add any applicable access conditions. - if (user_access('view own files')) { - $file_conditions->condition("$file_managed_alias.uid", $user->uid, '='); - } - elseif (user_access('view own private files')) { - $file_conditions->condition("$file_managed_alias.uri", db_like('private://') . '%', 'LIKE'); - $file_conditions->condition("$file_managed_alias.uid", $user->uid, '='); - } - - foreach (array_keys(file_entity_get_hidden_stream_wrappers()) as $name) { - $file_conditions->condition("$file_managed_alias.uri", $name . '%', 'NOT LIKE'); - } - - if ($type == 'entity') { + if ($type == 'entity' && count($subquery->conditions())) { // All the file access conditions are only for field values belonging to // files. $file_conditions->condition("$base_alias.entity_type", 'file'); @@ -1894,9 +1894,6 @@ function _file_entity_query_file_entity_access_alter($query, $type) { // Add the compiled set of rules to the query. $query->condition($or); } - else { - $query->condition($file_conditions); - } } /**