Commit 5a2656838af2b75db0b96c101513ae33964d5959

Authored by Braulio Bhavamitra
1 parent a7264f26

rails4: use Noosfero::Mailer to set required default_url_options

app/mailers/comment_notifier.rb
1 -class CommentNotifier < ActionMailer::Base 1 +class CommentNotifier < Noosfero::Mailer
  2 +
2 def notification(comment) 3 def notification(comment)
3 profile = comment.article.profile 4 profile = comment.article.profile
  5 + self.environment = profile.environment
4 @recipient = profile.nickname || profile.name 6 @recipient = profile.nickname || profile.name
5 @sender = comment.author_name 7 @sender = comment.author_name
6 @sender_link = comment.author_link 8 @sender_link = comment.author_link
@@ -8,7 +10,6 @@ class CommentNotifier &lt; ActionMailer::Base @@ -8,7 +10,6 @@ class CommentNotifier &lt; ActionMailer::Base
8 @comment_url = comment.url 10 @comment_url = comment.url
9 @comment_title = comment.title 11 @comment_title = comment.title
10 @comment_body = comment.body 12 @comment_body = comment.body
11 - @environment = profile.environment.name  
12 @url = profile.environment.top_url 13 @url = profile.environment.top_url
13 14
14 mail( 15 mail(
@@ -20,6 +21,8 @@ class CommentNotifier &lt; ActionMailer::Base @@ -20,6 +21,8 @@ class CommentNotifier &lt; ActionMailer::Base
20 21
21 def mail_to_followers(comment, emails) 22 def mail_to_followers(comment, emails)
22 profile = comment.article.profile 23 profile = comment.article.profile
  24 + self.environment = profile.environment
  25 +
23 @recipient = profile.nickname || profile.name 26 @recipient = profile.nickname || profile.name
24 @sender = comment.author_name 27 @sender = comment.author_name
25 @sender_link = comment.author_link 28 @sender_link = comment.author_link
@@ -28,7 +31,6 @@ class CommentNotifier &lt; ActionMailer::Base @@ -28,7 +31,6 @@ class CommentNotifier &lt; ActionMailer::Base
28 @unsubscribe_url = comment.article.view_url.merge({:unfollow => true}) 31 @unsubscribe_url = comment.article.view_url.merge({:unfollow => true})
29 @comment_title = comment.title 32 @comment_title = comment.title
30 @comment_body = comment.body 33 @comment_body = comment.body
31 - @environment = profile.environment.name  
32 @url = profile.environment.top_url 34 @url = profile.environment.top_url
33 35
34 mail( 36 mail(
app/mailers/contact.rb
@@ -30,14 +30,16 @@ class Contact @@ -30,14 +30,16 @@ class Contact
30 Contact::Sender.notification(self).deliver 30 Contact::Sender.notification(self).deliver
31 end 31 end
32 32
33 - class Sender < ActionMailer::Base 33 + class Sender < Noosfero::Mailer
  34 +
34 def notification(contact) 35 def notification(contact)
  36 + self.environment = contact.dest.environment
  37 +
35 @name = contact.name 38 @name = contact.name
36 @email = contact.email 39 @email = contact.email
37 @city = contact.city 40 @city = contact.city
38 @state = contact.state 41 @state = contact.state
39 @message = contact.message 42 @message = contact.message
40 - @environment = contact.dest.environment.name  
41 @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home') 43 @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home')
42 @target = contact.dest.name 44 @target = contact.dest.name
43 45
app/mailers/mailing.rb
@@ -48,7 +48,8 @@ class Mailing &lt; ActiveRecord::Base @@ -48,7 +48,8 @@ class Mailing &lt; ActiveRecord::Base
48 end 48 end
49 end 49 end
50 50
51 - class Sender < ActionMailer::Base 51 + class Sender < Noosfero::Mailer
  52 +
52 def notification(mailing, recipient) 53 def notification(mailing, recipient)
53 @message = mailing.body 54 @message = mailing.body
54 @signature_message = mailing.signature_message 55 @signature_message = mailing.signature_message
app/mailers/pending_task_notifier.rb
1 -class PendingTaskNotifier < ActionMailer::Base 1 +class PendingTaskNotifier < Noosfero::Mailer
2 2
3 def notification(person) 3 def notification(person)
  4 + self.environment = person.environment
  5 +
4 @person = person 6 @person = person
5 @tasks = person.tasks.pending 7 @tasks = person.tasks.pending
6 @organizations_with_pending_tasks = person.organizations_with_pending_tasks 8 @organizations_with_pending_tasks = person.organizations_with_pending_tasks
7 - @environment = person.environment.name  
8 @url = url_for(:host => person.environment.default_hostname, :controller => 'home') 9 @url = url_for(:host => person.environment.default_hostname, :controller => 'home')
9 @default_hostname = person.environment.default_hostname 10 @default_hostname = person.environment.default_hostname
10 @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier) 11 @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier)
app/mailers/scrap_notifier.rb
1 -class ScrapNotifier < ActionMailer::Base 1 +class ScrapNotifier < Noosfero::Mailer
  2 +
2 def notification(scrap) 3 def notification(scrap)
3 sender, receiver = scrap.sender, scrap.receiver 4 sender, receiver = scrap.sender, scrap.receiver
  5 + self.environment = sender.environment
  6 +
4 @recipient = receiver.name 7 @recipient = receiver.name
5 @sender = sender.name 8 @sender = sender.name
6 @sender_link = sender.url 9 @sender_link = sender.url
7 @scrap_content = scrap.content 10 @scrap_content = scrap.content
8 @wall_url = scrap.scrap_wall_url 11 @wall_url = scrap.scrap_wall_url
9 - @environment = sender.environment.name  
10 @url = sender.environment.top_url 12 @url = sender.environment.top_url
11 mail( 13 mail(
12 to: receiver.email, 14 to: receiver.email,
app/mailers/task_mailer.rb
1 -class TaskMailer < ActionMailer::Base 1 +class TaskMailer < Noosfero::Mailer
2 2
3 def target_notification(task, message) 3 def target_notification(task, message)
  4 + self.environment = task.environment
  5 +
4 @message = extract_message(message) 6 @message = extract_message(message)
5 @target = task.target.name 7 @target = task.target.name
6 - @environment = task.environment.name  
7 @url = generate_environment_url(task, :controller => 'home') 8 @url = generate_environment_url(task, :controller => 'home')
8 url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/'))) 9 url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/')))
9 @tasks_url = url_for_tasks_list 10 @tasks_url = url_for_tasks_list
@@ -16,6 +17,8 @@ class TaskMailer &lt; ActionMailer::Base @@ -16,6 +17,8 @@ class TaskMailer &lt; ActionMailer::Base
16 end 17 end
17 18
18 def invitation_notification(task) 19 def invitation_notification(task)
  20 + self.environment = task.requestor.environment
  21 +
19 msg = task.expanded_message 22 msg = task.expanded_message
20 @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) 23 @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)
21 24
@@ -27,11 +30,12 @@ class TaskMailer &lt; ActionMailer::Base @@ -27,11 +30,12 @@ class TaskMailer &lt; ActionMailer::Base
27 end 30 end
28 31
29 def generic_message(name, task) 32 def generic_message(name, task)
  33 + self.environment = task.requestor.environment
  34 +
30 return if !task.respond_to?("#{name}_message") 35 return if !task.respond_to?("#{name}_message")
31 36
32 @message = extract_message(task.send("#{name}_message")) 37 @message = extract_message(task.send("#{name}_message"))
33 @requestor = task.requestor.name 38 @requestor = task.requestor.name
34 - @environment = task.requestor.environment.name  
35 @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') 39 @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home')
36 40
37 mail( 41 mail(
app/mailers/user_mailer.rb
1 -class UserMailer < ActionMailer::Base 1 +class UserMailer < Noosfero::Mailer
  2 +
2 def activation_email_notify(user) 3 def activation_email_notify(user)
  4 + self.environment = user.environment
  5 +
3 user_email = "#{user.login}@#{user.email_domain}" 6 user_email = "#{user.login}@#{user.email_domain}"
4 @name = user.name 7 @name = user.name
5 @email = user_email 8 @email = user_email
6 @webmail = MailConf.webmail_url(user.login, user.email_domain) 9 @webmail = MailConf.webmail_url(user.login, user.email_domain)
7 - @environment = user.environment.name  
8 @url = url_for(:host => user.environment.default_hostname, :controller => 'home') 10 @url = url_for(:host => user.environment.default_hostname, :controller => 'home')
9 11
10 mail( 12 mail(
@@ -15,9 +17,10 @@ class UserMailer &lt; ActionMailer::Base @@ -15,9 +17,10 @@ class UserMailer &lt; ActionMailer::Base
15 end 17 end
16 18
17 def activation_code(user) 19 def activation_code(user)
  20 + self.environment = user.environment
  21 +
18 @recipient = user.name 22 @recipient = user.name
19 @activation_code = user.activation_code 23 @activation_code = user.activation_code
20 - @environment = user.environment.name  
21 @url = user.environment.top_url 24 @url = user.environment.top_url
22 @redirection = (true if user.return_to) 25 @redirection = (true if user.return_to)
23 @join = (user.community_to_join if user.community_to_join) 26 @join = (user.community_to_join if user.community_to_join)
@@ -30,6 +33,8 @@ class UserMailer &lt; ActionMailer::Base @@ -30,6 +33,8 @@ class UserMailer &lt; ActionMailer::Base
30 end 33 end
31 34
32 def signup_welcome_email(user) 35 def signup_welcome_email(user)
  36 + self.environment = user.environment
  37 +
33 @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) 38 @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
34 email_subject = user.environment.signup_welcome_text_subject 39 email_subject = user.environment.signup_welcome_text_subject
35 mail( 40 mail(
@@ -42,8 +47,9 @@ class UserMailer &lt; ActionMailer::Base @@ -42,8 +47,9 @@ class UserMailer &lt; ActionMailer::Base
42 end 47 end
43 48
44 def profiles_suggestions_email(user) 49 def profiles_suggestions_email(user)
  50 + self.environment = user.environment
  51 +
45 @recipient = user.name 52 @recipient = user.name
46 - @environment = user.environment.name  
47 @url = user.environment.top_url 53 @url = user.environment.top_url
48 @people_suggestions_url = user.people_suggestions_url 54 @people_suggestions_url = user.people_suggestions_url
49 @people_suggestions = user.suggested_people.sample(3) 55 @people_suggestions = user.suggested_people.sample(3)
app/views/comment_notifier/mail_to_followers.html.erb
@@ -18,5 +18,5 @@ @@ -18,5 +18,5 @@
18 <%= _("Greetings,") %> 18 <%= _("Greetings,") %>
19 19
20 -- 20 --
21 -<%= _('%s team.') % @environment %> 21 +<%= _('%s team.') % @environment.name %>
22 <%= url_for @url %> 22 <%= url_for @url %>
app/views/comment_notifier/notification.text.erb
@@ -15,5 +15,5 @@ @@ -15,5 +15,5 @@
15 <%= _("Greetings,") %> 15 <%= _("Greetings,") %>
16 16
17 -- 17 --
18 -<%= _('%s team.') % @environment %> 18 +<%= _('%s team.') % @environment.name %>
19 <%= url_for @url %> 19 <%= url_for @url %>
app/views/contact/sender/notification.html.erb
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 </head> 5 </head>
6 <body> 6 <body>
7 <p><%= _('This message was sent by %{sender} to %{target} on %{environment}.') % 7 <p><%= _('This message was sent by %{sender} to %{target} on %{environment}.') %
8 - {:sender => @name, :target => @target, :environment => @environment} %></p> 8 + {:sender => @name, :target => @target, :environment => @environment.name} %></p>
9 <%= _('Information about the user who sent this message:')%> 9 <%= _('Information about the user who sent this message:')%>
10 <ul> 10 <ul>
11 <li><%= content_tag('b', _('Name')+': ') + @name.to_s %></li> 11 <li><%= content_tag('b', _('Name')+': ') + @name.to_s %></li>
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 20
21 --<br/> 21 --<br/>
22 <%= _('Greetings,') %><br/> 22 <%= _('Greetings,') %><br/>
23 - <%= _('%s team.') % @environment %><br/> 23 + <%= _('%s team.') % @environment.name %><br/>
24 <%= @url %> 24 <%= @url %>
25 </body> 25 </body>
26 </html> 26 </html>
app/views/pending_task_notifier/notification.text.erb
@@ -21,5 +21,5 @@ @@ -21,5 +21,5 @@
21 <%= _('Greetings,') %> 21 <%= _('Greetings,') %>
22 22
23 -- 23 --
24 -<%= _('%s team.') % @environment %> 24 +<%= _('%s team.') % @environment.name %>
25 <%= @url %> 25 <%= @url %>
app/views/person_notifier/mailer/content_summary.html.erb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <div style="display: table; background-color: white; margin: 26px 0;"> 3 <div style="display: table; background-color: white; margin: 26px 0;">
4 <div style="padding: 25px 20px 20px 20px;text-align: left;"> 4 <div style="padding: 25px 20px 20px 20px;text-align: left;">
5 <%= link_to @url, :style => "text-decoration: none;" do %> 5 <%= link_to @url, :style => "text-decoration: none;" do %>
6 - <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment %></span> 6 + <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment.name %></span>
7 <% end %> 7 <% end %>
8 <span style="font-weight:bold;color: #333;font-size:19px;margin-left: 8px;"><%= _("%s's Notifications") % @profile.name %></h3> 8 <span style="font-weight:bold;color: #333;font-size:19px;margin-left: 8px;"><%= _("%s's Notifications") % @profile.name %></h3>
9 </div> 9 </div>
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 34
35 <div style="color:#444444;font-size:11px;margin-bottom: 20px;"> 35 <div style="color:#444444;font-size:11px;margin-bottom: 20px;">
36 <p style="margin:0"><%= _("Greetings,") %></p> 36 <p style="margin:0"><%= _("Greetings,") %></p>
37 - <p style="margin:0"><%= _('%s team.') % @environment %></p> 37 + <p style="margin:0"><%= _('%s team.') % @environment.name %></p>
38 <p style="margin:0"><%= link_to @url, url_for(@url) %></p> 38 <p style="margin:0"><%= link_to @url, url_for(@url) %></p>
39 </div> 39 </div>
40 </div> 40 </div>
app/views/scrap_notifier/notification.text.erb
@@ -12,5 +12,5 @@ @@ -12,5 +12,5 @@
12 <%= _("Greetings,") %> 12 <%= _("Greetings,") %>
13 13
14 -- 14 --
15 -<%= _('%s team.') % @environment %> 15 +<%= _('%s team.') % @environment.name %>
16 <%= url_for @url %> 16 <%= url_for @url %>
app/views/task_mailer/generic_message.text.erb
@@ -5,5 +5,5 @@ @@ -5,5 +5,5 @@
5 <%= _('Greetings,') %> 5 <%= _('Greetings,') %>
6 6
7 -- 7 --
8 -<%= _('%s team.') % @environment %> 8 +<%= _('%s team.') % @environment.name %>
9 <%= @url %> 9 <%= @url %>
app/views/task_mailer/target_notification.text.erb
@@ -6,5 +6,5 @@ @@ -6,5 +6,5 @@
6 <%= @tasks_url %> 6 <%= @tasks_url %>
7 7
8 -- 8 --
9 -<%= _('%s team.') % @environment %> 9 +<%= _('%s team.') % @environment.name %>
10 <%= @url %> 10 <%= @url %>
app/views/user/mailer/activation_code.html.erb
1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> 1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
2 2
3 -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %> 3 +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment.name, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
4 4
5 <%= _("Greetings,") %> 5 <%= _("Greetings,") %>
6 6
7 -- 7 --
8 -<%= _('%s team.') % @environment %> 8 +<%= _('%s team.') % @environment.name %>
9 <%= url_for @url %> 9 <%= url_for @url %>
app/views/user_mailer/activation_code.text.erb
1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> 1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
2 2
3 -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %> 3 +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment.name, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
4 4
5 <%= _("Greetings,") %> 5 <%= _("Greetings,") %>
6 6
7 -- 7 --
8 -<%= _('%s team.') % @environment %> 8 +<%= _('%s team.') % @environment.name %>
9 <%= url_for @url %> 9 <%= url_for @url %>
app/views/user_mailer/activation_email_notify.text.erb
@@ -8,5 +8,5 @@ @@ -8,5 +8,5 @@
8 <%= _('Greetings,') %> 8 <%= _('Greetings,') %>
9 9
10 -- 10 --
11 -<%= _('%s team.') % @environment %> 11 +<%= _('%s team.') % @environment.name %>
12 <%= @url %> 12 <%= @url %>
app/views/user_mailer/profiles_suggestions_email.html.erb
@@ -26,10 +26,8 @@ @@ -26,10 +26,8 @@
26 <% end %> 26 <% end %>
27 27
28 28
29 -<%= _("Greetings,") %>  
30 -  
31 <p><%= _("Greetings,") %></p> 29 <p><%= _("Greetings,") %></p>
32 30
33 --<br/> 31 --<br/>
34 -<%= _('%s team.') % @environment %><br/> 32 +<%= _('%s team.') % @environment.name %><br/>
35 <%= @url %> 33 <%= @url %>
lib/noosfero/mailer.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +
  2 +class Noosfero::Mailer < ActionMailer::Base
  3 +
  4 + attr_accessor :environment
  5 +
  6 + def default_url_options options = nil
  7 + options ||= {}
  8 + options[:host] = environment.default_hostname if environment
  9 + options
  10 + end
  11 +
  12 +end
  13 +
plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
@@ -28,9 +28,11 @@ class WorkAssignmentPlugin::EmailContact @@ -28,9 +28,11 @@ class WorkAssignmentPlugin::EmailContact
28 WorkAssignmentPlugin::EmailContact::EmailSender.notification(self).deliver 28 WorkAssignmentPlugin::EmailContact::EmailSender.notification(self).deliver
29 end 29 end
30 30
31 - class EmailSender < ActionMailer::Base 31 + class EmailSender < Noosfero::Mailer
32 32
33 def notification(email_contact) 33 def notification(email_contact)
  34 + self.environment = email_contact.sender.environment
  35 +
34 name = email_contact.sender.name 36 name = email_contact.sender.name
35 email = email_contact.sender.email 37 email = email_contact.sender.email
36 message = email_contact.message 38 message = email_contact.message