With this issue, I am going to try and allow any content entity to act as a group.
Problem/Motivation
Old school OG organic groups allowed any content entity to become a group. The implementation was a bit clunky, with a special field, but it allowed for some pretty great flexibility.
I am building out a complex web app with multiple levels of groups and permissions, all content is private. My three main custom content entities reference each other in a tree: Organization > Plan > Budget, using standard entity reference fields. Each of these types can be "shared": they each have a group of users. Each user can be assigned roles so they can control who can view, who can edit, etc. Users can grant access to a parent entity and they will get access to all children.
In order to achieve this functionality with current group.module architecture, I had to create a group entity for every single one of these entity types, then use a custom access handler to check group permissions up and down the tree.
This creates a situation with a ton of joins, impacting performance significantly. As we scale this is going to be a major problem.
to calculate a user's access, even the standard use case has 4 joins:
- Content Entity > GroupRelationship > Group Entity > Group Membership > User.
In my use case, there about 12 joins.
- Content Entity > Group Entity > Membership > User.
- Content Entity > Child Entity > Group Entity > Membership > User.
- Content Entity > Child Entity > Grandchild Entity > Group Entity > Membership > User.
Proposed resolution
Allow any content entity to become a group.
I have figured out a way to make this happen.
- Move
GroupTypesettings to Content Bundle Entity settings form using third-party-settings. - Alter
GroupRoleconfig entities to includegroup_entity_typeandgroup_entity_bundle. - Add
GroupRouteSubscriberto move GroupType sub pages "Roles", "Permissions", and "Content" underneathentity.BUNDLE.edit-formroute. This is EXACTLY how the Field UI module attaches itself to config entity forms.
Remaining tasks
- Alter plugins code.
- Alter schema for
GroupRelationshipto usegroup_entity_idandgroup_entity_typefields instead ofgid. - Move
GroupRelationshipUI to "group content entities" viaGroupRouteSubscriberor provider. - Update views, etc to use the new fields.
- TBD
User interface changes
GroupType configuration, including settings, roles, permissions, and content moves to group-enabled content entity type edit forms.
API changes
Add group_ui_base_route to custom content entity definition to make the entity a "group" and enable the Group config pages. Entity Info alters could be used to enable existing entity types like nodes. This is EXACTLY how the Field UI module attaches itself to config entity forms
Data model changes
See above. Will add detail later.
Notes
I am building this out and will use it in production when it's ready.
Obviously this is a very big change. I don't have any opinion about releasing it, but I guess if we did, it would be 5.x.
Feedback is encouraged.
Issue fork group-3635056
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
Comment #2
jon pughComment #3
jon pugh