# Automatisch groepslidmaatschap toestaan op basis van subdomein

**URL:** https://meta.discourse.org/t/allow-automatic-group-membership-based-on-subdomain/213615
**Category:** Feature
**Created:** [1 januari 2022 om 23:33 UTC](https://meta.discourse.org/t/allow-automatic-group-membership-based-on-subdomain/213615 "2022-01-01T23:33:33Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [1 januari 2022 om 23:33 UTC](https://meta.discourse.org/t/allow-automatic-group-membership-based-on-subdomain/213615/1 "2022-01-01T23:33:33Z")

</div>

Continuing the discussion from [Automatically add users to group based on part of email domain](https://meta.discourse.org/t/automatically-add-users-to-group-based-on-part-of-email-domain/211166/3):

# Proposal

At the minute the group membership setting “Users who register with an email domain that exactly matches one in this list will be automatically added to this group” – where the admin wants to match `example.com` – only matches second-level domains like `email@example.com`.

I propose that this be changed also to match subdomains, e.g. `email@sub.example.com`.

# Reason/benefits

1. It would not be feasible for me manually to type in the subdomains for two government-related domains in particular: each has hundreds of subdomains, which are constantly changing, and the full list is not publicly available.

2. It would provide consistency with `email_domains_whitelist`, as noted by @sam in [Automatic registration domain wild card - #3 by sam](https://meta.discourse.org/t/automatic-registration-domain-wild-card/146933/3)

# Proposed solutions

This is possible by a minor amendment to `pattern = "@(#{domains.gsub('.', '\.')})$"` at [discourse/discourse/blob/20de49c8722f8e50e93732702a8d06570376edcd/app/models/group.rb#L1017](https://github.com/discourse/discourse/blob/20de49c8722f8e50e93732702a8d06570376edcd/app/models/group.rb#L1017)

1. Changing this to `pattern = "@.*(#{domains.gsub('.', '\.')})$"` worked for me when I tested it on my forum.

2. I imagine that `pattern = "@(.+\\.)?(#{domains.gsub('.', '\.')})$"` (based on `email_domains_whitelist`) would also work but I only noticed that later and haven’t tested it. I don’t understand why it’s not `(.+\.)?` but maybe the `\\` is a Ruby thing.

An alternative (if you were worried about users who currently _intend_ to exclude subdomains from automatic membership) would be to allow wildcards, e.g. to type `*.domain.com` for automatic group membership.

# Thanks

Thanks for considering this request.

---

_[View the full topic](https://meta.discourse.org/t/allow-automatic-group-membership-based-on-subdomain/213615)._
