Unless I'm missing something, the way this module currently works is that when a file is indexed, no access field is set on the file entity, meaning that a user who can access the parent node, will not see content in the indexed file in search results.

For example, if I have a node titled 'foo', with an attachment that contains the word 'bar' (in the text only, not in the title), when an administrator searches for 'bar', they will see the file entity, but when a normal user, with access to the 'foo' node searches for 'bar', they get no results, since the file entity is indexed without an access field.

Looking at apachesolr_attachments_solr_document(), some care is taken to add data from the parent entity, so I wonder if this would be the appropriate place to add access information?

Comments

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new811 bytes

I grabbed the logic in the attached patch from the apachesolr_index_entity_to_documents() function, and this resolves the issue I was seeing since the apachesolr_access hook gets invoked.

nick_vh’s picture

Hmm, that is weird - this adds more stuff to the document? Not exactly the thing we'd want?

nick_vh’s picture

Status: Needs review » Needs work
jhedstrom’s picture

I don't understand why it "isn't the thing we'd want". Without those access parameters attached to the document (as apachesolr_access module adds them to node entities), only super-users can view these documents in the index.

grzesiek_k’s picture

I have the same problem - files search results from the .pdf are visible only for the admin user. Is there any proper solution for that problem ?

dan_lennox’s picture

I had this same issue and the patch in #1 by jhedstrom fixed this nicely. Thanks!!

I think Nick_vh is just talking about the appropriateness of your comments in the patch?

awnage’s picture

This fixed the issue for me as well. Thank you so much jhedstrom!

morenstrat’s picture

Patch in #1 works for me, too.

thsutton’s picture

Status: Needs work » Needs review

Works for me.

Maybe @Nick_vh could provide some information about what's wrong with it? Is it the possibility of other fields, not just the access field, being added to the document by implementations of that hook?

jvandooren’s picture

The patched worked in my case too...

Thank you!

jessehs’s picture

Re-roll of #1 to work with apachesolr_attachments-7.x-1.3.

haydeniv’s picture

Status: Needs review » Reviewed & tested by the community

I just tested this on my site and it works well with the current patch.

pwolanin’s picture

It would be nice to have some better code comments at least. I don't love that we're invoking this general hook when we just want to hit apachesolr_access, but on the other hand, I'm not sure it makes sense to hard-code that one call either.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

As a short-term fix I'd prefer something more targeted like:


// Add node access grants from the parent node to the file so that files
// are appropriately shown or filtered out of search results based on whether
// the user can access the node they are attached to.
if ($parent_entity_type == 'node' && function_exists('apachesolr_access_apachesolr_index_document_build_node')) {
  apachesolr_access_apachesolr_index_document_build_node($filedocument, $parent_entity, $env_id);
}

star-szr’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.04 KB

Here's #14 as a patch (just tweaked the comment wrapping to fit within 80 chars). I just re-indexed and tested and it works well for our use case. Thanks @pwolanin!

somebodysysop’s picture

I had the same problem attachment search results not displaying for non-administrator users, and I applied the patch in #15 to latest .dev and it did fix that problem. Now, non-administrator users can see search results for attachments to nodes to which they have access.

However, what if files divided into public and private fields? Just because a user has access to a node may not mean he necessarily will have access to the private file field within the node. Which means that in addition to the user's access to the parent node, we also need to check his access to the file field within the node.

If apachesolr_access was doing that, then this patch breaks it. If it wasn't, then we need further code to check access to the field that the file is attached to within the node.

Any suggestions on how to approach this?

somebodysysop’s picture

I figured that I could implement my own access control for files as the search results are displayed. The hook to use to process apachesolr search results: hook_apachesolr_process_results()

michaellenahan’s picture

I applied #15 and after a reindex the permissions are working correctly for us.

haydeniv’s picture

Status: Needs review » Reviewed & tested by the community

So I think we can call this RTBC unless we need to add some tests to this.

haydeniv’s picture

Hiding the old patches.

pwolanin’s picture

Title: File entities should use parent entity's access setting if the apachesolr_access module is enabled » Index file entities be with access grants from parent node if the apachesolr_access module is enabled
Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committing to 7.x-1.x

Should be backported, ideally.

  • pwolanin committed 129fbc8 on 7.x-1.x
    Issue #1782936 by jhedstrom, jessehs, Cottser: Index file entities be...