diff app/models/mailer.rb @ 1116:bb32da3bea34 redmine-2.2-integration

Merge from live
author Chris Cannam
date Mon, 07 Jan 2013 14:41:20 +0000
parents 433d4f72a19b ebfda4c68b7a
children b2f7f52a164d
line wrap: on
line diff
--- a/app/models/mailer.rb	Mon Jan 07 12:01:42 2013 +0000
+++ b/app/models/mailer.rb	Mon Jan 07 14:41:20 2013 +0000
@@ -27,6 +27,33 @@
     { :host => Setting.host_name, :protocol => Setting.protocol }
   end
 
+  # todo: luisf: 2Aug2012 - refactor...
+  def added_to_project(member, project)
+    principal = Principal.find(member.user_id)
+
+    if principal.type == "User"
+      user = User.find(member.user_id)
+      user_add_to_project(user, project) 
+    else
+      users = Principal.find(member.user_id).users      
+      users.map {|user| user_add_to_project(user, project) }      
+    end
+  end
+
+  # Builds a tmail object used to email the specified user that he was added to a project
+  #
+  # Example:
+  #   user_add_to_project(user, project) => tmail object
+  #   Mailer.deliver_add_to_project(user, project) => sends an email to the registered user
+  def user_add_to_project(user, project)        
+    set_language_if_valid user.language
+    recipients user.mail
+    subject l(:mail_subject_added_to_project, Setting.app_title)
+    body :project_url => url_for(:controller => 'projects', :action => 'show', :id => project.id),
+        :project_name => project.name
+    render_multipart('added_to_project', body)
+  end
+  
   # Builds a Mail::Message object used to email recipients of the added issue.
   #
   # Example:
@@ -472,3 +499,17 @@
     Rails.logger
   end
 end
+
+# Patch TMail so that message_id is not overwritten
+
+### NB: Redmine 2.2 no longer uses TMail I think? This function has
+### been removed there
+
+module TMail
+  class Mail
+    def add_message_id( fqdn = nil )
+      self.message_id ||= ::TMail::new_message_id(fqdn)
+    end
+  end
+end
+