Problem/Motivation
#3394741: BlockContentAccessControlHandler requires access block library permission for update, delete and revisions operations solved block access for update and delete but not create. The title left out "create" but several comments say that it works. Why as create left out? Hopefully this was just an oversight :)
Steps to reproduce
- Install Drupal with the standard profile
- Add a role that has
create any basic block contentpermission - Login as a user with the above role
- Visit /block/add/basic
- Get a 403
- Logout
- Log back in as an admin
- Grant the above role the "access block library" permission
- Logout
- Log back in as the user with the above role
- Visit /block/add/basic
- Get a 200, i.e the add form for a block
It should not be necessary to grant access to the block library in order to create a block content entity.
Proposed resolution
Change checkCreateAccess() to only check for 'create' and not 'access block library'.
Remaining tasks
Commit
Release note snippet
The "Access the Content blocks overview page" permission is no longer required to create blocks. This means that roles that have "Create new content block" permission for a given block type will be able to create these blocks when they could not in previous releases. Site owners should audit their Block Content permissions to ensure that block creation access is granted intentionally in all cases, and can also now consider revoking access to the content block overview listing for roles that do not need it.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3412420
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
douggreen commentedComment #3
douggreen commentedPatch attached
Comment #4
douggreen commentedComment #5
douggreen commentedComment #6
smustgrave commentedRecommend turning to an MR.
Will say believe this was done on purpose because of a layout builder scenario.
Comment #7
douggreen commentedMR created.
In reply to the comment by @smustgrave that this was possibly done on purpose because of a layout builder scenario, that isn't mentioned at all in the original ticket. And this very problem here was mentioned there.
Comment #8
smustgrave commentedDon't see an MR
Changing version to current development branch.
Will ask one of the other block_content maintainers.
If something that is changed will require a test assertion somewhere.
Comment #9
douggreen commentedMR created now, previously I'd just created the fork.
Comment #11
acbramley commentedTests need fixing.
Also correcting permission in IS and hiding the patch.
Comment #12
prashant.cI was able to reproduce the issue with the steps mentioned in the issue summary and the code changes fixes the issue and it working as expected for the users with permission to
Create new content block.Can we add tests for this in this file
/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.phpitself?Thanks
Comment #15
acbramley commentedI think tests in BlockContentAccessHandlerTest should be sufficient. I've rebased the MR against 11.x.
I think this makes sense from an API perspective we don't need to restrict the creation of entities based on a permission that is UI based.
Comment #16
acbramley commentedPushing this one along.
Comment #17
smustgrave commentedRan test only feature here https://git.drupalcode.org/issue/drupal-3412420/-/jobs/1790698 to show test coverage.
Trying to think of a scenario where this could be a BC concern but imagine if a site gave an editor this permission they also gave them 'access block library'
Comment #18
xjmI'm not sure if this is the correct fix. It might actually have been intended that you have access with any of the three permissions, i.e.:
So the question is, does having access to the block library mean that you should also be able to create blocks, or is there a usecase for being able to access the block library but not being able to create blocks? We should get subsystem maintainer feedback on whether there's usecases for accessing the block library without being able to create 'em. (Because like... I don't think there is...?)
EDIT: Removed the bit about the previous issue; I failed to read the explanation in #7 properly.
If what I suspect is true and "Access block library" should also grant permission to create them, then the correct fix is instead to OR together all three permissions equally, and correct the test accordingly.
Regardless of which fix we end up with, this is a disruptive change, because it changes which permissions people have to configure and what access site users get as a result. So, it will need a CR and a release note.
Thanks everyone!
Comment #19
xjmSaving credits.
Comment #20
xjmOh one other thing; we should also get Layout Builder subsystem maintainer review on this to make sure we're not breaking some sort of access assumptions there.
Comment #21
acbramley commentedNo, it should not. Changing this would grant access to users that previously could not create blocks. I do not see any reason to open these permissions up.
This issue is about removing the need for accessing the block library in order to create blocks for all the same reasons already discussed in #3394741: BlockContentAccessControlHandler requires access block library permission for update, delete and revisions operations - there are use cases where roles should be able to be setup where they cannot access the block library, but should be able to create blocks.
This has minimal interaction with Layout builder apart from allowing users to create reusable blocks without having access to the block library.
layout_builder_block_content_accessalready grants access to inline blocks irrespective of any of these permissions (it uses its owncreate and edit custom blockspermission).Added CR and release note.
Comment #22
xjmStill need that feedback specifically confirmed by an LB maintainer though. Thanks!
Comment #23
larowlanNot a layout builder subsystem maintainer, but framework manager opinion - this was an oversight from #3394741: BlockContentAccessControlHandler requires access block library permission for update, delete and revisions operations, which itself was an oversight from #1984588: Add Block Content revision UI and filed almost straight after that went in by @jenlampton.
Confirming that
\Drupal\layout_builder\Controller\ChooseBlockController::inlineBlockListdoes not consider create access when dealing with inline blocks.Comment #24
acbramley commentedBack to RTBC then. Thanks @larowlan.
Comment #25
xjmSo... what is the point of accessing the block library if you can't create block instances? What would you even use it for? Sorry, I'm still not understanding something or confused about something here.
Comment #26
larowlan@xjm - you might be able to edit blocks, but not create them. The block library has operations links for each block. But regardless, this isn't changing that - this is removing the need to access the block library in order to create inline blocks.
i.e this change allows a site to provide a link to create a new block, but without needing to give the user access to the block library.
In a node analogy, allowing the user to create a basic page without giving them access to admin/content.
Comment #27
xjm@larowlan I agree with fixing it so that the "create" permission alone is sufficient to create. What I'm still stuck on is how the block library is useful without the permission to create, because as far as I know, every block instance placed from the library is a new one. Maybe I'm conflating two different things. Maybe manual testing steps for using the block library before-and-after would help. I'll try to get to this later.
Actually, that made me realize that the change hasn't had any documented manual testing of the main issue with block creation either (oops!). #12 is not sufficient evidence of manual testing, unfortunately. Documenting specific STR with manual testing will make it easer for confused reviewers like myself to get to the same page. :)
Comment #28
xjmWorking on the manual testing now.
Comment #29
xjmSo turns out I was conflating block instances with content blocks, and the block plugin modal that you get when you click the "Place block" link at
/admin/structure/blockwith the block library at/admin/content/block. Both places have the "Add content block" button, but they are completely different UIs. My mistake!It turns out there are issues with the "access block library" permission, but they exist without this patch as well. Manual testing steps.
/admin/content/block, click "Add content block"./admin/people/create, create a test user that only has the "authenticated user" role./admin/people/permissions/authenticated, grant authenticated users only the "Access the Content blocks overview page" permission./admin/content/block.admin/structure/block, click the "Place block" button in the Header region, and place an instance of the test block from step 3./admin/content/block./admin/content/blockand click the link for the test block. The link actually takes you to the edit page, not the view page (there is no standalone "view" page for a content block apparently), which is why it 403s for the test user./admin/people/permissions/authenticated, grant authenticated users only the "Basic block: Edit content block" permission./admin/content/block. Clicking on the link for the block now works and takes you to the edit form as expected.Repeating the above steps with the patch, there is no change. Edit: However, if the steps are repeated with Views and Views UI uninstalled, the block title is correctly displayed with no link. So it's actually an issue with the block library view, not the entity collection itself.
So if you don't have permission to edit a block, the link in the block library should be rendered as plain text instead. But that's out of scope here since it's an existing problem without the patch.
In
BlockContentAccessControlHandler::checkAccess(), it looks like the intention was for "access block library" to give you permission to view the blocks even if they were unpublished, but there's actually no such thing as an unpublished content block, so that is also weird. You'd have to alter the entity type's base fields for that code to do anything.Still need that manual testing for the actual case of creating the content blocks (with exact steps to reproduce like I've given above for testing the access content library permission).
Comment #30
xjmFleshed out the release note a bit to describe the action site owners should take, including the UI label for the permission since it's very different from the machine name.
The fact that this grants access that previously was (incorrectly) denied means it's a minor-only change, so should only be committed to 11.x at this point. One of the first issues for the 11.1.0 release notes, but not the first.
Comment #31
xjmComment #32
xjmAlso expanded the CR to be more clear about the actions a site owner should take, and corrected the target branch to be 11.1.x. (10.4.x is a maintenance minor, so would not generally receive disruptive bugfixes like this one.)
Comment #33
xjmComment #34
xjmFiled the followup: #3455803: Block library view links to the edit page for each content block even when the user does not have edit access
Comment #35
acbramley commentedUpdating steps to reproduce.
Comment #36
smustgrave commentedWith the MR applied I followed the steps in the issue summary having an editor role with only
create any basic block contentpermission and I was able to create a block now.Since no code change the test-only run is still there https://git.drupalcode.org/issue/drupal-3412420/-/jobs/1790698
Believe this is good.
Comment #38
alexpottCommitted 6ef6a00 and pushed to 11.x. Thanks!
Only committing to 11.x as per the CR. I'd be in main to commit this to 11.0.x and 10.4.x but the CR stops me from doing that. And I don;t feel this bug fix is urgent.
Comment #39
acbramley commentedWhat do you mean by this?
Comment #40
xjm@acbramley I assume it was a typo or just an incomplete thought about decision factors. In this case, a release manager's decision in #30 and #32 that this is too disruptive for a maintenance minor is what stops it from being backported to 10.4. Edit: To clarify, the release manager (me) altered the change record (CR) with an update about its allowed versions as well as a tag indicating which minor release should mention the change, and I believe @alexpott referenced those changes in his decision. I think that's what the comment means.
11.1 and 10.4 ship at the same time, but 10.4 is supposed to have very limited changes per the maintenance minor docs. But this is the first time we've ever had a maintenance minor and so the committers haven't established a detailed policy yet; we'll learn as we go, just like we did each previous time we improved the release cycle. :)
Edit: To frame it a little better, I'm advising the absolute minimum of backports to 10.4 that are strictly necessary to meet the stated maintenance requirements, and relying on contrib to let us know if/when/how badly we break their compatibility between 11.1 and 10.4. We can always backport stuff later if we identify the need, but reverting loads of stuff is much more difficult.