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
- Set up a default moderation flow
- Create a new role, assign the permissions to moderate content
- As a different user create a draft content item
- As a user with the new role view the Moderated Content view
- 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))";