I use Domain Access to have a staging area for content before putting it live. My domain structure is as follows:

mydomain.com
staging.mydomain.com
subdomain.mydomain.com
staging.subdomain.mydomain.com

The staging domains are inactive, and are used to initially publish content to, from which it is later published to the main domains which are active.

When using the core search functionality, the search results return nodes that are in the inactive domains as well as the active domains. I'm searching with an anonymous user, who does not have permissions to access inactive domains. After clicking on the link of a search result of a node in an inactive staging domain, I get the "Access Denied" error as expected.

I am using the "Search all domains from any URL" advanced setting so I can search across all of my domains. If I change this to "Search content for the current domain only" it only shows results from the live domain I'm searching from, and no where else. Unfortunately, I'd like searches to reach across both of my active domains, but not the inactive domains (for those without appropriate permissions).

It would be great if there was another advanced setting regarding searching domains - something along the lines of a checkbox "Do not search inactive domains". Or maybe enabling the searching of node content on a domain by domain basis. Even only allowing users with the "Access inactive domains" permission to see the results of inactive domains in the search would suffice.

Thanks
K.

CommentFileSizeAuthor
#3 1362352-domain-search-broken.patch2.12 KBagentrickard

Comments

agentrickard’s picture

You can prevent this right now by selecting "Search content for the current domain only" from the settings page. If you are user 1 or can 'bypass node access', you may need to "Restrict node views for administrators" as well.

I agree, however, that we should filter these out.

agentrickard’s picture

Version: 7.x-2.16 » 7.x-3.x-dev
Category: feature » bug

In the 3.x branch, searching across all domains seems to be broken altogether.

agentrickard’s picture

StatusFileSize
new2.12 KB

I suspect that you only see search results because you are an administrator.

The attached patch "works", but cannot be committed, because if you have > 50 domains or so, the node access query will utterly break.

So the options seem to be:

  • Drop the "search all domains" feature.
  • Implement some extensive query-checking, similar to domain_alter_node_query() in order to support this logic.

The problem, for reference, is in SeachQuery::executeFirstPass


SELECT DISTINCT SUM(i.score * t.count) AS calculated_score FROM search_index i INNER JOIN node n ON n.nid = i.sid INNER JOIN search_total t ON i.word = t.word INNER JOIN node_access na ON na.nid = n.nid WHERE (n.status = '1') AND( (i.word = 'mos') )AND (i.type = 'node') AND(( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '0') AND (na.realm = 'domain_all') ))AND (na.grant_view >= '1') GROUP BY i.type, i.sid HAVING (COUNT(*) >= '1') ORDER BY calculated_score DESC LIMIT 1 OFFSET 0

Returns no results.

In Drupal 6, this didn't happen.

SELECT SUM(i.score * t.count) AS score FROM search_index i INNER JOIN search_total t ON i.word = t.word INNER JOIN node n ON n.nid = i.sid WHERE n.status = 1 AND (i.word = 'dolus') AND i.type = 'node' GROUP BY i.type, i.sid HAVING COUNT(*) >= 1 ORDER BY score DESC LIMIT 0, 1

The problem appears to be that node_access_view_all_nodes() is behaving differently in D7.

agentrickard’s picture

The problem seems to be in search.module.

It seems that search $query->executeFirstPass() ALWAYS filters for node access, even if node_access_view_all_nodes() returns TRUE

agentrickard’s picture

It seems that search $query->executeFirstPass() ALWAYS filters for node access, even if node_access_view_all_nodes() returns TRUE

agentrickard’s picture

agentrickard’s picture

And that core issue is bogus. This was entirely self inflicted. See #1396800: Special Page Requests not working

banoodle’s picture

Thank you, agentrickard for working on this issue.

I had the latest 7.x stable release of Domain Access installed and encountered this problem (search is not being restricted by domain even though it's enabled in advanced settings).

So I upgraded to the latest Dev release and applied the above patch. It didn't hurt anything, but it didn't solve my issue.

I'm just using core drupal search right now: do I maybe need to reindex the site for this to work? Or maybe I need to install Search API?

Any advice greatly appreciated. If I can't get this approach to work, I'm contemplating trying this recipe:

http://www.metaltoad.com/blog/drupal-solr-search-domain-access-filtering

Anne

agentrickard’s picture

First, make sure you aren't testing as an administrator (user 1) or someone with the 'Bypass node access' permission.

banoodle’s picture

Yeah -- I'm definitely not authenticated when I'm testing this (though I have been known to make this mistake ; )

kenorb’s picture

Status: Active » Needs review
bluegeek9’s picture

Status: Needs review » Closed (outdated)

Drupal 7 in End of Life and no longer supported. We encourage you to upgrade to a supported version of Drupal. For more information, see https://www.drupal.org/upgrade.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.