Provide custom content block create/edit permissions

Created on 27 May 2024, 8 months ago
Updated 11 June 2024, 7 months ago

Problem/Motivation

If a user does not have permission to create a content block, they are still able to insert it into the editor. They can select it and insert it into the page, but no fields for the edit form show up in the editor, just a submit button and it appears broken.

The same goes for editing.

Example: A user without block permission creates a node, an editor with block permission edits that node, inserting a content block the first user does not have permission to edit. If the first user goes back in to edit that node, they should not be able to edit that block.

Furthermore, if a node is submitted without editing the form (which you cant do since its not there) no contentBlockId is created and a PHP warning is shown Warning: Undefined array key "contentBlockId" in Drupal\gutenberg\ContentBlocksHandler->Drupal\gutenberg\{closure}() (line 87 of modules/contrib/gutenberg/src/ContentBlocksHandler.php).

Digging into this, I see that we are checking for 'create and edit custom blocks' as a permission to show the form. This permission is provided by layout_builder which may not necessarily be installed (In my case it wasn't).

Proposed resolution

This module should provide its own permission. Something like 'gutenberg create and edit custom block_content' or 'gutenberg create and edit custom BLOCKTYPE block content' if we want to restrict by type.

We should also hide the submit button and show a warning where the form would be, if the user does not have permission.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @loze
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    Digging into this, I see that we are checking for 'create and edit custom blocks' as a permission to show the form.
    This permission is provided by layout_builder which may not necessarily be installed (In my case is wasn't).

    This module should either provided its own permission 'gutenberg create and edit custom block_content' ?
    or possibly check the $block->access('update') on the individual block.

  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • Pipeline finished with Success
    8 months ago
    Total: 392s
    #183695
  • Pipeline finished with Success
    8 months ago
    Total: 220s
    #183704
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    My MR does the following:

    • adds the permission 'create and edit custom gutenberg content blocks' for all content block types in the editor so it does not need ot rely on the layout_builder permission
    • Shows a warning message to the user if they do not have permission
    • removes the submit button on the form if they do not have permission
    • Gets rid of the error messages if they submit the node with no contentBlockId
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • Pipeline finished with Success
    8 months ago
    Total: 246s
    #183873
  • Status changed to Fixed 8 months ago
  • πŸ‡΅πŸ‡ΉPortugal marcofernandes

    This is awesome! Thank you @loze.

  • Pipeline finished with Failed
    8 months ago
    Total: 1148s
    #185984
  • Pipeline finished with Success
    8 months ago
    Total: 1161s
    #186071
  • Pipeline finished with Skipped
    8 months ago
    #186103
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Success
    7 months ago
    Total: 140s
    #210816
  • Pipeline finished with Success
    6 months ago
    Total: 180s
    #222106
  • Pipeline finished with Success
    6 months ago
    #230283
  • Pipeline finished with Success
    6 months ago
    Total: 142s
    #240541
  • Pipeline finished with Success
    6 months ago
    Total: 121s
    #240550
  • Pipeline finished with Success
    6 months ago
    Total: 133s
    #240552
  • Pipeline finished with Success
    5 months ago
    Total: 335s
    #246636
  • Pipeline finished with Success
    5 months ago
    Total: 312s
    #246638
  • Pipeline finished with Skipped
    5 months ago
    #246734
  • Pipeline finished with Success
    5 months ago
    Total: 131s
    #254108
  • Pipeline finished with Success
    5 months ago
    Total: 133s
    #269526
  • Pipeline finished with Failed
    4 months ago
    Total: 143s
    #277170
  • Pipeline finished with Failed
    4 months ago
    Total: 14949s
    #277287
  • Pipeline finished with Failed
    4 months ago
    Total: 233s
    #277870
  • Pipeline finished with Failed
    4 months ago
    Total: 170s
    #277902
  • Pipeline finished with Success
    4 months ago
    Total: 186s
    #277910
  • Pipeline finished with Failed
    4 months ago
    Total: 271s
    #280722
  • Pipeline finished with Success
    4 months ago
    #281007
  • Pipeline finished with Failed
    4 months ago
    Total: 243s
    #282088
  • Pipeline finished with Success
    4 months ago
    Total: 151s
    #282092
  • Pipeline finished with Success
    4 months ago
    Total: 190s
    #283206
  • Pipeline finished with Success
    4 months ago
    Total: 186s
    #283281
  • Pipeline finished with Failed
    4 months ago
    #283890
  • Pipeline finished with Failed
    4 months ago
    Total: 191s
    #283900
  • Pipeline finished with Failed
    4 months ago
    Total: 190s
    #283903
  • Pipeline finished with Success
    4 months ago
    Total: 411s
    #283904
  • Pipeline finished with Success
    4 months ago
    Total: 144s
    #285285
  • Pipeline finished with Success
    4 months ago
    #285294
  • Pipeline finished with Success
    4 months ago
    Total: 148s
    #285297
  • Pipeline finished with Success
    4 months ago
    Total: 130s
    #291477
  • Pipeline finished with Success
    4 months ago
    Total: 130s
    #291504
  • Pipeline finished with Success
    4 months ago
    Total: 121s
    #291508
  • Pipeline finished with Success
    4 months ago
    Total: 126s
    #291538
  • Pipeline finished with Success
    4 months ago
    Total: 134s
    #292165
  • Pipeline finished with Canceled
    4 months ago
    Total: 580s
    #293260
  • Pipeline finished with Success
    4 months ago
    Total: 617s
    #293278
  • Pipeline finished with Failed
    3 months ago
    Total: 671s
    #304365
  • Pipeline finished with Success
    3 months ago
    Total: 235s
    #304437
  • Pipeline finished with Failed
    3 months ago
    Total: 208s
    #321736
  • Pipeline finished with Failed
    3 months ago
    Total: 358s
    #321738
  • Pipeline finished with Skipped
    3 months ago
    #324410
  • Pipeline finished with Skipped
    3 months ago
    #325419
  • Pipeline finished with Canceled
    2 months ago
    #331158
  • Pipeline finished with Success
    about 2 months ago
    Total: 208s
    #346002
  • Pipeline finished with Success
    about 2 months ago
    Total: 205s
    #346052
  • Pipeline finished with Success
    about 2 months ago
    Total: 215s
    #346062
  • Pipeline finished with Success
    about 2 months ago
    Total: 404s
    #346071
  • Pipeline finished with Success
    about 2 months ago
    Total: 304s
    #346079
  • Pipeline finished with Success
    about 2 months ago
    Total: 233s
    #346090
  • Pipeline finished with Success
    about 2 months ago
    Total: 208s
    #346119
  • Pipeline finished with Skipped
    about 1 month ago
    #364200
Production build 0.71.5 2024