Problem/Motivation

The Group content permission provider does not provide a 'view own unpublished entity' permission. This permission is particularly useful for the content moderation module. When content has to be reviewed before publishing you want the ability for the group member and creator of the content item to edit the content item. Right now the only way would be to add the "View any unpublished entity" permission to all group members which is not acceptable for most common use cases.

Proposed resolution

Add that permission in the GroupContentPermissionProvider for entities which implement the PublishedInterface and OwnerInterface.

The access check is already done in Drupal\group\Plugin\GroupContentAccessControlHandler by checking for the "view own unpublished entity".

There is already a test for the Entity Query Access in EntityQueryAlterComplexTest::testMemberViewOwnUnpublishedAccess so we won't need to test for that.

Tests need to be changed in:

  • GroupContentPermissionProvider: to make sure the correct permissions are provided based on the implementation of PublishedInterface and OwnerInterface
  • EntityAccessComplexTest: to make sure that the user can view it's own unpublished content when it has the permission

Issue fork group-2876696

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review

This adds the 'view own unpublished content' permission to be in keeping with all the node module's permissions.

jhedstrom’s picture

jhedstrom’s picture

FileSize
791 bytes
1.47 KB

Oops, that was missing a parameter to hasPermission().

jhedstrom’s picture

FileSize
1.32 KB

Bah, that had a custom code comment in it. Sorry for the noise.

robertragas’s picture

+1 , code works, but personally I would prefer to see this per content-type like
"Group node (Article) - Entity: View own unpublished content entities"

jhedstrom’s picture

I would prefer to see this per content-type like
"Group node (Article) - Entity: View own unpublished content entities"

Agreed. This is the corresponding core issue for such permissions: #2875867: Add per-bundle unpublished content permissions.

jhedstrom’s picture

Er, actually that core permission issue is for 'view any'. I'm not aware of any effort in core to split the view own permission out into per-bundle permissions.

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

jaapjan’s picture

Category: Bug report » Feature request
Issue summary: View changes

Since the Group module now leverages the contrib Entity module and has an access control handler which supports the "View own unpublished entity" permission I think we could change this to a Feature request. Implementing this shouldn't be too much work and the added benefit is that it will work for all the content entities.

@jhedstrom I hope you are OK with me changing this report. But since the issue was a bit older I thought it would make sense to do it like this.

jaapjan’s picture

Title: gnode_node_access should check for 'view own unpublished content' permission » Add support for 'view own unpublished entity' permission
Component: Group Node (gnode) » Group (group)

Merge request should be complete now. Open for any feedback/review.

jaapjan’s picture

_dcre_’s picture

patch #5 is not creating a permission per content type

i attach a slightly updated patch which does.

jaapjan’s picture

Beware that the patch file is outdated and does not use the new Entity Access handling.

The merge request contains the code you should use with the latest version of 1.3. https://git.drupalcode.org/project/group/-/merge_requests/9.patch

It would be really nice if you could test that one instead.

jyraya’s picture

Hello,

I tested the patch 9 referenced in the #16 of Jaap.

With the permission "Entity: View own unpublished content item entities", I was able to restrict the access to unpublished content to the only group-level authors and the users having a role with the permission "Entity: View any unpublished content item entities".

I was able to set the permissions for every content type "installed" on the group type.

Thanks everybody for the work!

bramtenhove’s picture

Status: Needs review » Reviewed & tested by the community

Also tested #16 and all works as expected.

Setting it to RTBC.

ayalon’s picture

Maybe we should also include "View own entity" in the patch. I added it and it works out of the box.

  /**
   * {@inheritdoc}
   */
  public function getEntityViewPermission($scope = 'any') {
    if ($this->definesEntityPermissions) {
      // @todo Implement view own permission.
      if ($scope === 'any') {
        // Backwards compatible permission name for 'any' scope.
        return "view $this->pluginId entity";
      }

      if ($scope === 'own' && $this->implementsOwnerInterface) {
        return "view $scope $this->pluginId entity";
      }
    }
    return FALSE;
  }
jyraya’s picture

The possibility to have a "View own entity" permission deserves its dedicated issue as:

  • The use case is not exactly the same as the current issue, as the current issue is focused on unpublished state of contents.
  • It could have consequences on other Group-dependent modules that should not be underestimated.
    Then, we should have further test efforts on this.

Therefore, I propose to move on with the current patch and create a dedicated issue for the "View own entity" permission detailing the use case, the motivations and

dan2k3k4’s picture

I'm attaching the merge-request patch from #9 as in case the MR gets new commits, then that link would get updated with those changes.

Testing #9 on a project where the editor creates a new node for a specific group they are a member of, but does not publish the node.

EDIT:
I missed the new permission on the Group Type which I needed to check:

- View own unpublished content item entities

FiNeX’s picture

Component: Group (group) » Code

This patch also works on Group 2.x but you've to apply manually.

dalra’s picture

Version: 8.x-1.x-dev » 3.0.x-dev
kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Needs work

This needs a reroll for v2/v3 as it still mentions GroupContentEnabler. I also see no label being added for the new permission.

msnassar’s picture

msnassar’s picture

Status: Needs work » Needs review
kristiaanvandeneynde’s picture

This would work, I'm just carefully considering whether this is an API break or not.

Also:

if ($scope === 'any') {
  return "view $scope unpublished $this->pluginId entity";
}

if ($scope === 'own' && $this->implementsOwnerInterface) {
  return "view $scope unpublished $this->pluginId entity";
}

Can simply be:

if ($scope === 'any' || $this->implementsOwnerInterface) {
  return "view $scope unpublished $this->pluginId entity";
}
kristiaanvandeneynde’s picture

Status: Needs review » Needs work

The last submitted patch, 28: group-2876696-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
FileSize
3.16 KB

Whoops

Status: Needs review » Needs work

The last submitted patch, 30: group-2876696-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
FileSize
4 KB

This should fix that.

Status: Needs review » Needs work

The last submitted patch, 32: group-2876696-32.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
FileSize
3.94 KB

I need to learn to test locally before submitting stuff...

kristiaanvandeneynde’s picture

Version: 3.0.x-dev » 3.1.x-dev
Status: Needs review » Fixed

As this is a feature I've added it to a new minor version (3.1.0/2.1.0)

Status: Fixed » Closed (fixed)

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