Many groups to many users

Created on 22 December 2023, 6 months ago
Updated 3 February 2024, 5 months ago

Problem/Motivation

I want to build a site with a permission system similar to what is described by the access_by_ref module . I will try to write out some user stories.

First here are some definitions:
Contributor - someone who is not necessarily part of a group, but can contribute content to the site
Group manager - A contributor who can edit a group page as well as any content for which the group has been given edit access
Group member - A contributor who can view a private group page as well as any content belonging to that private group
Group owner - Generally the person who created it, unless ownership had been otherwise transferred (this concept might not be important)

  • A contributor can create a group
  • A group manager can assign other users as group managers
  • A group manager can assign other users as group members
  • A group manager can give multiple groups (that they manage) edit access to a piece of content
  • A group manager can give multiple groups (that they manage) view access to a piece of private content
  • A contributor can give an individual user edit access to a piece of content
  • A contributor can give an individual user view access to a piece of private content
  • A group manager can determine a group to be private (unviewable by anyone outside of the group)
  • A contributor can determine a piece of content to be private (unviewable by anyone that is not given viewing access directly, or that is not belonging to a group which has been given viewing access)
  • A contributor can easily keep track of which groups or individuals have read or write access to a piece of content
  • A group manager can easily keep track of which individuals have read or write access to the group and all content the group has access to

Group module will not work because the content should not "belong" to a group

I was really looking forward to the Access by ref module because what it describes sounds like what I want, but from playing with it, I am not sure that it works.

I am also giving Entity access by reference field a try, which looked like it might be an improvement on access by ref, but I also ran into an issue there where I couldn't create fields (and opened an issue of course)

There are some others I have not tried.

I don't get the sense that this use case can be met by this module, given what I have read and tried so far, but it is hard to tell because this module seems pretty complex. On the other hand, I am getting a sense that the kind of functionality that I am hoping to achieve has some common pitfalls.

I was hoping you could tell me whether it is worth attempting to implement this with access policy. If you think it may fit my use case, please share any helpful tips, and if it does work, I would be happy to document my setup. If you know that it will not work, please say so.

Anyway, thanks for the awesome module. It seems pretty powerful.

💬 Support request
Status

Postponed

Version

1.0

Component

Documentation

Created by

🇺🇸United States MegaKeegMan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @MegaKeegMan
  • 🇺🇸United States partdigital

    Hi MegaKeegMan thanks for reaching out!

    You should be able to do this with access policy, this sounds like a combination of these two tutorials:

    If you haven't tried them yet I recommend going through them.

    For your use case it sounds like two roles (Content manager and Contributor) and two access policies (Public and Private)

    Public content
    Viewable to everyone but only editable to users in a group.
    Follow the "Group content by department" tutorial above. Only change you will need to make is to grant all roles "view" access.

    Private content:
    Editable by original author, only viewable to users in a group OR users are are explicitly granted access.

    Follow the "Private content" tutorial

    Then add additional access rules with the OR validation operator. You'll also need to adjust the operation constraints. Note, in order to add these access rules you'll need to add fields to the node and user.

    • Compare Group with user
    • Allowed users field has reference to current user

    Definitely worth giving a try. Let me know if you run into any issues.

  • 🇺🇸United States MegaKeegMan

    Oh cool. I started following along the group content by department guide, and I got the sense that if one user was given the Content manager role, then they would essentially be a manager of every group for which they had the taxonomy term assigned to them, where I actually want them to be managers of some, and only members of others. Is that not the case, and is it actually just that every user should have both roles?

  • 🇺🇸United States MegaKeegMan

    Making progress in understanding how to achieve my goals. Maybe this is also documented somewhere, but I am configuring the access rules for my policy:

    I am concerned that if I have the validation operator set to "Any" then it could grab the first access rule that the user meets the criteria for. In my example above, would a user that meets all of the rules above always be granted access by the most permissive rules provided here?

  • 🇺🇸United States MegaKeegMan

    Okay, but the main issue I think I have:
    groups permissions are taxonomy based. This does not necessarily have to be an issue. But A user should be able to add or remove a group (term) from another user's term reference field on the condition that they themselves are a manager of that group.

    Ideally (for me) group access would be managed centrally, and not from a user reference field. I am not sure if it will be possible to restrict what values can be added or removed from this field based on the current user's access to that group, which could be granted from a variety of sources:

    • edit access to that group (user reference field on node)
    • edit access to that group (term reference on their account)

    To clarify, in my current implementation, I have basically followed the private tutorial, and I have one access policy (though I think I will add another later). Let's just assume the one for now though.

    I have four relevant fields on my node:

    • Users with edit access (user reference)
    • Users with view access (user reference)
    • Groups with edit access (term reference)
    • Groups with view access (term reference)

    And I have added 4 access rules:

    • Users with edit access field has reference to current user
    • Users with view access field has reference to current user
    • Compare Groups with edit access with user
    • Compare Groups with view access with user

    And user accounts have 2 related fields:

    • Groups editable
    • Groups viewable

    Let's say I have Group 1 in my Groups editable field. In that case, I should be able to add or remove Group 1 from anyone else's Group's editable or Group's viewable fields. If I did not have Group 1 in my Groups editable field, I should not be able to do this. Though if Group 2 was in my Groups editable field, I should be able to add or remove Group 2 from someone else's account fields. Is it possible to do this in a secure way?

    If yes, then the next question would be: are there any recommendations about how I could administer group management and membership all in one place, without having to edit the term reference fields on the user? (It is okay for these fields to be used still, but I just want an interface where I can administer managers and members, such that the values in these user fields are not manipulated manually.

  • 🇺🇸United States partdigital

    Ah ok I think I understand now. I hadn’t considered this use case so thanks for that!

    A few suggestions:

    • You only need to have one “Group” field on the node. The “Group editable” and “Group viewable” on the user should be enough because they're already controlling operations.
    • Have you tried breaking up the policy into two (Group and User access policies) and putting them in a Selection set? This would allow you to toggle user/group access for each node. It's not strictly necessary but it might be nice user experience.

    Ideally (for me) group access would be managed centrally, and not from a user reference field.

    There’s currently nothing built into Access policy to do this. However, you could do the following:

    • Create a new view that shows the Group taxonomy terms.
    • When a user clicks a term it will show another view that lists the members of that group.
    • Install the Views bulk operations module and write a few custom action plugins (e.g Add member, Remove member).

    We did something similar to this on one of our projects and it worked well for us.

  • 🇺🇸United States MegaKeegMan

    Thanks for all of the feedback. It is very helpful. I will play with your suggestions a bit more and put some consideration into your bulk operations idea.

  • 🇺🇸United States MegaKeegMan

    Would someone performing these bulk operations on group members require the permission to change the values in the user field?

  • 🇺🇸United States MegaKeegMan

    As far as whether I should reduce the two group reference fields (on the node) to one, this has highlighted some questions I need to discuss with our client, will follow up once I have clarification.

  • 🇺🇸United States MegaKeegMan

    So looks like it will be a tad simpler for now. For the short term, I will just be using groups to manage read access on content, and not for any write access. All write access will be managed by the user reference fields on the node. This may change later in development. With that being said, I am very much appreciating the flexibility that this module provides.

  • 🇺🇸United States MegaKeegMan

    About splitting up the access policies, I am not sure that I would do it the way you suggest exactly. Rather I was considering having 2 access policies:

    • Public - All users can view, and therefore will not include fields pertaining to view access (Groups or users with view access). Will still have a field for users with edit access.
    • Private - Only referenced groups and users referenced in the users with view access field can view. And of course will have the users with edit access field too.

    Though I should still experiment with the selection sets of multiple access policies, as I would like to get a better idea of how that works and what it is like to implement.

  • 🇺🇸United States MegaKeegMan

    I realize I am saying a lot, but if you respond to anything, I think I am most curious about the answer to my question in comment 8:

    Would someone performing these bulk operations on group members require the permission to change the values in the user field?

  • 🇺🇸United States partdigital

    Would someone performing these bulk operations on group members require the permission to change the values in the user field?

    Apologies for the late reply, I'm currently on holiday.

    In your custom action you would be using the entity_autocomplete field widget so it's up to you how you want to handle the permissioning of that action. As far as which terms are available to that user, that should automatically be filtered for you as long as you've set up access policies for the taxonomy terms.

  • 🇺🇸United States MegaKeegMan

    I'm not sure yet that an access policy will be necessary for managing who can see which groups. Will there not be a way to just filter the view to only show terms that are in the current user's "group's managed" field (this is what I decided to call it).

    More specifically, my thoughts are that I want to restrict who can manage a group, but not who can view it (at least in the context of the bulk operations). To clarify, I may want a group to be publicly viewable by everyone, but I only want people who have the group in their "group's managed" field to be able to see it in their group management view.

    Perhaps I am mistaken, but this does not feel like something that should be handled by an access policy, but rather by a filter on the group management view. Though it is quite possible that there is yet again some nuance in configuring an access policy that I am not considering.

  • 🇺🇸United States MegaKeegMan

    Thinking about how to manage who are group managers and members per group. I think the view bulk operation method you mentioned is definitely worth considering. However, I am considering that simpler approach might be to use https://www.drupal.org/project/cer to sync the entity references between user and group. Will update once I have attempted this implementation. I am wondering how nicely this will work in a many to many situation.

  • 🇺🇸United States partdigital

    I've opened a discussion thread around groups, I've received a few related requests so I thought it might be useful to consolidate ideas into something cohesive.

    https://www.drupal.org/project/access_policy/issues/3419012 🌱 Discussion: Access policy group enhancements Active

  • Status changed to Postponed 5 months ago
Production build 0.69.0 2024