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?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | apachesolr_attachments-1782936-15.patch | 1.04 KB | star-szr |
Comments
Comment #1
jhedstromI 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.
Comment #2
nick_vhHmm, that is weird - this adds more stuff to the document? Not exactly the thing we'd want?
Comment #3
nick_vhComment #4
jhedstromI 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.
Comment #5
grzesiek_k commentedI 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 ?
Comment #6
dan_lennox commentedI 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?
Comment #7
awnage commentedThis fixed the issue for me as well. Thank you so much jhedstrom!
Comment #8
morenstratPatch in #1 works for me, too.
Comment #9
thsutton commentedWorks 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?
Comment #10
jvandooren commentedThe patched worked in my case too...
Thank you!
Comment #11
jessehsRe-roll of #1 to work with apachesolr_attachments-7.x-1.3.
Comment #12
haydeniv commentedI just tested this on my site and it works well with the current patch.
Comment #13
pwolanin commentedIt 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.
Comment #14
pwolanin commentedAs a short-term fix I'd prefer something more targeted like:
Comment #15
star-szrHere'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!
Comment #16
somebodysysop commentedI 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?
Comment #17
somebodysysop commentedI 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()
Comment #18
michaellenahan commentedI applied #15 and after a reindex the permissions are working correctly for us.
Comment #19
haydeniv commentedSo I think we can call this RTBC unless we need to add some tests to this.
Comment #20
haydeniv commentedHiding the old patches.
Comment #21
pwolanin commentedCommitting to 7.x-1.x
Should be backported, ideally.