Problem/Motivation
When an unpublished translation is added to a node, grants are removed from the database. This way no one can access the published original translation
Steps to reproduce
create an entity with translatable status field. No need to do any settings on the PbT side.
1: create a published node
2: save an unpublished translation
3: access is now impossible
This happens because somehow the grant hook is called with the delete flag and the grants to be saved for the node are now an empty array. I think the module doesn't take into account other translations of the node when it is saved?
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2024-06-12_09-13.png | 44.72 KB | hkirsman |
| #26 | permissions_by_term-3308318-26.patch | 12.54 KB | hkirsman |
| #25 | interdiff_19_25.txt | 3.62 KB | hkirsman |
| #25 | permissions_by_term-3308318-25.patch | 14.31 KB | hkirsman |
| #25 | 2024-06-11_16-57.png | 134.19 KB | hkirsman |
Issue fork permissions_by_term-3308318
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
jepster_Thanks for creating this issue here. This issue is resolved in version 3.1.19. See release notes: https://www.drupal.org/project/permissions_by_term/releases/3.1.19
Comment #3
damienmckennaComment #5
joey-santiago commentedSorry, it doesn't work for me...
What i'm doing is:
The problem is every time the unpublished translation is saved, i also lose access to the original node and also the node_access table contents are removed.
Can you please reopen this, or should i create a new issue?
Comment #6
joey-santiago commentedConfirm, i find this problem on 3.1.19 as well.
When an unpublished translation is saved, a call to NodeGrantDatabaseStorage::write with the delete flag on is launched, as expected, but the execution stops there, because the module doesn't return any grants i guess?
Now i finally get what happens.
When a published node is saved, the node type is handled by Pbt and the node has no terms associated with it, PbT returns NULL from permissions_by_term_node_access_records, but core has this:
so in this case we're saved by core: PbT doesn't want to do anything with that node and returns NULL, but we should indeed do something with it. When an unpublished translation is saved, then the node is not published and nothing is inserted for us.
Comment #7
joey-santiago commentedThis seems to fix the issue for me.
I can share with you the DrupalPod environment where i have the patch if you want to test it. Please, let me know if i can help in any way.
Comment #10
joey-santiago commentedRight. That was not the right way to go. We want to add the default grant instead of the ones checked by PbT.
Comment #14
joey-santiago commented... And finally, found another case in which instead of returning NULL, we should return the default grants.
Comment #15
joey-santiago commentedAlso added some tests for this.
Comment #16
jepster_Since joey-santiago worked on this issue after it was closed, I am re-opening it and I am asking for review. I will come back to this, when I will have some time for this. Sorry, I am quite busy now.
Comment #17
joey-santiago commentedComing back to this. We noticed that the patch works indeed for that case, but doesn't cover this:
in this case the patch only sets the default access, thus opening the node's permissions. Working on a fix.
Comment #18
joey-santiago commentedReworked the patch and confirmed tests are now passing. I plan on adding a couple tests for the case that we noticed failing, it will come next week.
Comment #19
joey-santiago commentedHere are some more tests. I really think @peter-majmesku some effort should be put into making the module reliable with multilanguage installs.
I had a bit of troubles understanding how the permission_mode should work, but i hope i got it right.
thanks
Comment #20
hkirsman commentedWhat would be needed to test the correct branch? There's only 8.x-1.x available here.
Comment #21
hkirsman commentedpermissions_by_term-3308318-18.patch and permissions_by_term-3308318-19.patch introduced new bug where node is suddenly accessible by anonymous users, permissions_by_term-3308318-10.patch seems to work. I'm new to to this so I thought I'd first start with fixing tests for the permissions_by_term-3308318-10.patch. Does that make sense? If that's ok, then maybe keep it for what was meant to be fixed in permissions_by_term-3308318-19.patch
Comment #22
alaa abbad commentedReroll the patch to ensure compatibility with the most recent version.
Comment #23
hkirsman commentedStatus check. So there's merge request and patches in this issue. The new defaultGrants() method in MR and in permissions_by_term-3308318-10.patch is exactly the same. Patch permissions_by_term-3308318-18.patch already has more logic in it. Latest patches from @joey-santiago were
permissions_by_term-3308318-18.patch and permissions_by_term-3308318-19.patch
Interdiff between them is:
So more tests were added as was said in https://www.drupal.org/project/permissions_by_term/issues/3308318#commen...
I'm a afraid my comment and patch in #21 might have been kind of incorrect as this is also related to https://www.drupal.org/project/drupal/issues/962664
I would say permissions_by_term-3308318-19.patch is the last correct patch for PbT 3.1.19 and Drupal core 9.
Problem is that the patch still fails. I would assume it was working in some env but what am I missing...
Comment #24
hkirsman commentedOk, I think I get it now. The patch was only tested with the test that was updated, but not whole permissions_by_term test set. tests/src/Kernel/NodeAccessRecordsTest.php works just fine. There's still this but it's minor code change where roles are created to add human readable label:
Role label is expected to be a string.Comment #25
hkirsman commentedGot tests working on Permissions by Term version 3.1.19, Drupal core 9.3.22 (could have been probably 9.5.x). Next up is to update againast latest version of PbT and maybe Drupal 10.2
Comment #26
hkirsman commentedI could not create interdiff for some reason, but it the new patch should be correct. I've tested this on permissions_by_term 3.1.33 and core 10.2.7
Comment #27
hkirsman commentedComment #28
hkirsman commentedThis is also issue for testing:
