Continuing the discussion from Automatically add users to group based on part of email domain:
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
-
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.
-
It would provide consistency with
email_domains_whitelist
, as noted by @sam in Automatic registration domain wild card - #3 by samYeah there is an inconsistency internally, our automatic group membership is based off a strict domain match per:
Our matcher for the
email_domains_whitelist
uses this matchI think it makes sense to make this coherent and consistent.
@techAPJ can you adjust the group regex… carefully and make sure it is tested so it also allows subdomains.
Proposed solutions
This is possible by a minor amendment to pattern = "@(#{domains.gsub('.', '\.')})$"
at discourse/discourse/blob/20de49c8722f8e50e93732702a8d06570376edcd/app/models/group.rb#L1017
-
Changing this to
pattern = "@.*(#{domains.gsub('.', '\.')})$"
worked for me when I tested it on my forum. -
I imagine that
pattern = "@(.+\\.)?(#{domains.gsub('.', '\.')})$"
(based onemail_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.