# HG changeset patch # User luisf # Date 1300901893 0 # Node ID f3b2dc533e83dec436f455a02e4b37a0a2c04887 # Parent f7e79424e7536f20226160b1fd882949b98fa9d8 added feature to send mails to user when added to project; TODO: need to create template. diff -r f7e79424e753 -r f3b2dc533e83 app/controllers/members_controller.rb --- a/app/controllers/members_controller.rb Tue Mar 22 14:16:09 2011 +0000 +++ b/app/controllers/members_controller.rb Wed Mar 23 17:38:13 2011 +0000 @@ -28,12 +28,24 @@ attrs = params[:member].dup if (user_ids = attrs.delete(:user_ids)) user_ids.each do |user_id| - members << Member.new(attrs.merge(:user_id => user_id)) + @new_member = Member.new(attrs.merge(:user_id => user_id)) + members << @new_member + + # send notification to member + Mailer.deliver_add_to_project(@new_member, @project) + end else - members << Member.new(attrs) + @new_member = Member.new(attrs) + members << @new_member + + # send notification to member + Mailer.deliver_add_to_project(@new_member, @project) + end + @project.members << members + end respond_to do |format| if members.present? && members.all? {|m| m.valid? } diff -r f7e79424e753 -r f3b2dc533e83 app/models/mailer.rb --- a/app/models/mailer.rb Tue Mar 22 14:16:09 2011 +0000 +++ b/app/models/mailer.rb Wed Mar 23 17:38:13 2011 +0000 @@ -31,6 +31,27 @@ h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? { :host => h, :protocol => Setting.protocol } end + + + + # Builds a tmail object used to email the specified user that he was added to a project + # + # Example: + # add_to_project(user) => tmail object + # Mailer.deliver_add_to_project(user) => sends an email to the registered user + def add_to_project(member, project) + + user = User.find(member.user_id) + + set_language_if_valid user.language + recipients user.mail + subject l(:mail_subject_register, Setting.app_title) + body :user => user, + :login_url => url_for(:controller => 'account', :action => 'login') + render_multipart('account_activated', body) + end + + # Builds a tmail object used to email recipients of the added issue. # @@ -440,3 +461,7 @@ end end end + + + +