From 5a2656838af2b75db0b96c101513ae33964d5959 Mon Sep 17 00:00:00 2001
From: Braulio Bhavamitra
Date: Sun, 5 Apr 2015 09:26:44 -0300
Subject: [PATCH] rails4: use Noosfero::Mailer to set required default_url_options
---
app/mailers/comment_notifier.rb | 8 +++++---
app/mailers/contact.rb | 6 ++++--
app/mailers/mailing.rb | 3 ++-
app/mailers/pending_task_notifier.rb | 5 +++--
app/mailers/scrap_notifier.rb | 6 ++++--
app/mailers/task_mailer.rb | 10 +++++++---
app/mailers/user_mailer.rb | 14 ++++++++++----
app/views/comment_notifier/mail_to_followers.html.erb | 2 +-
app/views/comment_notifier/notification.text.erb | 2 +-
app/views/contact/sender/notification.html.erb | 4 ++--
app/views/pending_task_notifier/notification.text.erb | 2 +-
app/views/person_notifier/mailer/content_summary.html.erb | 4 ++--
app/views/scrap_notifier/notification.text.erb | 2 +-
app/views/task_mailer/generic_message.text.erb | 2 +-
app/views/task_mailer/target_notification.text.erb | 2 +-
app/views/user/mailer/activation_code.html.erb | 4 ++--
app/views/user_mailer/activation_code.text.erb | 4 ++--
app/views/user_mailer/activation_email_notify.text.erb | 2 +-
app/views/user_mailer/profiles_suggestions_email.html.erb | 4 +---
lib/noosfero/mailer.rb | 13 +++++++++++++
plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb | 4 +++-
21 files changed, 67 insertions(+), 36 deletions(-)
create mode 100644 lib/noosfero/mailer.rb
diff --git a/app/mailers/comment_notifier.rb b/app/mailers/comment_notifier.rb
index faaf57c..7dacb2f 100644
--- a/app/mailers/comment_notifier.rb
+++ b/app/mailers/comment_notifier.rb
@@ -1,6 +1,8 @@
-class CommentNotifier < ActionMailer::Base
+class CommentNotifier < Noosfero::Mailer
+
def notification(comment)
profile = comment.article.profile
+ self.environment = profile.environment
@recipient = profile.nickname || profile.name
@sender = comment.author_name
@sender_link = comment.author_link
@@ -8,7 +10,6 @@ class CommentNotifier < ActionMailer::Base
@comment_url = comment.url
@comment_title = comment.title
@comment_body = comment.body
- @environment = profile.environment.name
@url = profile.environment.top_url
mail(
@@ -20,6 +21,8 @@ class CommentNotifier < ActionMailer::Base
def mail_to_followers(comment, emails)
profile = comment.article.profile
+ self.environment = profile.environment
+
@recipient = profile.nickname || profile.name
@sender = comment.author_name
@sender_link = comment.author_link
@@ -28,7 +31,6 @@ class CommentNotifier < ActionMailer::Base
@unsubscribe_url = comment.article.view_url.merge({:unfollow => true})
@comment_title = comment.title
@comment_body = comment.body
- @environment = profile.environment.name
@url = profile.environment.top_url
mail(
diff --git a/app/mailers/contact.rb b/app/mailers/contact.rb
index 058b3e9..cf11cd1 100644
--- a/app/mailers/contact.rb
+++ b/app/mailers/contact.rb
@@ -30,14 +30,16 @@ class Contact
Contact::Sender.notification(self).deliver
end
- class Sender < ActionMailer::Base
+ class Sender < Noosfero::Mailer
+
def notification(contact)
+ self.environment = contact.dest.environment
+
@name = contact.name
@email = contact.email
@city = contact.city
@state = contact.state
@message = contact.message
- @environment = contact.dest.environment.name
@url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home')
@target = contact.dest.name
diff --git a/app/mailers/mailing.rb b/app/mailers/mailing.rb
index 8f7c302..f50cc42 100644
--- a/app/mailers/mailing.rb
+++ b/app/mailers/mailing.rb
@@ -48,7 +48,8 @@ class Mailing < ActiveRecord::Base
end
end
- class Sender < ActionMailer::Base
+ class Sender < Noosfero::Mailer
+
def notification(mailing, recipient)
@message = mailing.body
@signature_message = mailing.signature_message
diff --git a/app/mailers/pending_task_notifier.rb b/app/mailers/pending_task_notifier.rb
index d9d1994..90ab6c5 100644
--- a/app/mailers/pending_task_notifier.rb
+++ b/app/mailers/pending_task_notifier.rb
@@ -1,10 +1,11 @@
-class PendingTaskNotifier < ActionMailer::Base
+class PendingTaskNotifier < Noosfero::Mailer
def notification(person)
+ self.environment = person.environment
+
@person = person
@tasks = person.tasks.pending
@organizations_with_pending_tasks = person.organizations_with_pending_tasks
- @environment = person.environment.name
@url = url_for(:host => person.environment.default_hostname, :controller => 'home')
@default_hostname = person.environment.default_hostname
@url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier)
diff --git a/app/mailers/scrap_notifier.rb b/app/mailers/scrap_notifier.rb
index 232a6d9..ff152e6 100644
--- a/app/mailers/scrap_notifier.rb
+++ b/app/mailers/scrap_notifier.rb
@@ -1,12 +1,14 @@
-class ScrapNotifier < ActionMailer::Base
+class ScrapNotifier < Noosfero::Mailer
+
def notification(scrap)
sender, receiver = scrap.sender, scrap.receiver
+ self.environment = sender.environment
+
@recipient = receiver.name
@sender = sender.name
@sender_link = sender.url
@scrap_content = scrap.content
@wall_url = scrap.scrap_wall_url
- @environment = sender.environment.name
@url = sender.environment.top_url
mail(
to: receiver.email,
diff --git a/app/mailers/task_mailer.rb b/app/mailers/task_mailer.rb
index cc46f6d..a8c1684 100644
--- a/app/mailers/task_mailer.rb
+++ b/app/mailers/task_mailer.rb
@@ -1,9 +1,10 @@
-class TaskMailer < ActionMailer::Base
+class TaskMailer < Noosfero::Mailer
def target_notification(task, message)
+ self.environment = task.environment
+
@message = extract_message(message)
@target = task.target.name
- @environment = task.environment.name
@url = generate_environment_url(task, :controller => 'home')
url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/')))
@tasks_url = url_for_tasks_list
@@ -16,6 +17,8 @@ class TaskMailer < ActionMailer::Base
end
def invitation_notification(task)
+ self.environment = task.requestor.environment
+
msg = task.expanded_message
@message = msg.gsub //, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)
@@ -27,11 +30,12 @@ class TaskMailer < ActionMailer::Base
end
def generic_message(name, task)
+ self.environment = task.requestor.environment
+
return if !task.respond_to?("#{name}_message")
@message = extract_message(task.send("#{name}_message"))
@requestor = task.requestor.name
- @environment = task.requestor.environment.name
@url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home')
mail(
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 93efd25..8556356 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -1,10 +1,12 @@
-class UserMailer < ActionMailer::Base
+class UserMailer < Noosfero::Mailer
+
def activation_email_notify(user)
+ self.environment = user.environment
+
user_email = "#{user.login}@#{user.email_domain}"
@name = user.name
@email = user_email
@webmail = MailConf.webmail_url(user.login, user.email_domain)
- @environment = user.environment.name
@url = url_for(:host => user.environment.default_hostname, :controller => 'home')
mail(
@@ -15,9 +17,10 @@ class UserMailer < ActionMailer::Base
end
def activation_code(user)
+ self.environment = user.environment
+
@recipient = user.name
@activation_code = user.activation_code
- @environment = user.environment.name
@url = user.environment.top_url
@redirection = (true if user.return_to)
@join = (user.community_to_join if user.community_to_join)
@@ -30,6 +33,8 @@ class UserMailer < ActionMailer::Base
end
def signup_welcome_email(user)
+ self.environment = user.environment
+
@body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
email_subject = user.environment.signup_welcome_text_subject
mail(
@@ -42,8 +47,9 @@ class UserMailer < ActionMailer::Base
end
def profiles_suggestions_email(user)
+ self.environment = user.environment
+
@recipient = user.name
- @environment = user.environment.name
@url = user.environment.top_url
@people_suggestions_url = user.people_suggestions_url
@people_suggestions = user.suggested_people.sample(3)
diff --git a/app/views/comment_notifier/mail_to_followers.html.erb b/app/views/comment_notifier/mail_to_followers.html.erb
index 10d28d7..c927f1f 100644
--- a/app/views/comment_notifier/mail_to_followers.html.erb
+++ b/app/views/comment_notifier/mail_to_followers.html.erb
@@ -18,5 +18,5 @@
<%= _("Greetings,") %>
--
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
<%= url_for @url %>
diff --git a/app/views/comment_notifier/notification.text.erb b/app/views/comment_notifier/notification.text.erb
index 5fd6d71..2cc22d4 100644
--- a/app/views/comment_notifier/notification.text.erb
+++ b/app/views/comment_notifier/notification.text.erb
@@ -15,5 +15,5 @@
<%= _("Greetings,") %>
--
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
<%= url_for @url %>
diff --git a/app/views/contact/sender/notification.html.erb b/app/views/contact/sender/notification.html.erb
index 817205d..9c57cda 100644
--- a/app/views/contact/sender/notification.html.erb
+++ b/app/views/contact/sender/notification.html.erb
@@ -5,7 +5,7 @@
<%= _('This message was sent by %{sender} to %{target} on %{environment}.') %
- {:sender => @name, :target => @target, :environment => @environment} %>
+ {:sender => @name, :target => @target, :environment => @environment.name} %>
<%= _('Information about the user who sent this message:')%>
- <%= content_tag('b', _('Name')+': ') + @name.to_s %>
@@ -20,7 +20,7 @@
--
<%= _('Greetings,') %>
- <%= _('%s team.') % @environment %>
+ <%= _('%s team.') % @environment.name %>
<%= @url %>