Hello,
our module, Access by Taxonomy, gives a user a way to set up viewing permissions for their content.
Upon install, taxonomy terms will have two new fields: allowed_users and allowed_roles. With these, one can specify the roles or users allowed to access any node tagged with the term.
We also add some permissions: "view any [content_type]". This is useful to give a certain role access to all the content regardless of the other rules. For example all editors can view all articles, despite some of the articles could be closed to administrators only.
This module is similar to permissions by term, but we use less hooks and make things work in a more streamlined way. Our module also works with translated content, while permissions by term does not support multilanguage.
We added a lot of Kernel tests to check that things work and to ensure the maintainability of the module.
Example of usage:
- create a tag "Premium users" and give the "Premium user" role to it. You can also specify an individual user (for example ,user ID 10).
- tag an article with "Premium users"
- only users with the "premium users" role are now allowed to view the article
- the user with ID 10 is allowed to view the article
- an editor (without "premium user" role) having the permission "view any article" can access the content
Thank you for reviewing this module! :)
Comments
Comment #2
vishal.kadamThank you for applying!
Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.
The important notes are the following.
phpcs --standard=Drupal,DrupalPracticeon the project, which alone fixes most of what reviewers would report.To the reviewers
Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.
The important notes are the following.
For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.
Comment #3
vishal.kadamComment #4
vishal.kadam1. FILE: README.md
The module uses a README.md file instead of a README.txt file. While the Drupal coding standards have not been yet updated about that, the Drupal.org community consider that positive.
Since there is a README.md file, that should follow the content and formatting described in README.md template.
2. FILE: access_by_taxonomy.info.yml
core_version_requirement: ^8 || ^9 || ^10The Drupal Core versions before 8.7.7 do not recognize the core_version_requirement key.
3. FILE: access_by_taxonomy.module
The usual description for a .module file is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.
The description for that hook should also say for which form that hook is implemented, either by indicating that with the name of the class that implements the form (namespace included) or the form ID (which is usually indicated by
getFormId()).4. FILE: src/AccessByTaxonomyPermissions.php
FILE: src/NodeAccessService.php
The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.
Comment #5
joey-santiago commentedThank you very much. Code updated.
I forgot to mention: if you go to our project code: https://git.drupalcode.org/project/access_by_taxonomy you'll see we have pipelines enabled, and everything is green.
Comment #6
joey-santiago commentedComment #7
vishal.kadamRest seems fine to me.
Let’s wait for other reviewers and Code Review Administrator to take a look and if everything goes fine, you will get the role.
Comment #8
joey-santiago commentedThank you very much! :) let's hope!
Comment #9
avpadernosrc/AccessByTaxonomyService.php
The first argument for logger methods that log a message is a literal string. Passing a dynamic string is considered a security issue.
$term = Term::load($tid);It is probably better to use the entity storage to load the taxonomy term, like already done from the code for other entities.
Since the class injected the translation manager, it should use that to get a translatable string instead of
t().Placeholders starting with a colon are for values that need to be filtered for dangerous protocols; that is not the case for numbers and entity IDs, which are supposed to be numbers.
Comment #10
joey-santiago commentedThank you very much for your review.
https://git.drupalcode.org/issue/access_by_taxonomy-3469105
i had already created this fork for working on the security fixes, so i went on on that. We'll merge that to the main branch soon.
I tackled all your points. Indeed many of them recurred in many places, but luckily our codebase is not too big to go through.
Comment #11
joey-santiago commentedComment #12
rushikesh raval commentedI am changing priority as per Issue priorities.
Comment #13
lostcarpark commentedI'm seeing a few issues, mostly pretty minor:
In
tests/src/FunctionalJavascript/FormAjaxTest.php, line 77:This creates the storage for the
field_tagsfield, but is never used again. There is no need to assign to the variable, you can just callFieldStorageConfig::create()as a method without assigning the result.On line 209 of the same file:
Normally I would expect this to be followed by
assertEqualsto check the expected text is in the element, but you don't do this, and the $txt variable is never used. If you just want to check the element exists on the page, you could change this to$this->assertSession()->elementExists().The next problem I've found is in
/src/NodeAccessService.phpon line 127:This should use
$this->t(). I see you're usingStringTranslationTraitin the class, which enables this but not actually availing of it.I note line 174 of the same file also uses
t(), but that's in a static function, where the $this variable isn't initialised, so it's correct.However, there are several static functions in this class, which leads me to wonder is this the best place for them, since they can't use injected dependencies. I wonder would it make sense to move some or all of them into a separate service?
I also note that this module doesn't currently have a Drupal 11 version. I don't think that's a reason it shouldn't opt in to the security policy, but it would definitely be a disincentive for people considering this module. Adding support for D11 shouldn't be difficult.
Comment #14
avpadernoComment #15
joey-santiago commentedComment #16
joey-santiago commentedThank you! Fixed those issues and also did the jump to d11.
That service that has static methods in it is mostly used for batch processing and so on, so i don't think it would make sense splitting it.
Comment #17
rushikesh raval commented1."main" is a wrong name for a branch. Release branch names always end with the literal .x as described in Release branches.
Comment #18
joey-santiago commentedBranch removed. It was only a stale branch, that likely was created by default on gitlab?
https://git.drupalcode.org/project/pathauto/-/branches
anyhow, i removed it.
Comment #19
joey-santiago commentedComment #20
klausimanual review:
access_by_taxonomy_schema(): please add a description the the database fields what the columns mean
AccessByTaxonomyService::getRoleGrant(): instead of using the for loop use fetchAllKeyed().
I did not fully test the access control logic, but from a visual code review it looks good.
Thanks for your contribution, Federico!
I updated your account so you can opt into security advisory coverage now.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on Slack or IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.