Problem/Motivation
In a multilingual site I set content access to enable translation for Basic page and another content type called "Club".
Permissions for "Translate Basic page content" are set for administrator only.
I need an editor to be able to translate content type "club" so I set permission for editor to "Translate Club content".
Now I am facing two problems:
1. If I do not set the "Create translations" permission for editor, there is no local task for "Translate" when editor views a "Club" node.
2. If I do set the "Create translations" permission for editor, there is a local task for "Translate" and all works fine but this "Translate" local task is also showing on other content types (which are not configured for editor translations).
When editor clicks on "Translate" for other content types (like Basic page) he gets the translation table but not edit or add option i.e you cannot really translate.
Steps to reproduce
- Enable translation for 2 content types
- Create a role and give permission to translate 1 of them. Give the user permission to create/edit/delete translations
- When using that role visit a node of the other content type where you do not have translation permission.
- You will now see a translation tab there even if you don't have permission to translate into that entity. When you click on the translation tab you will see all translations listed, but you cannot perform any actions.
Proposed resolution
- Add check for bundle permission to function content_translation_translate_access
Remaining tasks
- Review patch
User interface changes
- Translation overview tab is only visible if user have necessary permissions to translate.
API changes
- None
Data model changes
- None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #69 | interdiff-3014209-58-69.txt | 2.54 KB | leolandotan |
| #69 | drupal-3014209-69.patch | 6.98 KB | leolandotan |
| #83 | drupal-3014209-83.patch | 31.9 KB | akhil babu |
| #83 | drupal-3014209-83-test-only.patch | 27.67 KB | akhil babu |
| #84 | interdiff-69-83.txt | 27.61 KB | akhil babu |
Issue fork drupal-3014209
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
taitai commentednone
Comment #3
taitai commentedComment #4
taitai commentedComment #5
matsbla commentedI can confirm this behavior. I guess it would make sense to only display the translation tab if you have translation access for the entity + have permission to preform some kind if translation action (create/edit/delete).
Comment #6
fabiansierra5191 commentedI add this patch, basically only check if the user can edit the entity if can't remove access to the translation overview page.
Comment #7
fabiansierra5191 commentedComment #8
fabiansierra5191 commentedComment #10
Erso commentedI have faced same issue.
Translate any node should be administer right and node based translation, translation edit and delete should be for only that node. (Need same permission options like node permissions. )
Comment #11
kmetzThe patch in #8 only works for tab display but not for action dropdown buttons on the content overview page.
I created a new patch that
Comment #12
kmetzCorrected paths in the #11 patch so it applies correctly.
Comment #13
Dirst commentedHi Guys. It is still the issue on drupal 8.9.x so Ill try to rewrite patch for it.
Comment #14
Dirst commentedIm changing the version to 8.9.x because this issue is out of date and patch needs re-roll
Comment #15
matsbla commentedHere is a new attempt.
We also need to check for 'translate any entity' permission.
I think we should check all bundle permissions inside content_translation_translate_access and remove it from ContentTranslationOverviewAccess.
We also need to fix some tests that are wrong, as they don't have bundle translation permissions + operation translation permissions, but still pass now.
The result can maybe be a little confusing to test manually as there is another related bug here: #2137815-55: InvalidArgumentException: Invalid translation language specified.. It always give users permission to create translations when they have 'translate any entity' permission. I've also uploading a patch for it there, as well as a combined patch for both of them to test here.
Comment #16
matsbla commentedComment #17
avpadernoComment #19
hardik_patel_12 commentedRe-roll for 9.1.x-dev.
Comment #20
avpadernoComment #22
masipila commentedHi all,
my use case is closely related to the one described in the issue summary but it's still slightly different.
In my setup, the users are allowed to translate nodes if (and only if) they are allowed to update the node. To determine who is allowed to update the node can obviously be done in many, many different ways.
I'm still on D8 but I believe the behavior is exactly the same as with 9.2.x-dev:
I don't want to introduce unnecessary scope creep to this issue, but what is ultimately the point of showing the Translate local task?
Currently access to the Translate local task is determined with this:
The proposed patch changes the logic so that we take the 'translate any entity' and the content type / bundle specific permissions into account. But we still show it if $entity->access('view'). Why view, why not update?
Cheers,
Markus
Comment #23
sutharsan commentedPatch #19 no longer applies.
Comment #24
kishor_kolekar commentedRe-roll for 9.2.x-dev.
Comment #26
kapilv commentedComment #27
avpadernoComment #28
kapilv commentedComment #29
avpadernoComment #30
msutharsComment #31
anmolgoyal74 commentedComment #33
msutharsFixed the test cases. Updated the patch.
Comment #34
msutharsComment #35
msutharsReroll the patch.
Comment #36
sutharsan commentedSome suggestions to improve the readability of the code.
Can be simplified into
$bundle_permission = $this->currentUser->hasPermission('translate any entity');No need to change the variable name
$tanslate_permission, use it instead of$bundle_permissionI think this change is not required for issue.
I think this change is not required for issue.
Comment #37
msutharsComment #38
msutharsComment #39
msutharsUpdated the patch as suggested in #36.
Comment #40
msutharsFixed the phplint issue. Updated the patch.
Comment #42
msutharsComment #43
michaellenahan commentedRemoving Europe2020 tag, since this issue was not worked on at Drupalcon Europe 2020.
Comment #44
michaellenahan commentedComment #45
michaellenahan commentedComment #46
tvb commentedIn a fresh Drupal 9.2.0-dev installation:
* Enable Content Translation module.
* Enable translation for Article and Basic page.
* Create an Article and a Basic page node in English.
* Add a second language.
* Create new role Editor and assign permissions.
* Create new user and assign Editor role.
* Log in as new user.
Permissions for Editor role:
* Create/Delete/Edit translations
* Translate Article content item
* Article: Create new content
* Article: Edit any content
Before applying the patch:
* Article content item: Translate tab is displayed; Edit and Add buttons are listed in the Operations column.
* Basic page content item: Translate tab is displayed; No Edit or Add buttons in Operations column.
The result so far reproduces what is described in the issue summary.
After applying the patch from #40:
* Article content item: Translate tab is displayed; the Add button in the Operations column has disappeared.
* Basic page content item: Translate tab is still displayed
Comment #47
masipila commentedRe: #46
I believe this is because the condition still starts as follows:
$condition = $entity instanceof ContentEntityInterface && $entity->access('view')...... Which is what I was trying to ask in #22 earlier.
I added the tag requesting for issue summary update. We have steps to reproduce and I believe everybody agrees that the current behavior doesn't make sense (that's why we have this issue to begin with). But can we please discuss and agree what the expected result is and then update it to the issue summary?
Markus
Comment #48
jcmartinezComment #49
matsbla commentedHere is an updated patch.
#22
No, we do not show it if $entity->access('view'), but we do not display it if not $entity->access('view'), meaning we do not show the translation tab if the user can't view the entity.
Comment #50
matsbla commentedComment #51
paulocsI'll review it.
Comment #52
avpadernoComment #53
paulocsHi everyone!
As @masipila said, I think we should update the issue summary with the expected behavior.
What I understand is that if a user has not the permission to translate a specific bundle, it should not be displayed the local task.
But as I tested patch #49, I gave the permission "Translate Article content item" and, in fact, it possible to translate it, but if I go to another content type node which I din't give the permission to translate it, it is possible to see also the 'Translate' local taks.
So moving to NW.
Comment #54
paulocsComment #55
matsbla commented@paulocs, #53
Can you please elaborate on what other permissions the user have? If the user have permission to edit the content, or "translate any entity" they will also be able to translate the content.
Comment #56
paulocsThe user which should not see the 'Translate' local task has permission to:
Create/edit/delete translations
Translate Article content item
View published content
When that user access a node from the content type 'Test', it is possible to see the 'Translate' local task.
I added a screen shot from the node that is not an Article.
The user has no permission to:
Translate Teste content item
Translate any entity
Edit the content
Comment #58
prudloff commentedI tested #49 with an user that has the following permissions:
And the Translate button is displayed for entities that the user can not edit (and so can not translate).
It seems to be caused by a grouping error in the condition.
This should be evaluated together:
So it only returns true if the user has one of these permissions and the bundle permission (or has
translate editable entitiesand can edit the entity).I updated the patch to add parentheses, however I think the condition could be refactored in order to make it easier to read and maintained.
Comment #59
avpadernoComment #60
matsbla commented@prudloff
Thank you for spotting that one!
Comment #61
guilhermevp commentedPatch #58 works as intended. Created a user with the same permissions pointed by the comment #58 and the user is only able to translate content that them are allowed to edit.
Result:
RTBC.
Comment #62
quietone commented@guilhermevp, not quite RTBC. It still needs an IS update.
This is tagged for an issue summary update. I suggest adding the template to the IS, update the proposed resolution and add the latest before and after screenshots to the IS.
Setting back to NW for that and leaving novice tag.
Comment #63
init90Comment #65
matsbla commentedUpdate issue summary
Comment #66
matsbla commentedComment #67
darvanenThis has become impossible to parse by eye. Please split up the logic into a few checks/sub-conditions (use the parentheses as a guide) and build $condition from those checks.
Also try to keep the code within the 80 char limit. This kind of brevity doesn't materially improve performance and greatly decreases our ability to understand what is intended. Use as many lines as you need to make it readable.
It *looks* to me like #22 should be covered by this but I can't quite tell right now.
Adding the permissions here doesn't test it in isolation, need to refactor the test to check all the various combinations of permissions that allow access here, suggest creating several users in the setup phase named to indicate their permissions combination, then testing the link against each one.
Same as 2.
Same as 2.
Same as 2.
A failing test-only patch would greatly help with future reviews.
Comment #68
leolandotan commentedI'll try to work on this one. Specifically the items mentioned by @darvanen. I may not be able to create a very good test though but I'll do my best on the tests.
Comment #69
leolandotan commentedI updated the condition as specified by @darvanen in #67 but I haven't been successful with the tests yet. Just adding my initial work here for additional review.
Comment #70
andypostThis change means more tests should be added, so more reviews are welcome
Comment #71
leolandotan commentedRemoving myself from the assigned field since I can't work on the tests at the moment.
Comment #72
darvanenThanks for the part you were able to do @leolandotan, it looks good to me.
Setting NW for #70 / #67.2-#67.5
Comment #76
akhil babuI have created a patch with required tests. Functional tests are successfully passed in local. But I could not test Functional javascript tests.
Comment #77
akhil babuTest only patch
Comment #78
akhil babuTypo correction
Comment #79
akhil babuComment #80
akhil babuPatch with fixes and tests.
Comment #81
akhil babuRemoving unused variable
Comment #82
akhil babuCorrecting the selector name in tests as per the failure in #81
Comment #83
akhil babuFixed FunctionalJavascript test logic
Comment #84
akhil babuComment #85
akhil babuPhew!
Comment #86
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Think this is very close!
For the ContentTranslationOperationsTest tests can we some additional assertions.
$node = $this->drupalCreateNode(['status' => FALSE, 'type' => 'article']);Think this should be $article_node
Then a basic_node should be created.
Then during each user test should make sure they do have access to things but think we should also check to make they don't have access to other things.
Example if I have access to all can we check both content types
If I have access to just articles can we check that and check I can't translate basic pages.
Comment #90
tohesi commentedRe-rolled for latest 10.1.x.
Comment #91
larskleiner commentedThe tests in #90 don't apply on Drupal 10.2.3, I removed them for now.
Comment #93
sakthi_dev commentedRe-rolled for latest 11.x.
Comment #95
kekkisComment #96
kekkisI am working on adding back the tests that were removed because they no longer applied in #91. I'm running into a problem where, in
core/modules/content_translation/tests/src/Functional/ContentTranslationContextualLinksTest.php, an operation is tried with an admin user on admin/config/regional/content-language but even though$this->drupalLogin($this->rootUser);has been run, the HTML output states that the user has no access to the page.I'm wondering whether the new Super user access policy could have something to do with this problem, but from what I've been able to deduce so far, the services.yml in use for these tests is the
default.services.ymlinsites/defaultand that has the policy set totrue, meaning UID 1 should still be all-powerful. I would be grateful for assistance as this is currently blocking me from advancing with the tests.Comment #97
rodrigoaguileraI don't think the remaining tasks in this issues are for novice folks
Comment #99
inaw commentedRe-rolled patch #93 for latest 11.4.x.