Problem/Motivation

At Netuxo we are currently working on a project of three parts, using DA. From any of these parts we need to be able to return search results from all three "domains". This feature existed in the (distant) past, but not for D8 (https://www.drupal.org/node/189797),

We asked agentrickard whether this feature was (ever) expected for D8, how it might be managed and how it would/could interact with the native search or Search API (eg for Solr) and he very kindly responded (next section, Proposed resolution).

This issue can be used to record our - and anyone else's - findings/offerings/queries, etc on this subject. Added as a feature request, but assigned to myself (since we intend to create this possibility, ideally in a module we can offer back).

Proposed resolution

NB Comments in this section are agentrickard's

The search feature worked well in Drupal 5 and 6 but was problematic in Drupal 7. I had not intended to repeat the same feature in Drupal 8, though I think you can achieve the same result in different ways.

What we did in earlier versions was store a duplicate of the _all_ grant in the {node_access} table, and for select pages we would give users that grant, which effectively disabled node access control.

This approach doesn't play well with how SOLR search indexes work. So your approach would largely depend on how you were handling search.

I can see a few options for how this might be handled.

1) If using SOLR or some external service with Search API, you can build search as a View. And Views have.a setting to disable node access (it's labelled "disable SQL rewrites" under the advanced options). This might pose a security issue if you have other advanced access control rules.

2) You could write a small custom module (domain_search) that gave a grant to view all domain content on specific pages. That would be fairly simple. If your team could write that, I could probably add it to the main module suite, since it's pretty simple to maintain.

Note also that commerce entities are not covered by node access.

It would be great if you wrote up your solution to the issue.

Feel free to open a GitHub or Drupal.org issue for this (and to paste this message in there, too).

Remaining tasks

To be defined in more detail, but broadly/initially:

  • Test both approaches;
  • Share outcomes;
  • Share any module created;
  • Document how we tackled this requirement;

Comments

ippy created an issue. See original summary.

agentrickard’s picture

So, what I'm thinking is a very small module that could handle just setting node grants on specific, potentially configurable pages.

The only real logic you need is as follows:

function domain_search_node_grants_alter(&$grants, \Drupal\Core\Session\AccountInterface $account, $op)) {
  // Only act on View.
  if ($op != 'view') {
    return;
  }
  // @TODO: code to generate the current page request path and check it against a whitelist.
  if ($allowed) {
    $domains = \Drupal::service('domain.loader')->loadMuitlple();
    foreach ($domains as $domain) { 
      $grants['domain_id'][] = $domain->getDomainId();
    }
      $grants['domain_id'] = array_unique($grants['domain_id']);
  }
}
agentrickard’s picture

Status: Active » Closed (won't fix)