Layout builder fails to assign inline block access dependencies for the overrides section storage on entities with pending revisions

Created on 10 April 2019, about 5 years ago
Updated 15 April 2024, 2 months ago

Problem/Motivation

The SetInlineBlockDependency event subscriber fails to assign the correct access dependency to inline blocks when creating a pending revision of override section storage.

This creates a conflict between inline blocks, override layouts, paragraphs and content moderation, since the ERR formatter and paragraphs widget creates the following access dependency chain:

  1. Paragraphs entity checks host access (view/update).
  2. Inline block content checks the host, or "access dependency" for access.
  3. Node access should be granted, but the node is assigned to NULL, since the associated revision IDs are checked against the default entity, not the active entity.

Proposed resolution

For the purposes of access dependencies load the 'active' revision from the entity repository for the 'update' and 'delete' operation and load the canonical revision of the entity for all other operations.

Remaining tasks

Agree on an approach and tests.

User interface changes

None.

API changes

Method and constructor signatures only modified on @internal classes.

Data model changes

None.

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Layout builder 

Last updated about 2 hours ago

Created by

🇦🇺Australia Sam152

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Can the MR be updated for 10.1 please.
    Left some comments on the MR 1106 also.

    If we do end up changing the parameters for the eventSubscriber we will need a change record also.

    Hiding the files to avoid confusion as the solution is being worked on in the MR.

  • 🇺🇸United States DamienMcKenna NH, USA

    The merge request does not appear to work in the scenario where a media item is being added to a field in an inline block.

  • 🇺🇸United States DamienMcKenna NH, USA

    The problem is that this line does not work with future revisions:

          $layout_entity = $this->entityRepository->getActive($layout_entity_info->layout_entity_type, $layout_entity_info->layout_entity_id);
    

    We either need a different method to get the newest revision instead of the active revision, or pass the appropriate context definition to getActive() so it gets the correct revision.

  • 🇨🇭Switzerland phma Basel, CH

    I've run into a similar problem where the block_content entity has translations (because of core patch which adds symmetric translations to layouts). The media library widget was unable to update the media file once a translation was created. It would only work for the translation, but not the original language.

    Checking block usage with latest revision ID of the block_content entity won't work, because the section storage stores the latest translation affected revision ID in the layout. I'm not sure if this is a problem which should be taken into account here or solved elsewhere. But considering that layout_builder_st should at some point, it might be worth fixing it here.

    I've attached a patch which uses getLatestTranslationAffectedRevisionId on the entity storage to work around this (requires changes from the MR to be applied first). I can push it to the MR if this is useful, but since it needs entityTypeManager I wanted to check first if there is a better solution to the problem.

  • 🇺🇸United States bkosborne New Jersey, USA

    The merge request does not appear to work in the scenario where a media item is being added to a field in an inline block

    Could you elaborate or provide steps to reproduce?

    Unrelated, but after spending a lot of time reviewing this problem area, isn't the best solution here for layout builder to track what entity revision ID an inline block is attached to, instead of just its ID? If we had that in place, then there wouldn't be a need for us to have all this logic in place to check if we should be trying to load the canonical revision vs the active revision. We'd know exactly which revision to load. Maybe that's not compatible with translations or something?

    I guess that's a bit more complicated to accomplish and requires more refactoring though.

  • 🇺🇸United States bkosborne New Jersey, USA

    The problem is that this line does not work with future revisions:

    $layout_entity = $this->entityRepository->getActive($layout_entity_info->layout_entity_type, $layout_entity_info->layout_entity_id);
    

    We either need a different method to get the newest revision instead of the active revision, or pass the appropriate context definition to getActive() so it gets the correct revision.

    That code should be getting the latest revision. If you have a future revision, isn't that considered the latest revision? In what scenario is it not?

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    @bkosborne getActive will get the latest draft/translation - the naming isn't great, but the docs on the interface are good.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Rebased off 11.x

  • last update 12 months ago
    29,801 pass, 1 fail
  • First commit to issue fork.
  • last update 12 months ago
    29,805 pass
  • Status changed to Needs review 12 months ago
  • 🇮🇳India sakthi_dev

    As the view operation only assertTrue if the route has option "_layout_builder". So, the expected is to assertFalse for view and True for update and delete.
    @larowlan correct me if I'm wrong.
    Please review.

  • Status changed to Needs work 12 months ago
  • 🇺🇸United States smustgrave

    Not sure the change to false should be done. Seems like an odd test if you can update/delete but can't view.

  • 🇺🇸United States Luke.Leber Pennsylvania

    I believe this should be re-triaged as major, if not critical.

    Once content enters this state, it becomes impossible for content managers to update certain parts of it unless:

    1. The content is saved as a default revision
    2. The troublesome blocks are removed and replaced with new blocks end-user confirmed, but still data loss?

    https://www.drupal.org/project/drupal/issues/3053881 -- which I was also involved in -- was promoted to critical due to the same sort of potential for a "data-loss-like" condition.

  • 🇺🇸United States Luke.Leber Pennsylvania

    As a follow-up to my triage recommendation, this flaw can be reproduced via only core modules in common configurations.

    1. install layout builder, node, media, media library, and content moderation
    2. Add a block type with a media reference field, assigning the media library widget in the form display settings
    3. enable layout builder on the article content type and enroll it in content moderation
    4. Create a new node and edit the layout, adding an inline block that references a media item
    5. Save as draft
    6. Edit the inline block and attempt to swap out the media, notice that it fails with an AJAX error.
  • 🇺🇸United States Luke.Leber Pennsylvania

    The AJAX error contains...

    non-reusable blocks must set an access dependency for control

    when going to insert the new media.

  • 🇳🇿New Zealand John Pitcairn

    Yow. I can reproduce #98 as user 1 with full admin privileges.

    JS console error:
    ResponseText: {"message":"Non-reusable blocks must set an access dependency for access control."}

    Watchdog:

    Path: /media-library?destination=/node/4/layout&_wrapper_format=drupal_ajax&ajax_form=1&media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bimage%5D=image&media_library_selected_type=image&media_library_remaining=1&media_library_opener_parameters%5Bfield_widget_id%5D=field_image%3A-settings-block_form&media_library_opener_parameters%5Bentity_type_id%5D=block_content&media_library_opener_parameters%5Bbundle%5D=image&media_library_opener_parameters%5Bfield_name%5D=field_image&media_library_opener_parameters%5Bentity_id%5D=2&media_library_opener_parameters%5Brevision_id%5D=2&hash=RZpw_Ue-CORgfs34fAruBGXBLZUhx_qIoGwlq0UPRZU&views_display_id=widget&_wrapper_format=drupal_ajax.
    
    Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: Non-reusable blocks must set an access dependency for access control. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 118 of /var/www/html/public/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
  • 🇳🇿New Zealand John Pitcairn

    Current MR applies to 10.1.2 and fixes it. Not able to test in 11.x at present sorry.

  • First commit to issue fork.
  • Status changed to Needs review 8 months ago
  • 🇧🇬Bulgaria pfrenssen Sofia

    Addressed all remarks on the MR.

  • Pipeline finished with Success
    8 months ago
    Total: 794s
    #43532
  • Status changed to Needs work 8 months ago
  • 🇺🇸United States smustgrave

    Some small change requests. Also for the deprecation will need a change record and that link pasted into the deprecation messages.

    Thanks for picking this one back up!

  • 🇺🇸United States mikeryan Murphysboro, IL, USA

    Note that there are at least two contrib modules (just in our current project) that will need changes to avoid "Declaration must be compatible with Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency::getInlineBlockDependency(Drupal\block_content\BlockContentInterface $block_content, string $operation): ?Drupal\Core\Access\AccessibleInterface":

  • 🇪🇸Spain unstatu

    I have tested the latest version of the MR and it works well in Drupal 10.1.7

    Uploading the latest version of the MR in a patch.

  • 🇪🇸Spain unstatu

    Changed the version by mistake.

  • First commit to issue fork.
  • Pipeline finished with Canceled
    3 months ago
    Total: 22s
    #137177
  • Pipeline finished with Canceled
    3 months ago
    Total: 584s
    #137180
  • Pipeline finished with Failed
    3 months ago
    Total: 1193s
    #137191
  • Pipeline finished with Running
    3 months ago
    #137221
  • 🇨🇦Canada vincent signoret

    As mentioned in #106, I currently have an issue with:

    "Node access should be granted, but the node is assigned to NULL, since the associated revision IDs are checked against the default entity, not the active entity."

    I was able to reproduce the bug and the patch solved my issue on a vanilla install.

    However, on different projects where we are using the module Layout Builder Asymmetric Translation , we can't use this current patch.

  • Pipeline finished with Failed
    28 days ago
    Total: 200s
    #184839
Production build 0.69.0 2024