"unpublished nodes" don't show up on node/%node/translate for users where uid ≠ 0 as soon as modules are installed that implement hook_node_grants
I spent quite a while looking into what causes this issue, and succesfully reproduced it on a clean install of 7.14 and 7.x-dev.
These are the steps to reproduce:
- perform a fresh install of Drupal 7.14
- Enable locale and content_translation modules- Give "authenticated user" the following permissions:
-- create/edit own/delete own content for Basic Page
-- translate content
-- view own published content- For the basic page content type, enable Multilingual support: " Enabled, with translation"
- in "Regional and languages", add a language (I added Dutch (NL))
- Create a new user johndoe
- Log in as johndoe
- Create a basic page in the default language (EN)
- Go to the translate tab of that page and add a Dutch translation
- Go to the translate tab from the translation. Remember what you see.- Log back in as admin
- Unpublish the original node (node/1)
- Log back in as johndoe
- Check the translate tab on node/1/translate and node/2/translate. Everything looks normal.
- Logged in as admin again, enable any module that implements hook_node_grants (e.g.: content_access, og_access, nodeaccess_userreference, ..)
- Rebuild node access
- Log back in as johndoe
- Check the translate tab on node/1/translate and node/2/translate. What the @é$%! Why does English appear "not translated" ?
=> THE PROBLEM: our unpublished translations won't appear any more- Disable any modules that implement hook_node_grants, recheck the page.. Everything back to normal.
A little background info (from my point of view, might be completely wrong)
in translation.module, translation_node_get_translations() adds a node_access tag.
This will be handled in node.module by _node_query_node_access_alter(). Here the simple query get extra conditions added . This is no problem at all, but one of the last lines of code $subquery->where("$nalias.$field = na.nid");
seems to suggest that a node must always have an entry in the node_access table, which seems not to be the case?
Comment | File | Size | Author |
---|---|---|---|
#3 | 1673794-unpublished-access-to-translations.patch | 855 bytes | agentrickard |
Comments
Comment #1
agentrickardWhat module are you using that applies hook_node_grants()?
Comment #2
agentrickardThere are a couple of issues here, including the fact that a node access query cannot account for the "view own unpublished nodes" permission. That has to be fixed by looping through and checking node_access() on each node.
Comment #3
agentrickardHere is one potential solution, which I just discussed with @xjm.
You cannot actually use a query to determine who can view these nodes, precisely because of the "view unpublished." (Side note: the proper behavior of hook_node_access_records() is to store $node->status in the grant_view column.)
So this patch moves the node access check out of the query and to the foreach loop, which should fix your issue. However, the Translate tab will vanish if ou cannot view any of the translations -- and it is also possible that certain languages will vanish if the user has no permission. We might want to clean that up as well.
Comment #4
agentrickardThis will need to be fixed in Drupal 8 first. Tagging for translation team.
Comment #5
kupide CreditAttribution: kupide commented#2 works for me. Thx !!
Comment #5.0
kupide CreditAttribution: kupide commentedadded: "as soon as modules are installed that implement hook_node_grants" for clarity
Comment #6
alansaviolobo CreditAttribution: alansaviolobo commentedComment #8
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #9
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #10
bogdan.racz CreditAttribution: bogdan.racz at Dream Production commentedI wasn't able to replicate the problem, with the steps above, event though they we're specified for Drupal 7.
I guess it needs an issue update, or simply close it.
Comment #11
rv0 CreditAttribution: rv0 commentedIf the issue isn't there in D8, shouldn't it be set to D7 again instead of closing it?
Comment #13
hitesh-jain CreditAttribution: hitesh-jain at Acquia commentedComment #14
hitesh-jain CreditAttribution: hitesh-jain at Acquia commentedComment #15
flyke CreditAttribution: flyke commentedI have this problem on a Drupal 8.2.3 site.
- site with 3 languages, and 2 users with the role 'content editor'
- content editor 1 creates a node (in default language) and saves it as unpublished
- content editor 2 can edit the node but cannot translate it (translate tab is missing and translate option is also missing from the operations in the backoffice node overview page).
- If content editor 1 or 2 publish the node, then content editor 2 can translate it
- so now the node is in default language (1), and also succesful translated to language 2
- most weird part: if you unpublish language 1, and then try to add a translation via language 2, you get an access denied error
So in short:
problem 1: non admin user cannot translate unpublished content
problem 2: non admin user cannot translate a node if the source node is unpublished
For reference: the permissions of my content editor role:
NO: Administer translation settings
YES: Create translations
YES: Delete translations
YES: Edit translations
YES: Translate any entity
YES: Translate Basic page content
(the testing above is from nodes of the type basic page)
Comment #17
anish.a CreditAttribution: anish.a at Axelerant commentedThis needs testing and have to know the steps to reproduce. I am not sure if the issue is relevant anymore.
Comment #23
weseze CreditAttribution: weseze as a volunteer commentedStill relevant in latest 8.9.
Comment #28
quietone CreditAttribution: quietone at PreviousNext commentedThis was a bugsmash daily target yestersay. Lendude responded saying that they are currently "working on a site that uses node grants a LOT and also uses translations for all content types, this is not an issue". That sites does "use content moderation, so ‘unpublished’ becomes a bit more vague". They looked at the D7 and D8 code and determined that this is a “different nid for a translation” problem. And concluding this issue belongs in Drupal 7.
They also pointed out that the problem in #15, is a different problem and perhaps needs a separate issue. For that, I tested on Drupal 10.1.x, standard install. I was not able to follow the second step. "content editor 1 creates a node (in default language) and saves it as unpublished'. The content editor does not have permission to set the content as unpublished.
This is summarized into two problems in that comment.
And I found that not to be true. A non admin user can translate unpublished content if it is their own content. And I deleted the first language and the author, a content editor, was able to add a translation in the second language without error.
All together, I think this is working as designed. If I am wrong, open a new issue and provide steps to reproduce.
I am moving this to Drupal 7.