# Hierarchical group membership (groups inside groups)

**URL:** https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263
**Category:** Support
**Created:** [March 5, 2021, 10:59pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263 "2021-03-05T22:59:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 5, 2021, 10:59pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/1 "2021-03-05T22:59:34Z")

</div>

For our running club, I’m coordinating a year-long challenge that has a team component. For each 10-year age-group team, I’m creating a Discourse group so they can be @mentioned and potentially have their own conversations, though I very much doubt anyone will figure that out. So I have seven groups for each of the age-group teams, and I have to update those manually as people register.

I also want to have an uber-group that contains all the people who are participating in the challenge. It would be a LOT easier if I could have the larger Challengers group merely contain the sub-groups for 19-and-under, 20-29, 30-39, and so on. That way I could just manage the sub-groups and have the changes flow through to the uber-group.

Is there (or could there be) a way to do this, or am I stuck having to manually type in every username from the sub-groups? (I think this will be several hundred people all told, and a weekly task.)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 6, 2021, 1:21am UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/2 "2021-03-06T01:21:46Z")

</div>

You should be same to use Bulk Add to Group, which will save you a lot of typing!

I don’t think we have plans to implement full hierarchical group membership resolution.

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 8, 2021, 8:31pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/3 "2021-03-08T20:31:38Z")

</div>

I keep being confused by references Bulk Add to Group, since it doesn’t appear in the UI as far as I can tell—the screenshots from the 2015 topic you linked to don’t match with what I see now. Is it just the same as using the Add Members dialog within a group?

And how can I copy a list of members of one group to be able to bulk add to another? The best workflow I can come up with at the moment is to copy the text of the Members page and use a style-savvy grep (in Nisus Writer Pro) to copy the usernames. Doable, but not exactly easy.

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [March 8, 2021, 9:11pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/4 "2021-03-08T21:11:20Z")

</div>

There are [quite a few references](https://meta.discourse.org/search?q=bulk%20add) to the “bulk add to group” feature here on Meta, but I don’t see it active anymore at `https://discourse.example.org/admin/groups/bulk`, just a blank page (I checked a couple different sites where I have admin rights). Do you see anything there @adamengst?

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 15, 2021, 5:33pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/5 "2021-03-15T17:33:01Z")

</div>

Sorry for the delay—missed the notification. No, I don’t have a page at

[https://forum.fingerlakesrunners.org/admin/groups/bulk](https://forum.fingerlakesrunners.org/admin/groups/bulk) at all (404), and the main groups page is at [FLRC Forum](https://forum.fingerlakesrunners.org/g)

No mention of Bulk Add anywhere that I can find.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [March 16, 2021, 4:30pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/6 "2021-03-16T16:30:47Z")

</div>

I guess this is a bit of a hidden feature, but you can use the bulk invite feature to add existing users to groups. Just prep a csv with the email address and group as explained in the modal, and upload it. The users will not be emailed.

 ![Screen Shot 2021-03-16 at 9.29.57 AM](https://global.discourse-cdn.com/meta/original/3X/0/0/003ea1082686913dd053205e37bd956d67c55f4a.png)

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [March 16, 2021, 4:33pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/7 "2021-03-16T16:33:52Z")

</div>

@tobiaseigen Aha! Do you happen to know if that would handle group updates for existing users if the email address in question already has an account?

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [March 16, 2021, 4:34pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/8 "2021-03-16T16:34:48Z")

</div>

Yes. That is precisely what I mean by this:

> [@tobiaseigen](#):
>
> you can use the bulk invite feature to add existing users to groups

This feature seems to be doing double duty and we can improve the UI. I will propose something.

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [March 16, 2021, 4:36pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/9 "2021-03-16T16:36:10Z")

</div>

Awesome, thanks! Off to LibreOffice Calc I go! ⌨

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 16, 2021, 5:04pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/11 "2021-03-16T17:04:03Z")

</div>

Thanks! That’s getting closer, although I’ll note that keying off email address often works poorly for me because lots of people have multiple addresses, so I have to verify ahead of time whether I’m inviting the one that’s associated with an account or another one that will be confusing (and potentially set them up with a second account).

I don’t know how the underlying foundation works, but it would seem simplest to allow groups to contain references to other groups.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [March 16, 2021, 5:19pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/13 "2021-03-16T17:19:49Z")

</div>

You could always do a user export and then use the exported CSV to create a new list to import back using the bulk invite feature. Sounds like you just need to do this once to get the system set up with your existing users, then manually when new people join or make a change to their age bracket.

Maye there’s a case for custom code to semi-automate this for your community - you could post a request in #Marketplace if you have a budget.

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 16, 2021, 7:52pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/14 "2021-03-16T19:52:44Z")

</div>

Good point on the user export—I wasn’t thinking about that as a way to populate the list with accounts to start. I’ll keep noodling on this and see how it works out.

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [November 26, 2022, 6:50am UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/15 "2022-11-26T06:50:09Z")

</div>

Hierarchical groups (groups as members of groups) would have the additional advantage of automatically removing members from inherited groups.

To implement such a feature “by hand”, you would have to remember whether a group membership was inherited by a hierarchically higher group or set directly.

Could you comment on using an external user directory service (ldap) to implement a hierarchical group function?

---

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [March 21, 2023, 7:00am UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/16 "2023-03-21T07:00:08Z")

</div>

@angus I’m wondering whether the [`GroupAssociatedGroup`](https://github.com/discourse/discourse/blob/main/app/models/group_associated_group.rb) already implements this thread’s intention.

[https://github.com/discourse/discourse/commit/df3886d6e5fca3e1ac2bb961997fcc52bfeff8c1](https://github.com/discourse/discourse/commit/df3886d6e5fca3e1ac2bb961997fcc52bfeff8c1)

> [@Managing group membership via authentication](https://meta.discourse.org/t/managing-group-membership-via-authentication/175950):
>
> @david Continuing the discussion from [https://github.com/discourse/discourse-openid-connect/pull/7#issuecomment-758082333](https://github.com/discourse/discourse-openid-connect/pull/7#issuecomment-758082333) As you probably can guess, I’m also keen to see a stable solution to this problem, which is not specific to the openid-connect plugin. Let’s see if we can figure out a way forward To pick up on the point you’ve raised. How do you decide which groups to add and remove the user from? And how does that affect manually adding/removing users from groups in Discourse itself? …

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [March 21, 2023, 7:54am UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/17 "2023-03-21T07:54:33Z")

</div>

No, that feature is concerned with the syncing of groups on external services with Discourse groups, not with group hierarchies.

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [March 21, 2023, 2:06pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/18 "2023-03-21T14:06:03Z")

</div>

Since I started this thread, I thought I’d just weigh in and say that my request for hierarchical groups is still completely relevant.

The Bulk Invite to Group feature simply doesn’t come into play because in my case, I’m adding people to specific age-based groups and an overall group that encompasses all the age-based groups over a 4-month time frame as they register in another system.

I’ll see if my developer can automate the process this year, now that I know how utterly tedious it is to do by hand on a weekly basis.

---

<div class="post-metadata">

### Author: ![Drew-ART](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Drew-ART](https://meta.discourse.org/u/Drew-ART)
#### Post date: [May 11, 2023, 9:03pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/19 "2023-05-11T21:03:00Z")

</div>

@adamengst Any progress here?

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [May 11, 2023, 10:11pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/20 "2023-05-11T22:11:36Z")

</div>

Yes, in fact my developer was able to sync up data from Webscorer, which we use for race registration, with Discourse groups. It requires that names match, but he built an admin page that shows when they don’t.

So there’s no hierarchy, but we’re populating multiple groups automatically, which removes the main need I had.

It’s open-source code so I can probably share it if anyone’s interested in seeing how it works.

---

<div class="post-metadata">

### Author: ![adamengst](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamengst/32/116607_2.png) [@adamengst](https://meta.discourse.org/u/adamengst)
#### Post date: [May 12, 2023, 6:48pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/21 "2023-05-12T18:48:46Z")

</div>

I got a direct request for this too, so if anyone would like to look at @SteveDesmond.ca’s code for writing into Discourse groups, it’s available at:

[https://github.com/FingerLakesRunnersClub/Leaderboards](https://github.com/FingerLakesRunnersClub/Leaderboards)

And Steve said he’s happy to answer questions about it.

---

<div class="post-metadata">

### Author: ![SteveDesmond.ca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevedesmond.ca/32/306761_2.png) [@SteveDesmond.ca](https://meta.discourse.org/u/SteveDesmond.ca)
#### Post date: [May 13, 2023, 5:25pm UTC](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263/22 "2023-05-13T17:25:10Z")

</div>

Here’s an outline for the [specific code](https://github.com/FingerLakesRunnersClub/Leaderboards/blob/ad375a74813c6495f8cba3527db7599958c34846/Web/Controllers/CommunityController.cs#L23-L84) Adam mentioned previously:

1. (L36) get all users in the external system
2. (L37) get all users in Discourse
3. (L38-39) get all members of the groups in question (`global` is the “supergroup” in this case)
4. (L46-78) for each user in the external system, check if they exist in Discourse, and map which groups they’re already part of and need to be added to

[Next page](https://meta.discourse.org/t/hierarchical-group-membership-groups-inside-groups/182263.md?page=2)
