diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3031afdb85..0a7977eabd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -20,6 +20,7 @@ def create flash[:warning] = I18n.t('users_controller.account_migrated_create_new_password') redirect_to "/profile/edit" else + WelcomeMailer.notify_newcomer(@user).deliver_now flash[:notice] = I18n.t('users_controller.registration_successful').html_safe flash[:warning] = I18n.t('users_controller.spectralworkbench_or_mapknitter', :url1 => "'#{session[:openid_return_to]}'").html_safe if session[:openid_return_to] session[:openid_return_to] = nil diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 53b3cd7764..71ee8d34db 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -63,6 +63,15 @@ def feature(title) end end + def feature_node(title) + features = Node.where(type: 'feature', title: title) + if !features.empty? + return features.last + else + '' + end + end + def locale_name_pairs I18n.available_locales.map do |locale| [I18n.t('language', locale: locale), locale] diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb index d9641a2b76..a1fd775520 100644 --- a/app/mailers/welcome_mailer.rb +++ b/app/mailers/welcome_mailer.rb @@ -1,7 +1,7 @@ class WelcomeMailer < ActionMailer::Base helper :application include ApplicationHelper - # default from: "notifications@#{ActionMailer::Base.default_url_options[:host]}" + default from: "notifications@#{ActionMailer::Base.default_url_options[:host]}" # PasswordResetMailer.reset_notify(user).deliver_now def add_to_list(user, list) @@ -10,4 +10,12 @@ def add_to_list(user, list) @footer = feature('email-footer') mail(to: list + '+subscribe@googlegroups.com', subject: subject, from: user.email) end + + def notify_newcomer(user) + subject = 'Welcome to Public Lab' + @user = user + @footer = feature('email-footer') + @body = feature_node('welcome-email-body') + mail(to: user.email, subject: subject) + end end diff --git a/app/views/welcome_mailer/notify_newcomer.html.erb b/app/views/welcome_mailer/notify_newcomer.html.erb new file mode 100644 index 0000000000..49f0854089 --- /dev/null +++ b/app/views/welcome_mailer/notify_newcomer.html.erb @@ -0,0 +1,4 @@ + +<%= raw auto_link(@body.latest.render_body_email(ActionMailer::Base.default_url_options[:host]), sanitize: false) %> + +<%= @footer %> \ No newline at end of file diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index cb8ce965ed..9de6bd7cf6 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -248,3 +248,13 @@ draft: type: "note" cached_likes: 0 slug: test-<%= Time.now.strftime("%m-%d-%Y") %>-draft-note token:briRpnTHzKHepo6-j8-b5w + +welcome_feature: + nid: 22 + uid: 1 + title: "welcome-email-body" + created: <%= Time.now.to_i %> + changed: <%= Time.now.to_i %> + status: 1 + type: "feature" + cached_likes: 0 diff --git a/test/fixtures/revisions.yml b/test/fixtures/revisions.yml index 4a44a5044e..8f39094f1b 100644 --- a/test/fixtures/revisions.yml +++ b/test/fixtures/revisions.yml @@ -270,3 +270,10 @@ checkbox_two: # Heading 1 List of things * [x] + +email_body: + nid: 22 + uid: 1 + title: "welcome-email-body" + body: Welcome email body + timestamp: <%= (Time.now - 1.week).to_i %> diff --git a/test/unit/welcome_mailer_test.rb b/test/unit/welcome_mailer_test.rb new file mode 100644 index 0000000000..8512dbc986 --- /dev/null +++ b/test/unit/welcome_mailer_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class WelcomeMailerTest < ActionMailer::TestCase + + test 'notify newcomer with welcome email' do + user = users(:bob) + @body = nodes(:welcome_feature) + + assert_difference 'ActionMailer::Base.deliveries.size', 1 do + WelcomeMailer.notify_newcomer(user).deliver_now + end + assert !ActionMailer::Base.deliveries.empty? + + email = ActionMailer::Base.deliveries.last + assert_equal ["notifications@#{request_host}"], email.from + assert_equal [user.email], email.to + assert_equal "Welcome to Public Lab", email.subject + assert email.body.include?("Welcome email body") + end +end