Problem/Motivation

The paragraph type module creates permission records for each paragraph type.
This spams the admin permission UI.

Proposed resolution

The module should create a setting per paragraph type to enable permissions on a type.
Only then, a permission record should be created.

As this module is stable, an update hook should enable the setting for all existing paragraph types.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork paragraphs-2879350

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

miro_dietiker created an issue. See original summary.

thenchev’s picture

Assigned: Unassigned » thenchev

I can take a stab at this.

thenchev’s picture

Status: Active » Needs review
StatusFileSize
new4.08 KB

Here is a preliminary patch. Working on tests.

Do we need to reexport all the paragraph type across paragraphs and paragraphs collection modules?

Status: Needs review » Needs work

The last submitted patch, 3: add_paragraph_type-2879350-3.patch, failed testing.

acaljuba’s picture

Status: Needs work » Needs review
StatusFileSize
new4.58 KB
new507 bytes

Small fixes in schema file.

acaljuba’s picture

Tests have been extended.

Status: Needs review » Needs work

The last submitted patch, 6: add_paragraph_type-2879350-6.patch, failed testing.

acaljuba’s picture

Status: Needs work » Needs review
StatusFileSize
new6.92 KB
new860 bytes

Small fixes.

Status: Needs review » Needs work

The last submitted patch, 8: add_paragraph_type-2879350-8.patch, failed testing.

acaljuba’s picture

Status: Needs work » Needs review
StatusFileSize
new7.13 KB
new1.42 KB

Small fixes. Hopes it goes well this time.

miro_dietiker’s picture

This looks pretty much fine.

The only thing is that the permission flag is now introduced in the main module while its implementation is only introduced in the submodule. However, introducing its schema and the API in the submodule might be much more work.
Still want some more review / feedback on some Entity API guy. :-)

miro_dietiker’s picture

Priority: Normal » Minor
Status: Needs review » Needs work
  1. +++ b/config/schema/paragraphs_type.schema.yml
    @@ -20,6 +20,9 @@ paragraphs.paragraphs_type.*:
    +    enable_permissions:
    

    This should go into third party settings of paragraphs.
    It makes no sense to have this as a top level setting that is not implemented in paragraphs.module itself.

  2. +++ b/src/Entity/ParagraphsType.php
    @@ -89,6 +90,33 @@ class ParagraphsType extends ConfigEntityBundleBase implements ParagraphsTypeInt
    +  public function hasEnabledPermissions() {
    ...
    +  public function setEnabledPermissions($enable_permissions) {
    

    This also is not possible in paragraphs.module if it is not setting aware and thus we should use get / setThirdPartySettings then.

We discovered in our use cases that we need to set most of the paragraph type permissions anyway as soon as you have lower privileged users (authenticated) ones that add content too. Thus lowering prio.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new5.36 KB
new6.79 KB

Moved to third party settings. Now everything is in the submodule.

berdir’s picture

Status: Needs review » Needs work

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

partdigital’s picture

I've rerolled the patch against 8.x-1.x and fixed the automated tests.

Changes can be found in this MR: https://git.drupalcode.org/project/paragraphs/-/merge_requests/83/diffs

I did make one change to however. If the permission setting isn't enabled for a paragraph then that paragraph simply isn't available to use at all. That would require us to turn on the setting for every single paragraph which kind of defeats the purpose of having the setting in the first place.

I've updated the access hooks so that Paragraphs are not restricted if the setting is disabled. This allows us to have some paragraphs that are controlled with permissions and others that aren't. On a site with 20+ paragraphs this helps a lot.

function paragraphs_type_permissions_paragraph_access(ParagraphInterface $entity, $operation, AccountInterface $account) {
  
  // If the permission does not exist then do not restrict access.
  $enable_permission = $entity->getParagraphType()->getThirdPartySetting('paragraphs_type_permissions', 'enable_permissions', FALSE);
  if (!$enable_permission) {
    return AccessResult::neutral();
  }

}

function paragraphs_type_permissions_paragraph_create_access(AccountInterface $account = NULL, array $context = array(), $entity_bundle = NULL) {

  // If the permission does not exist then do not restrict access.
  $paragraph_type = \Drupal::entityTypeManager()->getStorage('paragraphs_type')->load($type);
  $enable_permission = $paragraph_type->getThirdPartySetting('paragraphs_type_permissions', 'enable_permissions', FALSE);
  if (!$enable_permission) {
    return AccessResult::neutral();
  }

}

partdigital’s picture

Status: Needs work » Needs review