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
- Create a group role for the insider scope as shown in the screenshot
. - Create a group.
- Go to /admin/group.
- No groups appear in the list, while they should.
Remaining tasks
- Investigate the issue.
- Resolve.
- Update tests.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | group-3305707-24.patch | 46.17 KB | kristiaanvandeneynde |
Comments
Comment #2
marios anagnostopoulos commentedComment #3
marios anagnostopoulos commentedComment #4
kristiaanvandeneyndeVery detailed report, thanks for that! I will have a look at the cause you described and see if this can be fixed.
Comment #5
kristiaanvandeneyndeOkay, I think I see what's going on here:
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:
Comment #6
kristiaanvandeneyndeThis is how I would probably fix it. Needs tests and we might need to check the other query alters for similar logic.
Comment #7
kristiaanvandeneyndeOkay so those going green is:
Signing off for the day, but what we need now is a test that goes red without my patch and green with.
Comment #8
kristiaanvandeneyndeGroupRelationshipQueryAlter suffered from the same problem. EntityQueryAlter did not because it always adds an OR-group at the top level. Still needs tests.
Comment #9
kristiaanvandeneyndeThis 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.
Comment #11
kristiaanvandeneyndeThis should fix the failures for GroupQueryAlter, still needs others fixed and expanded test coverage.
Comment #12
kristiaanvandeneyndeThis adds back the unpublished checks and adds checks for the issue that caused this issue (one scope has admin, the other does not)
Comment #14
kristiaanvandeneyndeThis should fix group access. Before we commit, we should take out the fix and see if the mixed cases fail then.
Comment #15
kristiaanvandeneyndeThis should fix all of the group tests. Then we can move on to reviewing the other query alters.
Comment #17
kristiaanvandeneyndeForgot to uncomment a few things to make local testing easier...
Comment #19
kristiaanvandeneyndeComment #20
kristiaanvandeneyndeMight see some cacheability fails now, but the unsupported actions should go green now.
Comment #22
kristiaanvandeneyndeCopy-paste mistake
Comment #24
kristiaanvandeneyndeComment #27
kristiaanvandeneyndeConfirmed locally that the 3 view tests fail for mixed scope (admin v regular) when I comment out the new code. So fixed!