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.

  1. Move GroupType settings to Content Bundle Entity settings form using third-party-settings.
  2. Alter GroupRole config entities to include group_entity_type and group_entity_bundle.
  3. Add GroupRouteSubscriber to move GroupType sub pages "Roles", "Permissions", and "Content" underneath entity.BUNDLE.edit-form route. This is EXACTLY how the Field UI module attaches itself to config entity forms.

Remaining tasks

  1. Alter plugins code.
  2. Alter schema for GroupRelationship to use group_entity_id and group_entity_type fields instead of gid.
  3. Move GroupRelationship UI to "group content entities" via GroupRouteSubscriber or provider.
  4. Update views, etc to use the new fields.
  5. 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

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

jon pugh created an issue. See original summary.

jon pugh’s picture

Issue summary: View changes
jon pugh’s picture

Issue summary: View changes