I have an index of nodes that I am faceting by taxonomy vocabulary Category.
I have a term in Category called 'members only' and I only let users with a role of member view content with that term, via hook_node_access.
Logged in as a member everything works correctly, but as an anonymous user I see the same facet options and result counts as the members see, despite that the search results themselves are correctly access controlled.

Do I need to write a custom Processor?

CommentFileSizeAuthor
#8 2942655.patch759 bytesborisson_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jody Lynn created an issue. See original summary.

borisson_’s picture

Issue tags: +Needs tests

This is a great question, we don't do any access control, and I don't think we should. But this is a great usecase that we should fix. Let's start by writing a test.

In theory this should just work, because we get the results form search api. I think that means this is a search api issue. However, I'm not sure. I'm hoping to see @drunken_monkey online soon. He might know more about this.

mkalkbrenner’s picture

In theory this should just work, because we get the results form search api. I think that means this is a search api issue.

Solr doesn't have any native concept to do that. And it would be very complex to implement something like this. I think the easiest solution would be to simply configure the facet block correctly. It should be shown to "members" only.

drunken monkey’s picture

In general, the Search API (any backend) will only return facet filter values that appear in the result set. (Except if the "Minimum count" is set to 0 – but that doesn't seem to be the cause here.)

It could just be a caching issue, I guess? Try clearing the whole cache (under Administration » Configuration » Development » Performance) and then right away viewing the search as an anonymous user (without visiting it as an admin/member in between). If the facets are correct (without "members only") then, it seems facet or block caching is interferring.

If that's not the problem, and unless something's going very wrong in the backend, it just seems like you haven't configured access control correctly for the search. Do you have the "Content access" processor enabled on the index? If not, enable it, re-index and then see whether the problem persists.
The search results probably seem correctly access-controlled because of the Views query plugin doing a manual extra "entity access" check on all results before viewing them. You can test that theory by temporarily disabling this in the view's "Query settings" ("Skip item access checks"). Also, if results are removed that way, paging will be incorrect (too few items per page, no results for the last pages, etc.) for anonymous users.

If the "Content access" processor is enabled but results still aren't properly access-checked (with "Skip item access checks" enabled), you might indeed need to write a custom processor to do the access checks for you. This should only happen if you're not using the default node access framework provided by Core, though.

I'm hoping to see @drunken_monkey online soon. He might know more about this.

Oh, sorry, since Chatzilla doesn't work anymore, I can't log in to IRC anymore. I guess I should register for Slack.

Solr doesn't have any native concept to do that. And it would be very complex to implement something like this. I think the easiest solution would be to simply configure the facet block correctly. It should be shown to "members" only.

As I understand it, the facets block should be shown to everyone, it's just that one facet value that shouldn't be. All other categories are open to anyone, so anonymous users should see that, too.

borisson_’s picture

Category: Feature request » Support request
Issue tags: -Needs tests

Removing needs tests and setting this to a support request.

Jody Lynn’s picture

Thank you @drunkenmonkey

I confirmed it is not caching related, I do have the content access processor on, and disabling the views entity access shows me that the content access processing is not working (and yes, paging is incorrect as well)

I am handing the access control via hook_node_access logic, not the node_access db table of grants. So I'm thinking I probably need to either change my access control logic or write a custom processor.

Jody Lynn’s picture

Ok, I switched from hook_node_access to hook_node_access_records/hook_node_grants and all is well.
Just the usual fun with having two different node access systems in core ;)

borisson_’s picture

Title: Facet results shown for inaccessible content » Add FAQ about Facet results shown for inaccessible content
Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Component: Code » Documentation
Category: Support request » Task
Status: Active » Needs review
FileSize
759 bytes

Ok, that's great, let's add this as an FAQ item in the readme, so that the next person running into this doesn't have the same problem.

borisson_’s picture

Status: Needs review » Fixed

Committed and pushed, more docs is great, thanks!

  • borisson_ committed f574502 on 8.x-1.x
    Issue #2942655 by borisson_, drunken monkey: Add FAQ about Facet results...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.