updated news added mailings

pull/1186/head
Martin Linkhorst 12 years ago
parent 727a232d3d
commit 1f8666e2d2
  1. 19
      app/mailers/user_mailer.rb
  2. 2
      app/models/news_observer.rb
  3. 4
      app/views/mailer/news_added.html.erb
  4. 4
      app/views/user_mailer/news_added.html.erb
  5. 2
      app/views/user_mailer/news_added.text.erb
  6. 24
      test/functional/user_mailer_test.rb

@ -89,6 +89,25 @@ class UserMailer < ActionMailer::Base
mail :to => to, :subject => subject mail :to => to, :subject => subject
end end
end end
def news_added(user, news)
@news = news
headers["X-OpenProject-Project"] = news.project.identifier
headers["X-OpenProject-Type"] = "News"
#message_id news
to = user.mail
locale = user.language.presence || I18n.default_locale
I18n.with_locale(locale) do
subject = "[#{news.project.name}] #{t(:label_news)}: #{news.title}"
mail :to => to, :subject => subject
end
end
private private

@ -17,7 +17,7 @@ class NewsObserver < ActiveRecord::Observer
if Setting.notified_events.include?('news_added') if Setting.notified_events.include?('news_added')
users = User.find_all_by_mails(news.recipients) users = User.find_all_by_mails(news.recipients)
users.each do |user| users.each do |user|
Mailer.deliver_news_added(news, user) UserMailer.news_added(user, news).deliver
end end
end end
end end

@ -1,4 +0,0 @@
<h1><%= link_to(h(@news.title), @news_url) %></h1>
<em><%=h @news.author.name %></em>
<%= textilizable(@news, :description, :only_path => false) %>

@ -0,0 +1,4 @@
<h1><%= link_to @news.title, news_url(@news) %></h1>
<em><%= @news.author.name %></em>
<%= textilizable @news.description %>

@ -1,5 +1,5 @@
<%= @news.title %> <%= @news.title %>
<%= @news_url %> <%= news_url(@news) %>
<%= @news.author.name %> <%= @news.author.name %>
<%= @news.description %> <%= @news.description %>

@ -147,6 +147,30 @@ class UserMailerTest < ActionMailer::TestCase
mail mail
end end
def test_news_added
news = News.find(:first)
assert UserMailer.news_added(@user, news).deliver
end
def test_should_not_send_email_without_recipient
news = News.find(:first)
user = news.author
# Remove members except news author
news.project.memberships.each {|m| m.destroy unless m.user == user}
user.pref[:no_self_notified] = false
user.pref.save
User.current = user
UserMailer.news_added(user, news.reload).deliver
assert_equal 1, last_email.to.size
# nobody to notify
user.pref[:no_self_notified] = true
user.pref.save
User.current = user
ActionMailer::Base.deliveries.clear
UserMailer.news_added(user, news.reload).deliver
assert ActionMailer::Base.deliveries.empty?
end
end end

Loading…
Cancel
Save