Original summary
Thanks for this needed module!
I needed to restrict select permissions (but not view permissions) on vocabularies per user role. Ex
Vocab 1 (all can view, only role 1 can select)
Vocab 2 (all can view, only role 2 can select)Patch attached. If its outside the scope of this module, I can release separately with a dependency.
Remaining tasks
- Review
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3110558-25.patch | 82.39 KB | feyp |
| #25 | 3110558-25-tests-only.patch | 65.43 KB | feyp |
| #25 | interdiff-3110558-23-25.txt | 846 bytes | feyp |
Issue fork taxonomy_access_fix-3110558
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:
- 3110558-add-a-select-terms-permission
changes, plain diff MR !4
Comments
Comment #2
el1_1el commentedThe prior patch did not account for views entity references. This one does
Comment #3
el1_1el commentedaand i overthought the last one and messed up simple use cases. maybe 3rd time
Comment #4
feyp commentedThank you very much for your patch. Unfortunately, due to some unexpected circumstances, I have been away since January and didn't have time to look at this in depth, yet. Also, it might take some more time until I can actually look at this. Just some general remarks for now, to give you a heads up:
Let me know, if you would like to do this. If you feel uncomfortable writing tests or an upgrade path, you could start by just porting the patch to 8.x-3.x and then maybe someone else from the community could add the test coverage and/or the upgrade path. Once you have a patch for 8.x-3.x ready, I'll be happy to review it as soon as possible and give you more detailed feedback. Should you instead decide to release a separate module, please post a link to the module here, so that users interested in this feature will be able to find it.
Comment #5
el1_1el commentedWith the complete rewrite from 2x-3x and without the static method call for access in hook_options_list_alter, it seems the view permissions are interfering with the select permissions and one could theoretically want to select but not view also. So I ended up forking from 2.7 to https://www.drupal.org/project/taxonomy_access_select which is only for that one permission.
I may work more on a patch for this module if there is interest, but this was a simpler solution for now.
Comment #6
shortspoken commentedThanks for the module!
I have a similar problem to solve: we have unpublished terms and a non-admin user should be able to select those terms without giving the permission to "Administer Taxonomy".
Therefore the following permissions would be helpful:
The code I am refering to is located here:
\Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection::getReferenceableEntities()Comment #7
feyp commentedComment #8
feyp commentedAttached is a patch against 4.x-dev that introduces 4 new permissions:
The patch will replace the default entity reference selection plugin for Taxonomy terms with an extended version that requires the above permissions. This allows users to just (un-)install the module and instantly switch on/off the new permissions without the need to reconfigure entity reference fields.
The patch also adds an update path that grants the permission to select published terms to all roles with the permission to view published terms, which would have been required to do this previously.
Comment #10
shortspoken commentedThanks @FeyP!
I did a functionality test with the following permissions:
and it works as expected. :)
Appreciate your work!
Comment #11
shortspoken commentedComment #12
feyp commentedThis is not ready. The patch doesn't apply against the current 4.x-dev. It needs a reroll.
Comment #14
technoveltyco commentedI re-rolled a new patch 3110558-13.patch against the latest 4.x-dev. It is the same implementation of the patch 3110558-08.patch in #8.
The code is also available in the branch 3110558-add-a-select-terms-permission of the issue fork.
I used this simpletest.me instance https://master-lfne2jk9mqututivivrssptrv3mpgvgo.tugboatqa.com for testing the patch in D9.3, if you want to try it out.
Comment #15
technoveltyco commentedComment #18
technoveltyco commentedI've re-rolled the faulty patch in #14 and attaching the new one in 3110558-18.patch.
This patch fixes all the automated tests including all the select term permission asserts, and also refactor the functional update test to check the schema updates 9401 for view term label per VOCABULARY, and 9402 for the select term per VOCABULARY.
The patch is also available in the merge request 3110558-add-a-select-terms-permission of the issue fork.
Comment #19
technoveltyco commentedComment #20
dunx commentedWe have tested https://www.drupal.org/project/taxonomy_access_fix/issues/3110558#commen... and this works for us.
Can this be merged?
Comment #21
feyp commentedThanks for working on the reroll @technoveltyco. It is much appreciated.
@dunx
At some point this will be merged, it is on my todo list. I just need to get to it ;). Originally I planned to work on Drupal 10 compatibility before getting back to this, but since we now have a reroll, I think we'll get this in first and then look at Drupal 10 compatibility so that we don#t need another reroll.
Thanks for testing the MR/patch and reporting back in this issue that it works for you. This definitely helps to build confidence that we have a solid solution. What we still need is a review of the code and especially the test coverage. Since we're dealing with permissions and access checks we can't be too careful ;). I'll do a final review myself before I commit this, but it helps to get the issue merged faster, if other users will do a code review. Except for the test coverage, where it is easy to introduce some copy/paste error and perpetuate a bug, which in this case could have security implications, I'd be interested in opinions whether my design decision to replace the default handler is a good idea or if there would be a better approach.
So ultimately, we need to get this issue to RTBC status. If no other community members will do the review, I will at some point still review this, but it might take longer.
Comment #22
feyp commentedThanks for the re-roll. I now had a chance to review this more closely. It looks good in general, but there are some things we can improve.
I think we can simplify this. The new code for the select operation would also work for the view operation. So we can use that for both operations and just have an else for the "view label" operation.
You added this block to the beginning of the
foreachloop forTest the per vocabulary 'select terms in' permission.inTermAccessTest. This is correct, but we need to add the same check for the other newly added select term permissions tested further down.This error was already present in the original patch. The permission name should be
'select any unpublished term'.Coder doesn't like these class names.
I think we can just get the expected schema from the available schemas now, so we can probably remove the 2nd parameter.
I think we can move this out of the loop, should be okay to just assert this once.
Thanks for replacing this deprecated code. However,
KernelTestBasehas a methodgetModulePath()that we can use here as a replacement, so no need to get theextension.path.resolverservice.The previous patch had a change to
.info.yml, which is lost in the new patch:I don't remember now why it was needed, but I've certainly done that for a reason, so I think we need to add this again.
The re-roll also introduces some white space changes Coder doesn't like that we need to fix.
I'll work on a new patch.
Comment #23
feyp commentedAttached is a new patch that addresses #22.
Comment #25
feyp commentedJust did another full review of the code and I found one other thing we should address. There's a place in
TermSelectAccessTestwhere we're testing that permissions without access to select terms can't select any terms. We should have added the new view term names permissions there with the re-roll and then the reorder permission was also missing there. So let's add those. Didn't find anything else.Comment #27
feyp commentedI have done a final review in #25 and did some manual testing on Drupal 9.4.5 and it looks like everything still works as intended. Given that the main part of the functionality (the replacement of the TermSelection plugin) hasn't changed since the original patch and the feature was tested successfully by @shortspoken and @dunx, I'll mark this as RTBC.
Comment #29
feyp commentedCommitted. Thanks all!