Problem/Motivation
user_role_change_permissions and user_role_revoke_permissions both take a role ID parameter, but don't validate that the role entity exists before atttempting to operate on it.
Steps to reproduce
Call user_role_revoke_permissions('fake-role-id', ['assign content']) in custom code
See that an error is thrown.
Proposed resolution
In the functions, check that the role exists.
Remaining tasks
Review the MR.
Merge if approved.
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3365626-5.patch | 1.38 KB | philipnorton42 |
Issue fork drupal-3365626
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
meanderix commentedComment #3
peri22 commentedIt works for me.
Comment #4
poker10 commentedThe fix looks good, thanks. Let's just add a test when using the
user_role_revoke_permissions()with non-existing rid.Comment #5
philipnorton42 commentedI came across this issue the other day and found this patch, worked for my situation.
Added the test to check that this patch fixes the issue.
Comment #7
poker10 commentedI think the failure is caused because of the patches order (which does matter here). The regular patch needs to be the last one to pass.
Anyway, I think the patch looks good, it has tests and the fix is the same as in
user_role_grant_permissions(). Thanks!Comment #8
smustgrave commentedHiding patches so hopefully when it retests it won't auto fail it.
Triggering a 11.x build.
Comment #9
smustgrave commentedPassed 11.x
And test-only patch of #5 shows the issue.
Comment #11
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #15
danielvezaThis seemed to be a problem in
user_role_change_permissions,user_role_grant_permissionsanduser_role_revoke_permissions.I've taken a slightly different approach of checking that the role entity can be loaded before doing anything. Added test coverage.
Comment #16
smustgrave commentedCan IS be cleaned up some please. What steps were being done to trigger this or was this just found in general? Proposed solution needs to be written out.
Comment #17
danielvezaComment #18
danielvezaIS updated, added the default template.
Comment #19
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #21
oily commentedFixed merge conflict. Fixed PHPSTAN. Test coverage is in place. Here is test-only output:
This looks good. Could this be close to RTBTC?
Comment #22
oily commentedComment #23
smustgrave commentedThink we should be logging an error if the role doesn't exist.
Comment #24
danielvezaI retained the existing behaviour of failing silently.
Maybe we should throw a
\LogicExceptionor\UnexpectedValueExceptionrather than logging.Comment #25
smustgrave commentedThat would work too +1
Comment #26
danielvezaTests are fixed for this.
Comment #27
phenaproximaReviewed. I found few minor points, and one probable flaw in the test coverage as written, which is why I felt this needs to be kicked back.
Comment #28
berdirI'm derailing this, but in the slack thread about this, we discussed that we need to find new places for all remaining functions in .module files anyway. It could be a new service with those methods ported 1:1, but I'm not sure it's really worth it. Using the entity API is not that much more complicated (we could add 1-2 helpers such as a a way to add multiple permissions, and then this would be the responsibility of the calling code to decide what to do in that situation.
Also, recipe config actions are kind of a replacement for this as well, think we should re-evaluate whether node_install() and media_install() should exist at all or if it should be the job of recipes and distributions to do this. There is after all a very long comment in node_install() why you shouldn't do that.