Problem/Motivation

The parent issue #2809291: Add "edit block $type" permissions was Fixed even though some of the "Remaining tasks" in the issue summary were still pending.

Proposed resolution

  1. Allow users with the create $type block content permission to create blocks via /block/add route as per #2809291-106: Add "edit block $type" permissions
  2. Update the permissions callback to add dependency information. See the change record Permissions can define dependencies.
  3. Enable the "Manage Permissions" tab. See the change record Add "Manage permissions" tab after "Manage display"

Remaining tasks

User interface changes

API changes

None

Data model changes

None

Release notes snippet

N/A

Issue fork drupal-3315042

Command icon 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

benjifisher created an issue. See original summary.

benjifisher’s picture

Issue summary: View changes

It looks as though (2) from the issue description was already done on the parent issue, just not checked off the list.

In Drupal\block_content\BlockContentType, I see

  public function blockTypePermissions() {
    return $this->generatePermissions(BlockContentType::loadMultiple(), [$this, 'buildPermissions']);
  }

as recommended in the change record.

I also tested:

  1. Install Drupal with the current 10.1.x and the demo_umami profile.
  2. On /en/admin/people/permissions/module/block_content, grant all "edit block type" permissions to the Editor role.
  3. Use /en/admin/config/development/configuration/single/export to inspect the dependencies for the role.

The dependencies were added.

benjifisher’s picture

The "Manage Permissions" tab was added in #3253955: Let modules opt in to the bundle-specific permissions form. But when that issue was fixed, there were no per-block-type permissions from the block_content module. There might be such permissions from other modules, such as Configuration Translation or Layout Builder. Since there may or may not be per-block-type permissions, the BlockContentType entity specifies an access check to avoid allowing access to an empty page, or generating links to it.

The change record explains how to handle this: specify one of two route providers in the entity annotations, depending on whether the check is needed. I have made the required change in the MR for this issue.

benjifisher’s picture

Assigned: benjifisher » Unassigned
Status: Active » Needs review

Item (1) from the issue description relates to the "create block $type" permissions. Some patches on the parent issue added these permissions, but the final version does not. The create permissions were moved to a child issue (sibling of this one): #3213736: Add "create block $type" permissions.

Again, the task should have been removed from the list in the issue summary of the parent issue.

I have addressed all three items, so this issue is now ready for review.

benjifisher’s picture

P.S. I copied some comments from the parent issue to #3213736: Add "create block $type" permissions.

aaronmchale’s picture

Status: Needs review » Reviewed & tested by the community

Did some manual testing, in short:

  • Standard 10.1.x install, created an extra block type called "Test" (Standard comes with "Basic block" already), and 1 content editor user.
  • Created two custom blocks, one of each type, placed them in the "Hero" section of Olivero.
  • Confirmed that by default Content Editor cannot edit either block.
  • Gave Content Editor the "edit any block" for my "Test" block type.
  • Confirmed that Content Editor can access block/2 (type: Test) but importantly not block/1 (type: Basic block).
  • After applying the MR to my local install, confirmed that permissions still behave as described.

As a sort of sanity check, I also tested adding and remove the Administer Block permission to Content Editor, and everything behaved as expected. I also noted that adding the Administer Block permission was the only way to get the contextual links to appear, even though Content Editor could edit the "Test" block, I had to navigate directly to block/2 in order to edit it, there was no intuitive way to access this page from the site front-end.

So while functionally everything works as expected, from a UX perspective I'd say that's a fundamental problem. That said, that is something which is not in the scope of this issue, so I'm happy to mark this issue as RTBC.

benjifisher’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new62.16 KB

AaronMcHale:

Thanks for testing. Did you also review the +1/-1 change in the MR?

Please re-test the contextual links. In the Standard profile, the Content Editor role already has permission to use contextual links. That and permission to edit Test blocks should be enough, and it works as expected in my testing:

screenshot showing two custom blocks, with the contextual link for one of them

It is also listed as one of the "completed tasks" on the parent issue. (Search that issue for "contextual".)

Also, you tested the functionality of the parent issue, but you did not test the change made in this one, which affects access to the Permissions form (tab, local task) for the block types.

  1. A user with the "administer permissions" permission should have access to Manage Permissions: /admin/structure/block/block-content/manage/basic/permissions.
  2. That page should appear as a tab (local task) on the block-type page.
  3. Links to the permissions forms should be available in the Operations column of /admin/structure/block/block-content/types.

All of that should function the same with or without the change in this issue. The change here is to skip the unnecessary test that there is at least one permission to manage. Maybe the easiest way to test that is to hack Drupal\user\Form\EntityPermissionsForm::access() so that it always returns AccessResult::forbidden(). With 10.1.x, even the administrator role cannot access the permissions form. With the patch, anyone with the "administer permissions" permission should have access.

In my testing, all of that works.

Back to NR.

aaronmchale’s picture

Status: Needs review » Reviewed & tested by the community

Did you also review the +1/-1 change in the MR?

Yes, that was what my manual testing centred around, essentially validating what the behaviour is in HEAD and then confirming that after applying the MR, there is no regressions; And so, as far as I could tell, the change in the MR did not result in any regression.

Please re-test the contextual links. In the Standard profile, the Content Editor role already has permission to use contextual links. That and permission to edit Test blocks should be enough, and it works as expected in my testing

I just tested again, inspected the source code, and confirmed that the contextual links are actually there, I just wasn't initially seeing them, perhaps because of where I positioned the block and that it only has one word in it, so the "hit box" is quite short. Regardless I do now see the contextual links for the blocks for which the content editor user has permission to edit.

Maybe the easiest way to test that is to hack Drupal\user\Form\EntityPermissionsForm::access() so that it always returns AccessResult::forbidden(). With 10.1.x, even the administrator role cannot access the permissions form. With the patch, anyone with the "administer permissions" permission should have access.

Can confirm that I can also replicate that, and everything there works as expected.

So looks like RTBC again.

  • catch committed 6c6f7ad on 10.1.x
    Issue #3315042 by benjifisher, AaronMcHale: Remaining tasks for "edit...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Took me a minute to realise the patch doesn't actually fix 2/3 bullets in the issue summary because they were already fixed in the parent issue, but it's all in the comments and patch ended up being trivial. Committed 6c6f7ad and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.