Problem/Motivation

We currently have granular inline block permissions in Drupal, allowing to precisely set which custom block bundles can be created / edited by which user role. Unfortunately, restricting access to certain custom block types doesn't work in Layout Builder that allows to add / edit all or nothing within a layout by design.

Proposed resolution

  1. Add a new permission create and edit accessible custom blocks.
  2. Restrict custom blocks list in LB to only those accessible ones for users having only that permission and not create and edit custom blocks
  3. Alter LB block add, edit and delete route access basing on custom block permissions for the current user and the old / new permission.
  4. (Of course) Add automated test coverage.
  5. Create a follow-up to remove the old permission and make LB always respect block access logic or at least mark the old permission with restrict access: true

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3041174

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

tim.plunkett created an issue. See original summary.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

benjifisher’s picture

I think it would be disruptive to change things so that the current LB permission is no longer enough to create and edit inline blocks (of any type). If we were going to do that, we should have done it when the new block permissions were added, in 10.1.0. Now I think the right thing to do is to add a new permission that needs one of the more granular block permissions to be useful.

Currently, in layout_builder.permissions.yml:

create and edit custom blocks:
  title: 'Create and edit content blocks'
  description: 'Manage the single-use blocks within the Layout Builder'

I think we can tweak the description: change "the" to "all".

The new permission would be something like

create and edit certain custom blocks:
  title: 'Create and edit certain content blocks'
  description: 'Use Layout Builder to manage single-use blocks that the user can add or edit'

In the description, I am trying to be consistent with the labels of some existing LB permissions, like "Content - Article: Configure layout overrides for content items that the user can edit".

_utsavsharma’s picture

Status: Active » Needs review
StatusFileSize
new830 bytes
new830 bytes

Tried to address the #10.

benjifisher’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

@_utsavsharma :

Thanks for starting this issue.

We should keep the old permission and add a new one. The patch in #11 replaces the old permission with a new one.

Once we have the permission, we will have to update the access controls so that the permission does what it says. That will be the hard part of this issue.

We also need to expand the issue summary. So far, it is just a stub.

graber’s picture

No point having 2 permissions ultimately since the old one will allow bypassing access of granular block permissions. I was thinking maybe a follow-up with an update hook in the next major to leave only 1 permission so site owners will not end up not having access unexpectedly until they update to that next major with a CR of course?

graber’s picture

Assigned: Unassigned » graber

Also.. I'll work on it.

graber’s picture

Issue summary: View changes

graber’s picture

Added some initial work on this. Definitely needs more work.

graber’s picture

Assigned: graber » Unassigned
Status: Needs work » Needs review

Passing to the first review and testing.

graber’s picture

Thank you for checking this Alec! Included your remarks except those about catching exceptions. I think if any of those exceptions happen, it indicates a serious issue with the project that should be caught on a local / dev environment or as early as possible in any case (invalid custom code or data corruption) and not allowed to stay there much longer and eventually be noticed resulting in a completely different bug.

Just to be sure, I checked other calls of those methods in the module - they are not wrapped in a try-catch anywhere so those exceptions would be thrown elsewhere anyway. Setting those threads as resolved.

graber’s picture

Single test fail completely unrelated: Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLinkabilityTest. OK, all green again.

plach’s picture

@Graber

Could you please add some details to the IS Problems/Motivations section?

graber’s picture

Issue summary: View changes
graber’s picture

Thank you for checking this @plach, all resolved, if you have concerns about the Kernel test, please provide more details, I don't think we need to go for a functional in such a simple case and at a big performance cost. Layout Builder tests are very heavy already :(

plach’s picture

Looks good to me, I'll manually test this for a while and then report back.

smustgrave’s picture

Issue summary appears to have been updated previously.

Tested locally the new permission and an editor role. Things appear to be working as expected but will leave in review for more eyes +1

alecsmrekar’s picture

Most entity types rely on an "update" operation instead of the "edit" operation. Paragraphs will check the "update" operation on it's parent entity. If the parent entity is a block, we'll need to convert "update" to "edit".

Here's a proposal for changing getBundlePermission:

  public static function getBundlePermission(string $block_bundle, string $operation): string {
    if ($operation === 'create') {
      return 'create ' . $block_bundle . ' block content';
    }
    elseif ($operation === 'update') {
      $operation = 'edit';
    }
    return $operation . ' any ' . $block_bundle . ' block content';
  }
smustgrave’s picture

Status: Needs review » Needs work

To try out #26

graber’s picture

@alecsmrekar feel free to commit that, it'll be your change after all :)

dburiak made their first commit to this issue’s fork.

dburiak changed the visibility of the branch 3041174-adjust-layout-builder to hidden.

dburiak’s picture

Status: Needs work » Needs review

Combined the changes from MR!6125 and #26 to MR!8743.
The MR!6125 is hidden as redundant.

smustgrave’s picture

Status: Needs review » Needs work

If we are changing solution issue summary should be updated.

6125 was passing the pipeline but new MR is not so moving to NW for that.

dburiak’s picture

Status: Needs work » Needs review

The #26 doesn't change the solution; it is just an adjustment.
The MR!8743 is updated to pass the code styles check. Please review.

smustgrave’s picture

Status: Needs review » Needs work

@dburiak mind rebasing

matthiasm11’s picture

StatusFileSize
new109.1 KB

Works fine on D10. Adding a dedicated patch file for D10.
The merge request should still be rebased for D11.

dburiak’s picture

The MR is rebased. Review is needed.

dburiak’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new5.43 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.

dburiak’s picture

The code style is fixed.

dburiak’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

matthiasm11’s picture

Status: Needs work » Needs review
StatusFileSize
new24.78 KB

Rebasing MR8743 gave too much errors, fixing it became a lot of work.
I've created a clean new merge request, starting from a fresh 11.x.

Attached a static D11 patch file.

matthiasm11 changed the visibility of the branch 3041174-adjust-layout-builder-operation to hidden.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The 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.

dench0’s picture

Version: 11.x-dev » 11.3.x-dev
dench0’s picture

StatusFileSize
new12.57 KB

11.3.1 patch

dench0’s picture

StatusFileSize
new24.38 KB

Fixed D11.3.1 patch

quietone’s picture

Version: 11.3.x-dev » 11.x-dev

Hi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.