Commit c22914e74f0c6a4945c0c34a58c69eb251211388
1 parent
9e3ed259
Exists in
master
and in
22 other branches
rails3: moving task_mailer to mailers folder
Showing
2 changed files
with
62 additions
and
62 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | +class TaskMailer < ActionMailer::Base | |
| 2 | + | |
| 3 | + def target_notification(task, message) | |
| 4 | + @message = extract_message(message) | |
| 5 | + @target = task.target.name | |
| 6 | + @environment = task.environment.name | |
| 7 | + @url = generate_environment_url(task, :controller => 'home') | |
| 8 | + url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url) | |
| 9 | + @tasks_url = url_for_tasks_list | |
| 10 | + | |
| 11 | + mail( | |
| 12 | + to: task.target.notification_emails, | |
| 13 | + from: self.class.generate_from(task), | |
| 14 | + subject: "[%s] %s" % [task.environment.name, task.target_notification_description] | |
| 15 | + ) | |
| 16 | + end | |
| 17 | + | |
| 18 | + def invitation_notification(task) | |
| 19 | + msg = task.expanded_message | |
| 20 | + @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) | |
| 21 | + | |
| 22 | + mail( | |
| 23 | + to: task.friend_email, | |
| 24 | + from: self.class.generate_from(task), | |
| 25 | + subject: '[%s] %s' % [ task.requestor.environment.name, task.target_notification_description ] | |
| 26 | + ) | |
| 27 | + end | |
| 28 | + | |
| 29 | + def generic_message(name, task) | |
| 30 | + return if !task.respond_to?("#{name}_message") | |
| 31 | + | |
| 32 | + @message = extract_message(task.send("#{name}_message")) | |
| 33 | + @requestor = task.requestor.name | |
| 34 | + @environment = task.requestor.environment.name | |
| 35 | + @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') | |
| 36 | + | |
| 37 | + mail( | |
| 38 | + to: task.requestor.notification_emails, | |
| 39 | + from: self.class.generate_from(task), | |
| 40 | + subject: '[%s] %s' % [task.requestor.environment.name, task.target_notification_description] | |
| 41 | + ) | |
| 42 | + end | |
| 43 | + | |
| 44 | + protected | |
| 45 | + | |
| 46 | + def extract_message(message) | |
| 47 | + if message.kind_of?(Proc) | |
| 48 | + self.instance_eval(&message) | |
| 49 | + else | |
| 50 | + message.to_s | |
| 51 | + end | |
| 52 | + end | |
| 53 | + | |
| 54 | + def self.generate_from(task) | |
| 55 | + "#{task.environment.name} <#{task.environment.contact_email}>" | |
| 56 | + end | |
| 57 | + | |
| 58 | + def generate_environment_url(task, url = {}) | |
| 59 | + url_for(Noosfero.url_options.merge(:host => task.environment.default_hostname).merge(url)) | |
| 60 | + end | |
| 61 | + | |
| 62 | +end | ... | ... |
app/models/task_mailer.rb
| ... | ... | @@ -1,62 +0,0 @@ |
| 1 | -class TaskMailer < ActionMailer::Base | |
| 2 | - | |
| 3 | - def target_notification(task, message) | |
| 4 | - @message = extract_message(message) | |
| 5 | - @target = task.target.name | |
| 6 | - @environment = task.environment.name | |
| 7 | - @url = generate_environment_url(task, :controller => 'home') | |
| 8 | - url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url) | |
| 9 | - @tasks_url = url_for_tasks_list | |
| 10 | - | |
| 11 | - mail( | |
| 12 | - to: task.target.notification_emails, | |
| 13 | - from: self.class.generate_from(task), | |
| 14 | - subject: "[%s] %s" % [task.environment.name, task.target_notification_description] | |
| 15 | - ) | |
| 16 | - end | |
| 17 | - | |
| 18 | - def invitation_notification(task) | |
| 19 | - msg = task.expanded_message | |
| 20 | - @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) | |
| 21 | - | |
| 22 | - mail( | |
| 23 | - to: task.friend_email, | |
| 24 | - from: self.class.generate_from(task), | |
| 25 | - subject: '[%s] %s' % [ task.requestor.environment.name, task.target_notification_description ] | |
| 26 | - ) | |
| 27 | - end | |
| 28 | - | |
| 29 | - def generic_message(name, task) | |
| 30 | - return if !task.respond_to?("#{name}_message") | |
| 31 | - | |
| 32 | - @message = extract_message(task.send("#{name}_message")) | |
| 33 | - @requestor = task.requestor.name | |
| 34 | - @environment = task.requestor.environment.name | |
| 35 | - @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') | |
| 36 | - | |
| 37 | - mail( | |
| 38 | - to: task.requestor.notification_emails, | |
| 39 | - from: self.class.generate_from(task), | |
| 40 | - subject: '[%s] %s' % [task.requestor.environment.name, task.target_notification_description] | |
| 41 | - ) | |
| 42 | - end | |
| 43 | - | |
| 44 | - protected | |
| 45 | - | |
| 46 | - def extract_message(message) | |
| 47 | - if message.kind_of?(Proc) | |
| 48 | - self.instance_eval(&message) | |
| 49 | - else | |
| 50 | - message.to_s | |
| 51 | - end | |
| 52 | - end | |
| 53 | - | |
| 54 | - def self.generate_from(task) | |
| 55 | - "#{task.environment.name} <#{task.environment.contact_email}>" | |
| 56 | - end | |
| 57 | - | |
| 58 | - def generate_environment_url(task, url = {}) | |
| 59 | - url_for(Noosfero.url_options.merge(:host => task.environment.default_hostname).merge(url)) | |
| 60 | - end | |
| 61 | - | |
| 62 | -end |