Merge pull request #3289 from fullfatthings/suppress_sso_welcome_emails

Add an sso option to suppress welcome emails
This commit is contained in:
Sam 2015-03-23 10:36:58 +11:00
commit 853c91d7d0
3 changed files with 25 additions and 3 deletions

View File

@ -60,7 +60,7 @@ class DiscourseSingleSignOn < SingleSignOn
if sso_record && (user = sso_record.user) && !user.active
user.active = true
user.save!
user.enqueue_welcome_message('welcome_user')
user.enqueue_welcome_message('welcome_user') unless suppress_welcome_message
end
custom_fields.each do |k,v|

View File

@ -1,8 +1,8 @@
class SingleSignOn
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update,
:about_me, :external_id, :return_sso_url, :admin, :moderator]
:about_me, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message]
FIXNUMS = []
BOOLS = [:avatar_force_update, :admin, :moderator]
BOOLS = [:avatar_force_update, :admin, :moderator, :suppress_welcome_message]
NONCE_EXPIRY_TIME = 10.minutes
attr_accessor(*ACCESSORS)

View File

@ -106,6 +106,28 @@ describe DiscourseSingleSignOn do
expect(sso.nonce).to_not be_nil
end
context 'welcome emails' do
let(:sso) {
sso = DiscourseSingleSignOn.new
sso.username = "test"
sso.name = "test"
sso.email = "test@example.com"
sso.external_id = "A"
sso
}
it "sends a welcome email by default" do
User.any_instance.expects(:enqueue_welcome_message).once
user = sso.lookup_or_create_user(ip_address)
end
it "suppresses the welcome email when asked to" do
User.any_instance.expects(:enqueue_welcome_message).never
sso.suppress_welcome_message = true
user = sso.lookup_or_create_user(ip_address)
end
end
context 'when sso_overrides_avatar is enabled' do
let!(:sso_record) { Fabricate(:single_sign_on_record, external_avatar_url: "http://example.com/an_image.png") }
let!(:sso) {