Moderated Content view does not show the correct data for roles other than the group creator

Created on 29 August 2024, 4 months ago

Problem/Motivation

In the Moderated Content view on the Group content items aren't shown except when the user has the `bypass node access` permission.

The issue appears to be due to the "Respect group content unpublished permission" filter. The filter adds a "where" expression to the views query that is supposed to restrict the nodes listed to those of the types available to the group:

      $snippet .= "
        (($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND group_relationship_field_data_node_field_data.type='group-group_node-$nodeType' AND :own_unpublished_$nodeType)
        OR
        (group_relationship_field_data_node_field_data.type='group-group_node-$nodeType' AND :all_unpublished_$nodeType))";

However, in the table `group_relationship_field_data`, the `type` column's value begins with the group's Group Type id, and that is not always going to be "group". If the Group Type is "Department", then the value may be `department-group_node-page`, rather than `group-group_node-page`.

Steps to reproduce

  1. Set up a default moderation flow
  2. Create a new role, assign the permissions to moderate content
  3. As a different user create a draft content item
  4. As a user with the new role view the Moderated Content view
  5. You should see the draft content item, but in fact you don't

Proposed resolution

Fix the `GroupContentRespectUnpublished` views filter plugin to use the group's Group Type id in the query:

    $groupTypeId = $group->getGroupType()->id();

      $snippet .= "
        (($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0 AND group_relationship_field_data_node_field_data.type='$groupTypeId-group_node-$nodeType' AND :own_unpublished_$nodeType)
        OR
        (group_relationship_field_data_node_field_data.type='$groupTypeId-group_node-$nodeType' AND :all_unpublished_$nodeType))";
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada xrobp

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024