From d53c4e9aaeb66afacf38db4f269ff3506eff866a Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 2 Feb 2011 15:57:26 -0800 Subject: [PATCH] [#792] Add confirmation emails for successful issue creation --- app/models/mail_handler.rb | 1 + app/models/mailer.rb | 9 +++++++ .../mail_handler_confirmation.text.html.rhtml | 2 ++ ...mail_handler_confirmation.text.plain.rhtml | 2 ++ config/locales/en.yml | 6 +++-- test/unit/mail_handler_test.rb | 27 ++++++++++++++++++- 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 app/views/mailer/mail_handler_confirmation.text.html.rhtml create mode 100644 app/views/mailer/mail_handler_confirmation.text.plain.rhtml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 4686811d..1fc88c25 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -141,6 +141,7 @@ class MailHandler < ActionMailer::Base issue.save! add_attachments(issue) logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info + Mailer.deliver_mail_handler_confirmation(issue, user, issue.subject) if Setting.mail_handler_confirmation_on_success issue end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c4bba852..b7716ab9 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -285,6 +285,15 @@ class Mailer < ActionMailer::Base render_multipart('register', body) end + def mail_handler_confirmation(object, user, email_subject) + recipients user.mail + project = object.try(:project).try(:name) || '' + subject "[#{project}] #{l(:label_mail_handler_confirmation, :subject => email_subject)}" + body(:object => object, + :url => url_for(:controller => 'issues', :action => 'show', :id => object.id)) + render_multipart('mail_handler_confirmation', body) + end + def test(user) redmine_headers 'Type' => "Test" set_language_if_valid(user.language) diff --git a/app/views/mailer/mail_handler_confirmation.text.html.rhtml b/app/views/mailer/mail_handler_confirmation.text.html.rhtml new file mode 100644 index 00000000..5e115e2b --- /dev/null +++ b/app/views/mailer/mail_handler_confirmation.text.html.rhtml @@ -0,0 +1,2 @@ +

<%= l(:text_mail_handler_confirmation_successful) %>
+<%= auto_link(@url) %>

diff --git a/app/views/mailer/mail_handler_confirmation.text.plain.rhtml b/app/views/mailer/mail_handler_confirmation.text.plain.rhtml new file mode 100644 index 00000000..0b8348e4 --- /dev/null +++ b/app/views/mailer/mail_handler_confirmation.text.plain.rhtml @@ -0,0 +1,2 @@ +<%= l(:text_mail_handler_confirmation_successful) %> +<%= @url %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c167c53..7625455e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -818,7 +818,8 @@ en: label_path_encoding: Path encoding label_deleted_custom_field: '(deleted custom field)' label_toc: "Contents" - + label_mail_handler_confirmation: "Confirmation of email submission: {{subject}}" + button_login: Login button_submit: Submit button_save: Save @@ -943,7 +944,8 @@ en: text_git_repo_example: "a bare and local repository (e.g. /gitrepo, c:\\gitrepo)" text_display_subprojects: Display subprojects text_current_project: Current project - + text_mail_handler_confirmation_successful: "Your email has been successful added at the following url" + default_role_manager: Manager default_role_developer: Developer default_role_reporter: Reporter diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index a4e68542..b51b1ef6 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -39,6 +39,8 @@ class MailHandlerTest < ActiveSupport::TestCase def setup ActionMailer::Base.deliveries.clear Setting.notified_events = Redmine::Notifiable.all.collect(&:name) + Setting.mail_handler_confirmation_on_success = true + Setting.mail_handler_confirmation_on_failure = true end def test_add_issue @@ -67,6 +69,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert !issue.description.match(/^Status:/i) assert !issue.description.match(/^Start Date:/i) # Email notification should be sent + assert_equal 2, ActionMailer::Base.deliveries.size mail = ActionMailer::Base.deliveries.last assert_not_nil mail assert mail.subject.include?('New ticket on a given project') @@ -289,7 +292,7 @@ class MailHandlerTest < ActiveSupport::TestCase # This email contains: 'Project: onlinestore' issue = submit_email('ticket_on_given_project.eml') assert issue.is_a?(Issue) - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_add_issue_note @@ -456,6 +459,28 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255] end + context "#receive_issue" do + should "deliver an email confirmation when configured" do + ActionMailer::Base.deliveries.clear + issue = submit_email('ticket_on_given_project.eml') + + assert_equal 2, ActionMailer::Base.deliveries.size + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + assert mail.subject.include?('[OnlineStore]'), "Project name missing" + assert mail.subject.include?('Confirmation of email submission: New ticket on a given project'), "Main subject missing" + assert mail.body.include?("/issues/#{issue.reload.id}"), "Link to issue missing" + end + end + + context "#receive_issue_reply" do + should "deliver an email confirmation when configured" + end + + context "#receive_message_reply" do + should "deliver an email confirmation when configured" + end + private def submit_email(filename, options={})