summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt2
-rw-r--r--includes/callback_node_access.inc44
-rw-r--r--search_api.module4
3 files changed, 26 insertions, 24 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 5cf8f49..2fdf834 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,5 +1,7 @@
Search API 1.0, dev (xx/xx/xxxx):
---------------------------------
+- #1324182 by dereine, drunken monkey: Fixed indexing author when node access is
+ enabled.
- #1215526 by cpliakas, drunken monkey: Added support for the "Bundle" facet
dependency plugin.
- #1337292 by drunken monkey: Fixed facet dependency system.
diff --git a/includes/callback_node_access.inc b/includes/callback_node_access.inc
index 002cc94..ce671d7 100644
--- a/includes/callback_node_access.inc
+++ b/includes/callback_node_access.inc
@@ -65,45 +65,45 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback {
$account = drupal_anonymous_user();
}
- if ($this->index->item_type == 'node') {
- // Load all notes as once.
- foreach ($items as $nid => &$item) {
- // Check whether all users have access to the node.
- if (!node_access('view', $item, $account)) {
- // Get node access grants.
- $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(':nid' => $item->nid));
+ foreach ($items as $nid => &$item) {
+ // Check whether all users have access to the node.
+ if (!node_access('view', $item, $account)) {
+ // Get node access grants.
+ $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(':nid' => $item->nid));
- // Store all grants together with it's realms in the item.
- foreach ($result as $grant) {
- if (!isset($items[$nid]->search_api_access_node)) {
- $items[$nid]->search_api_access_node = array();
- }
- $items[$nid]->search_api_access_node[] = "node_access_$grant->realm:$grant->gid";
+ // Store all grants together with it's realms in the item.
+ foreach ($result as $grant) {
+ if (!isset($items[$nid]->search_api_access_node)) {
+ $items[$nid]->search_api_access_node = array();
}
+ $items[$nid]->search_api_access_node[] = "node_access_$grant->realm:$grant->gid";
}
- else {
- // Add the generic view grant if we are not using node access or the
- // node is viewable by anonymous users.
- $items[$nid]->search_api_access_node = array('node_access__all');
- }
+ }
+ else {
+ // Add the generic view grant if we are not using node access or the
+ // node is viewable by anonymous users.
+ $items[$nid]->search_api_access_node = array('node_access__all');
}
}
}
/**
- * If the data alteration is being enabled, sets "Published" to "indexed".
+ * Submit callback for the configuration form.
+ *
+ * If the data alteration is being enabled, set "Published" and "Author" to
+ * "indexed", because both are needed for the node access filter.
*/
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
- parent::configurationFormSubmit($form, $values, $form_state);
-
$old_status = !empty($form_state['index']->options['data_alter_callbacks']['search_api_alter_node_access']['status']);
$new_status = !empty($form_state['values']['callbacks']['search_api_alter_node_access']['status']);
if (!$old_status && $new_status) {
$form_state['index']->options['fields']['status']['type'] = 'boolean';
+ $form_state['index']->options['fields']['author']['type'] = 'integer';
+ $form_state['index']->options['fields']['author']['entity_type'] = 'user';
}
- return $values;
+ return parent::configurationFormSubmit($form, $values, $form_state);
}
}
diff --git a/search_api.module b/search_api.module
index fe5c218..e1d7402 100644
--- a/search_api.module
+++ b/search_api.module
@@ -1307,7 +1307,7 @@ function search_api_search_api_query_alter(SearchApiQueryInterface $query) {
// Only add node access if the necessary fields are indexed in the index, and
// unless disabled explicitly by the query.
$fields = $index->options['fields'];
- if (!empty($fields['search_api_access_node']) && !empty($fields['status']) && !$query->getOption('search_api_bypass_access')) {
+ if (!empty($fields['search_api_access_node']) && !empty($fields['status']) && !empty($fields['author']) && !$query->getOption('search_api_bypass_access')) {
$account = $query->getOption('search_api_access_account', $GLOBALS['user']);
if (is_numeric($account)) {
$account = user_load($account);
@@ -1349,7 +1349,7 @@ function _search_api_query_add_node_access($account, SearchApiQueryInterface $qu
if (user_access('view own unpublished content')) {
$filter = $query->createFilter('OR');
$filter->condition('status', NODE_PUBLISHED);
- $filter->condition('uid', $account->uid);
+ $filter->condition('author', $account->uid);
$query->filter($filter);
}
else {