Merge pull request #4969 from opf/fix/subtask_notification_wp_link

execute wp notifications as recipient for permissions
pull/4979/head
Oliver Günther 8 years ago committed by GitHub
commit f03d9de5ac
  1. 52
      app/mailers/user_mailer.rb
  2. 27
      spec/models/work_package/work_package_notifications_spec.rb
  3. 12
      spec_legacy/functional/user_mailer_spec.rb

@ -49,46 +49,52 @@ class UserMailer < BaseMailer
end
def work_package_added(user, journal, author)
work_package = journal.journable.reload
@issue = work_package # instance variable is used in the view
@journal = journal
User.execute_as user do
work_package = journal.journable.reload
@issue = work_package # instance variable is used in the view
@journal = journal
set_work_package_headers(work_package)
set_work_package_headers(work_package)
message_id work_package, user
message_id work_package, user
with_locale_for(user) do
mail_for_author author, to: user.mail, subject: subject_for_work_package(work_package)
with_locale_for(user) do
mail_for_author author, to: user.mail, subject: subject_for_work_package(work_package)
end
end
end
def work_package_updated(user, journal, author = User.current)
work_package = journal.journable.reload
User.execute_as user do
work_package = journal.journable.reload
# instance variables are used in the view
@issue = work_package
@journal = journal
# instance variables are used in the view
@issue = work_package
@journal = journal
set_work_package_headers(work_package)
set_work_package_headers(work_package)
message_id journal, user
references work_package, user
message_id journal, user
references work_package, user
with_locale_for(user) do
mail_for_author author, to: user.mail, subject: subject_for_work_package(work_package)
with_locale_for(user) do
mail_for_author author, to: user.mail, subject: subject_for_work_package(work_package)
end
end
end
def work_package_watcher_added(work_package, user, watcher_setter)
@issue = work_package
@watcher_setter = watcher_setter
User.execute_as user do
@issue = work_package
@watcher_setter = watcher_setter
set_work_package_headers(work_package)
message_id work_package, user
references work_package, user
set_work_package_headers(work_package)
message_id work_package, user
references work_package, user
with_locale_for(user) do
mail to: user.mail, subject: subject_for_work_package(work_package)
with_locale_for(user) do
mail to: user.mail, subject: subject_for_work_package(work_package)
end
end
end

@ -59,5 +59,32 @@ describe WorkPackage, type: :model do
expect(mail).to be_present
end
end
describe 'notification triggered by subtask update' do
let!(:child) do
FactoryGirl.create :work_package, subject: "I'm a child",
parent: work_package,
done_ratio: 42
end
let(:message) { "Updated automatically by changing values within child work package" }
let(:label) { "##{child.id}" }
let(:href) { "/work_packages/#{child.id}" }
let(:link_regex) { /#{message} <a[^<]*href="[^"]*#{href}"[^<]*>#{label}<\/a>/ }
before do
child.update_attributes done_ratio: 99
end
it "sends out an email including a link to the subtask" do
matching_part = ->(part) { part.sub_type == "html" && part.to_s =~ link_regex }
matching_mail = ->(mail) { mail.body.parts.find(&matching_part) }
mail = ActionMailer::Base.deliveries.find(&matching_mail)
expect(mail).to be_present
end
end
end
end

@ -42,12 +42,10 @@ describe UserMailer, type: :mailer do
WorkPackage.delete_all
Project.delete_all
::Type.delete_all
User.current = User.anonymous
end
it 'should test mail sends a simple greeting' do
user = FactoryGirl.create(:user, mail: 'foo@bar.de')
user = FactoryGirl.create(:admin, mail: 'foo@bar.de')
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
@ -66,7 +64,6 @@ describe UserMailer, type: :mailer do
Setting.default_language = 'en'
Setting.host_name = 'mydomain.foo'
Setting.protocol = 'https'
User.current = FactoryGirl.create(:admin)
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
@ -109,7 +106,6 @@ describe UserMailer, type: :mailer do
Setting.default_language = 'en'
Setting.host_name = 'mydomain.foo/rdm'
Setting.protocol = 'http'
User.current = FactoryGirl.create(:admin)
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
@ -156,8 +152,6 @@ describe UserMailer, type: :mailer do
Setting.protocol = 'http'
OpenProject::Configuration['rails_relative_url_root'] = nil
User.current = FactoryGirl.create(:admin)
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
assert UserMailer.work_package_updated(user, journal).deliver_now
@ -251,7 +245,6 @@ describe UserMailer, type: :mailer do
# notify him
user.pref[:no_self_notified] = false
user.pref.save
User.current = user
ActionMailer::Base.deliveries.clear
UserMailer.news_added(user, news, user).deliver_now
assert_equal 1, last_email.to.size
@ -259,7 +252,6 @@ describe UserMailer, type: :mailer do
# nobody to notify
user.pref[:no_self_notified] = true
user.pref.save
User.current = user
ActionMailer::Base.deliveries.clear
UserMailer.news_added(user, news, user).deliver_now
assert ActionMailer::Base.deliveries.empty?
@ -470,7 +462,7 @@ describe UserMailer, type: :mailer do
def setup_complex_issue_update
project = FactoryGirl.create(:valid_project)
user = FactoryGirl.create(:user, member_in_project: project)
user = FactoryGirl.create(:admin, member_in_project: project)
type = FactoryGirl.create(:type, name: 'My Type')
project.types << type
project.save

Loading…
Cancel
Save