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. Create a draft content item
  4. As any user without `bypass node access` permission, 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))";
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

xrobp created an issue. See original summary.

xrobp’s picture

Issue summary: View changes
xrobp’s picture

xrobp’s picture

Title: Moderated Content view does not show the correct data for roles other than the group creator » Moderated Content view does not show the correct data for anyone without bypass node access permission

xrobp’s picture

Status: Active » Needs review
slydevil’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Works! Thanks @xrobp.
slydevil’s picture

Issue tags: -Works! Thanks @xrobp.

Works! Thanks @xrobp.

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

msnassar’s picture

For now we should ignore the failing tests in D11 builds. This is going to be fixed in another issue.

The tests using D10 are passing, this demonstrate that our tests are not good. So in order to demonstrate this issue, lets write a test that fails .
BTW, from group 2, I think we might not need this views plugin anymore! But lets demonstrate this later in another ticket.

msnassar’s picture

Now we have a failing tests... Lets have them passing by fixing the reported issue.

msnassar’s picture

I have cherry picked the fix from MR21. Now the tests are green again...

I think the exiting code in this test can be improved... Anyway, the next step is to demonstrate that we might not need this views plugin anymore!

andras_szilagyi’s picture

Looks good

keszthelyi’s picture

Tested the fix in MR!28 and it solved the issue +1

msnassar changed the visibility of the branch issue/3471105-moderated-content-view to hidden.

msnassar changed the visibility of the branch 3471105-moderated-content-view-test-v2 to hidden.

msnassar changed the visibility of the branch 3471105-moderated-content-view-test-v2 to active.

  • hernani committed 372e963f on 3.0.x authored by msnassar
    Issue #3471105 by msnassar, xrobp, slydevil, andras_szilagyi, keszthelyi...

  • hernani committed cdd55cf5 on 2.0.x authored by msnassar
    Issue #3471105 by msnassar, xrobp, slydevil, andras_szilagyi, keszthelyi...
hernani’s picture

Status: Reviewed & tested by the community » Fixed

Merged !

Thank you !

Status: Fixed » Closed (fixed)

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