mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add setting auto_approve_email_domains to auto approve users (#9323)
* FEATURE: add setting `auto_approve_email_domains` to auto approve users This commit adds a new site setting `auto_approve_email_domains` to auto approve users based on their email address domain. Note that if a domain already exists in `email_domains_whitelist` then `auto_approve_email_domains` needs to be duplicated there as well, since users won’t be able to register with email address that is not allowed in `email_domains_whitelist`. * Update config/locales/server.en.yml Co-Authored-By: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
@@ -583,7 +583,7 @@ describe UsersController do
|
||||
UsersController.any_instance.stubs(:honeypot_value).returns(nil)
|
||||
UsersController.any_instance.stubs(:challenge_value).returns(nil)
|
||||
SiteSetting.allow_new_registrations = true
|
||||
@user = Fabricate.build(:user, password: "strongpassword")
|
||||
@user = Fabricate.build(:user, email: "foobar@example.com", password: "strongpassword")
|
||||
end
|
||||
|
||||
let(:post_user_params) do
|
||||
@@ -826,6 +826,22 @@ describe UsersController do
|
||||
new_user = User.find(json["user_id"])
|
||||
expect(new_user.locale).not_to eq("fr")
|
||||
end
|
||||
|
||||
it "will auto approve user if the user email domain matches auto_approve_email_domains setting" do
|
||||
Jobs.run_immediately!
|
||||
SiteSetting.must_approve_users = true
|
||||
SiteSetting.auto_approve_email_domains = "example.com"
|
||||
|
||||
post "/u.json", params: post_user_params.merge(active: true, api_key: api_key.key)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
new_user = User.find(json["user_id"])
|
||||
expect(json['active']).to be_truthy
|
||||
expect(new_user.approved).to be_truthy
|
||||
expect(ReviewableUser.pending.find_by(target: new_user)).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user