FIX: Allow longer TLDs

This commit is contained in:
Robin Ward 2016-04-08 12:11:58 -04:00
parent ab11cea5b9
commit adb3810f67
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
2 changed files with 10 additions and 5 deletions

View File

@ -399,7 +399,7 @@ class Group < ActiveRecord::Base
domains.each do |domain|
domain.sub!(/^https?:\/\//, '')
domain.sub!(/\/.*$/, '')
self.errors.add :base, (I18n.t('groups.errors.invalid_domain', domain: domain)) unless domain =~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\Z/i
self.errors.add :base, (I18n.t('groups.errors.invalid_domain', domain: domain)) unless domain =~ /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,24}(:[0-9]{1,5})?(\/.*)?\Z/i
end
self.automatic_membership_email_domains = domains.join("|")
end

View File

@ -60,6 +60,11 @@ describe Group do
expect(group.valid?).to eq true
end
it "is valid for newer TLDs" do
group.automatic_membership_email_domains = "discourse.institute"
expect(group.valid?).to eq true
end
it "is invalid for bad incoming email" do
group.incoming_email = "foo.bar.org"
expect(group.valid?).to eq(false)
@ -234,20 +239,20 @@ describe Group do
groups = Group.includes(:users).to_a
expect(groups.count).to eq Group::AUTO_GROUPS.count
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:admins]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:admins]}
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:staff]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:staff]}
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_1]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_1]}
# admin, system and user
expect(g.users.count).to eq 3
expect(g.user_count).to eq 3
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_2]}
g = groups.find{|grp| grp.id == Group::AUTO_GROUPS[:trust_level_2]}
# system and user
expect(g.users.count).to eq 2
expect(g.user_count).to eq 2