Problem/Motivation

The groups do not appear in the admin overview page for the site administrator, since he has no permission to view them.
In order for administrator to have access to the groups, one must create two group roles (1 for the insider and 1 for the outsider scopes) mapped to the administrator site role.
I guess there are business cases, where the site admin should not have access to all the content, so it could be like this by design, and since I am new to the module, I will not dwell on that.

The expected behavior with the existing implementation, would be that if just one role for one scope was created, the mapped site role should be able to view only groups relevant to the scope. E.g. If just 1 group role was created, for the insider scope, mapped to the administrator site role, then the administrator should view only the groups he is a member of.
Obviously the opposite logic applies if the outsider scope was used. For the outsider scope this works as intended, but if the insider scope was selected, the admin can view no groups, not even the ones he is a member of.

After some digging, this issue seems to stem from the GroupQueryAlter::addSynchronizedConditions and the permissions calculated in SynchronizedGroupPermissionCalculator::calculatePermissions.

If I understand correctly, the calculator gets the users roles and applies the relevant scopes. Every user is an authenticated user, so they always get the outsider scope, which in turn applies the isNull sub-condition in the GroupQueryAlter::addSynchronizedConditions. If both roles exist, the sub-condition is an OR condition, but if just one role exists, then it is an AND condition, which results to contradicting WHERE statements. For reference I will attach the 3 resulting queries in the end of the GroupQueryAlter::doAlter:

  • inside - Just a group role with the insider scope exists.
  • outside - Just a group role with the outsider scope exists.
  • both - Both of the above exist... Duh :D

Steps to reproduce

  1. Create a group role for the insider scope as shown in the screenshot screens.
  2. Create a group.
  3. Go to /admin/group.
  4. No groups appear in the list, while they should.

Remaining tasks

  • Investigate the issue.
  • Resolve.
  • Update tests.

Comments

marios anagnostopoulos’s picture

Issue summary: View changes
marios anagnostopoulos’s picture

Issue summary: View changes
kristiaanvandeneynde’s picture

Very detailed report, thanks for that! I will have a look at the cause you described and see if this can be fixed.

kristiaanvandeneynde’s picture

Okay, I think I see what's going on here:

  • You have an insider admin role synced with the Drupal admin role (that you have)
  • You have an outsider regular role which can view published groups synced with the Authenticated user Drupal role
  • Because your insider or outsider status is only confirmed on the query level, we need to add both to the query

Admin roles map to the simpler $allowed_ids in GroupQueryAlter::doAlter(), but then it still processes the outsider role and adds the status condition and contradiction membership condition.

This is because all conditions are glued together using AND rather than OR. When we have both non-status-relevant and status-relevant items, we need to make sure they get added to an OR group.

Then the query becomes:

WHERE
  (
    (`groups`.type IN ('organisation'))
    AND (gcfd.entity_id IS NOT NULL)
  )
  OR # THIS WAS ERRONEOUSLY AND
  (
    (groups_field_data.status = 1)
    AND
    (
      (groups_field_data.type IN ('organisation'))
      AND (gcfd.entity_id IS NULL)
    )
  )
kristiaanvandeneynde’s picture

StatusFileSize
new4.95 KB

This is how I would probably fix it. Needs tests and we might need to check the other query alters for similar logic.

kristiaanvandeneynde’s picture

Okay so those going green is:

  • A good thing because it does not break any existing tests
  • A bad thing because it clearly still needs a test for the scenario from the issue summary

Signing off for the day, but what we need now is a test that goes red without my patch and green with.

kristiaanvandeneynde’s picture

Status: Active » Needs review
StatusFileSize
new7.02 KB

GroupRelationshipQueryAlter suffered from the same problem. EntityQueryAlter did not because it always adds an OR-group at the top level. Still needs tests.

kristiaanvandeneynde’s picture

StatusFileSize
new36.16 KB

This one might break things and turns off some existing tests, but it's a complete, more thorough approach so we can test mixed cases more easily. The one that was reported here still needs to be added.

Status: Needs review » Needs work

The last submitted patch, 9: group-3305707-9.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new40.05 KB

This should fix the failures for GroupQueryAlter, still needs others fixed and expanded test coverage.

kristiaanvandeneynde’s picture

StatusFileSize
new40.13 KB

This adds back the unpublished checks and adds checks for the issue that caused this issue (one scope has admin, the other does not)

Status: Needs review » Needs work

The last submitted patch, 12: group-3305707-13.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new40.61 KB

This should fix group access. Before we commit, we should take out the fix and see if the mixed cases fail then.

kristiaanvandeneynde’s picture

StatusFileSize
new41.61 KB

This should fix all of the group tests. Then we can move on to reviewing the other query alters.

Status: Needs review » Needs work

The last submitted patch, 15: group-3305707-17.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new42.88 KB

Forgot to uncomment a few things to make local testing easier...

Status: Needs review » Needs work

The last submitted patch, 17: group-3305707-19.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new43.74 KB
kristiaanvandeneynde’s picture

StatusFileSize
new45.7 KB

Might see some cacheability fails now, but the unsupported actions should go green now.

Status: Needs review » Needs work

The last submitted patch, 20: group-3305707-20.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new45.7 KB

Copy-paste mistake

Status: Needs review » Needs work

The last submitted patch, 22: group-3305707-21b.patch, failed testing. View results

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
StatusFileSize
new46.17 KB

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Confirmed locally that the 3 view tests fail for mixed scope (admin v regular) when I comment out the new code. So fixed!

Status: Fixed » Closed (fixed)

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