Closed (fixed)
Project:
Group
Version:
8.x-1.x-dev
Component:
Group Node (gnode)
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Jun 2017 at 19:54 UTC
Updated:
6 Dec 2017 at 14:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kevin.dutra commentedStarting work on this, not ready yet -- definitely needs test updates.
Comment #3
realityloop commentedAlso see https://www.drupal.org/node/2878389#comment-12089798
Comment #4
kevin.dutra commentedFixed a couple issues and adjusted the existing tests to account for the changes.
I think these tests are a good start, but ultimately, I don't think it goes far enough to check the hooks directly. What we really need is a test that makes use of the generic
$node->access()to be sure that the pieces are all playing together properly.Comment #5
seanbThis doesn't seem to work. I love the idea of adding static caching. Have you tested this with custom group roles (not synchronized from the user roles)?
$roleis a object, andgetGroupRoleId()expects a role ID. So we need to do$synchronizer->getGroupRoleId($group_type_id, $role->id())We need a use statement for
Drupal\group\Entity\GroupRoleSince
$rolecan be empty, this could lead to an error. Probably best to add a check for$roleabove like:Comment #6
seanbThere is another issue I found trying to debug this, the subgroup patch in #2736233: Port Subgroup (ggroup) to the D8 version allows membership inheritance. An event was added to the
hasPermission()method of a group to also check the permission in subgroups/supergroups. This makes it harder to change the grants to roles as you are proposing in the patch.Not sure what to do, but just wanted to let you know so maybe we can figure out another way?
Comment #7
seanbThis already helps A LOT! Page load was more than 3 times as fast. Number of queries went from 1169 to 689.
Comment #8
kevin.dutra commentedThanks for the review and good catches! Going ahead and moving back into "needs work" for the time being.
Comment #9
kevin.dutra commentedI also fixed one more inconsistency with the way the grant realm was crafted for the synced roles. (The grant used the Drupal role ID but the access record used the group role ID, so they would never match.) But they do now.
Comment #10
kevin.dutra commentedOops, forgot the extra test coverage.
Comment #11
seanbChanges look good! Thanks.
There is still an issue for possible membership inheritance through subgroups. Could you maybe also take a look at this? Maybe we can come up with some solution to allow these changes while still keeping permission inheritance?
Comment #12
kevin.dutra commentedYep, I'll definitely take a look and noodle on it.
Comment #13
kevin.dutra commentedWhoops, kinda forgot a key piece there. (Also a couple minor formatting/comment issues.)
Comment #14
kevin.dutra commentedD'oh. Logic bug. If a node belonged to multiple groups of the same type, then only then not all the access records would be applied.
Comment #15
kevin.dutra commentedAlso, I looked over the subgroup ticket. Wow, that's a whole lotta weird and complicated. I'm not sure I even 100% understand everything that's going on there, so I can't really say for sure, but I think the general idea would be to augment the node access records with the records for the parent/child groups. (The grants don't need to be adjusted because they already identify the appropriate traits for the user.)
Comment #16
seanbYeah, subgroups are pretty complex. Just found out the node grants doesn't work well with subgroups in the current situation as well. The grants are only added for the groups you are a member of. Since you can inherit roles/membership for parent groups or subgroups, this is an issue.
This needs attention for sure, which might not be a problem of the node grants hook.
Comment #17
danmuzyka commentedThis looks good overall, just have a few nitpicks/suggestions.
Shouldn't this also mention 'gnode_out:role_id' for the synced roles, and 'gnode:role_id' for the group roles?
Maybe the comment here should mention that we assign a generic grant ID of '0' rather than the group ID, since this permission isn't specific to a given group.
Maybe the comment here should mention that we assign a generic grant ID of '0' rather than the group ID, since this permission isn't specific to a given group.
Maybe the comment here should mention that we assign a generic grant ID of '0' rather than the group ID, since this permission isn't specific to a given group.
Maybe the comment here should mention that we assign a generic grant ID of '0' rather than the group ID, since this permission isn't specific to a given group.
Shouldn't this state 'Anonymous users only receive the anonymous grant.' rather than '...the bypass grant.'?
Would it be feasible to simulate creation of a synced role and checking that it IS set appropriately here, in addition to checking that the faux roles are not set?
Comment #18
kevin.dutra commentedComment #19
danmuzyka commentedLooks good to me. Thanks @kevin.dutra!
Comment #20
sriharsha.uppuluri commentedI see there is a lot of speed after applying the patch. From 10s to 1s. And also after apply of this @https://www.drupal.org/node/2895988
Comment #21
kristiaanvandeneyndeSweet, reviewing the patch now at DrupalCamp BE.
@seanB I was the room monitor for your session just now, what a coincidence :)
Comment #22
kristiaanvandeneyndeRe #9:
There's no dedicated method for it (yet), no. Currently it requires you to get the group_roles field from the representative GroupContent entity. Please open a feature request for this if you haven't already. Issue queue is a bit overwhelming right now :)
While this doesn't change any existing functionality, it does count as a minor API break. I'm considering to let this one slide for a mention in the release notes, though.
Looking into the rest of the patch still.
Comment #23
kristiaanvandeneyndeI'm still looking into this but there's two parts in the code that have me worried so far:
You can get less access by joining a group. It's perfectly possible for me to allow only outsiders to see "call to action to join" type of content and disallow members to see that under any circumstance. You can give any outsider role the "view node type X" permission and not give it to members.
This is not how the node access layer is supposed to work. In D7 we used to let Group trump all other modules but then people told us to play nice, so we did. We need to respect other access modules' settings.
Comment #24
kristiaanvandeneyndeI'm sorry, I really appreciate the effort but this patch needs work.
There is one major improvement in this patch that holds merit: If you are anonymous to one group, you are anonymous to all groups. So you're right to add all of the node's anonymous group permissions together into a gnode_anon realm and assign it a realm ID of 0. I'm sure this alone will lead to a huge performance increase.
But we can't similarly throw all of the outsiders in one big pool. Because you may be an outsider to group 1 and not 2, you must specify the group ID that the access record came from for outsiders. If not, you could run into the following scenario:
Set-up
Tests
This is why the original code did not keep track of grants/access records per audience because it doesn't work that way. As I said earlier, though: You uncovered an excellent optimization for anonymous users!
How about we keep the existing code and only add a 'gnode_anonymous' realm that has the power of short-circuiting gnode_node_grants() just like the bypass grant already does? We'd still need to figure out a way to improve performance for logged in users, though.
Comment #25
kristiaanvandeneyndeAlso can someone post some numbers or experiences with the performance? For what audiences does it work well and for what audiences is it really slow. And is it slow on the database server (big query) or on the PHP side (lots of processing)?
Comment #26
sriharsha.uppuluri commentedFacing issue on node update the node_access table is not getting updated.
Eg: I have group A and group B, node/1 attached to group A. Next, I have added the same node to group B. But its not adding the gid in node_access.
Comment #27
sriharsha.uppuluri commentedIn function
gnode_node_access_recordsthe code is like entering access permissions only once. If added the node in other group the node access is not adding.Comment #28
kristiaanvandeneyndeYup, I just ran into that myself while trying to write a new patch for this issue. But what you're reporting is not within the scope of this issue and probably warrants its own bug report if there isn't one already.
Comment #29
kristiaanvandeneyndeThis isn't complete yet as I haven't adjusted the existing tests nor added new ones for the added functionality, but I figured I'd post this already so you guys can review. This takes the excellent optimization for anonymous users and implements it. Please review.
Edit: The new idea still needs to be reflected in gnode_node_grants() where we short-circuit that one for anonymous users.
Comment #30
kristiaanvandeneyndeThis actually has the full functionality change. Will adjust/add test coverage next.
Comment #31
kristiaanvandeneynde...
Comment #32
kristiaanvandeneyndeI think this is complete. It also checks whether subject entities are resaved when added to a group to counter the report made in #27. Can anyone test the performance of this for anonymous users both before and after the patch?
Comment #34
kristiaanvandeneyndePatch makes sense to me, was derived from earlier user-contributed patches and I'm generally lacking reviewers.