comparison app/models/mailer.rb @ 949:ebfda4c68b7a bug_505

Fixes Bug #505 (introduced in Bug #97): now also sends emails to all users members of a group when the group is added to a project.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 02 Aug 2012 19:40:23 +0100
parents ec1c49528f36
children bb32da3bea34
comparison
equal deleted inserted replaced
948:83866d58f2dd 949:ebfda4c68b7a
30 h = Setting.host_name 30 h = Setting.host_name
31 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? 31 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
32 { :host => h, :protocol => Setting.protocol } 32 { :host => h, :protocol => Setting.protocol }
33 end 33 end
34 34
35 35 # todo: luisf: 2Aug2012 - refactor...
36 def added_to_project(member, project)
37 principal = Principal.find(member.user_id)
38
39 if principal.type == "User"
40 user = User.find(member.user_id)
41 user_add_to_project(user, project)
42 else
43 users = Principal.find(member.user_id).users
44 users.map {|user| user_add_to_project(user, project) }
45 end
46 end
36 47
37 # Builds a tmail object used to email the specified user that he was added to a project 48 # Builds a tmail object used to email the specified user that he was added to a project
38 # 49 #
39 # Example: 50 # Example:
40 # add_to_project(user) => tmail object 51 # user_add_to_project(user, project) => tmail object
41 # Mailer.deliver_add_to_project(user) => sends an email to the registered user 52 # Mailer.deliver_add_to_project(user, project) => sends an email to the registered user
42 def added_to_project(member, project) 53 def user_add_to_project(user, project)
43
44 user = User.find(member.user_id)
45
46 set_language_if_valid user.language 54 set_language_if_valid user.language
47 recipients user.mail 55 recipients user.mail
48 subject l(:mail_subject_added_to_project, Setting.app_title) 56 subject l(:mail_subject_added_to_project, Setting.app_title)
49 body :project_url => url_for(:controller => 'projects', :action => 'show', :id => project.id), 57 body :project_url => url_for(:controller => 'projects', :action => 'show', :id => project.id),
50 :project_name => project.name 58 :project_name => project.name
51 render_multipart('added_to_project', body) 59 render_multipart('added_to_project', body)
52 end 60 end
53
54
55 61
56 # Builds a tmail object used to email recipients of the added issue. 62 # Builds a tmail object used to email recipients of the added issue.
57 # 63 #
58 # Example: 64 # Example:
59 # issue_add(issue) => tmail object 65 # issue_add(issue) => tmail object