diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 3d4b87e..2aac844 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,4 +1,5 @@ class UserMailer < ActionMailer::Base + include Dmpopidor::Mailers::UserMailer include MailerHelper helper MailerHelper helper FeedbacksHelper @@ -112,20 +113,20 @@ # commenter - User who wrote the comment # plan - Plan for which the comment is associated to # answer - Answer commented on - def new_comment(commenter, plan, answer) - if commenter.is_a?(User) && plan.is_a?(Plan) - owner = plan.owner - if owner.present? && owner.active? - @commenter = commenter - @plan = plan - @answer = answer - FastGettext.with_locale FastGettext.default_locale do - mail(to: plan.owner.email, subject: - _('%{tool_name}: A new comment was added to %{plan_title}') %{ :tool_name => Rails.configuration.branding[:application][:name], :plan_title => plan.title }) - end - end - end - end + # def new_comment(commenter, plan, answer) + # if commenter.is_a?(User) && plan.is_a?(Plan) + # owner = plan.owner + # if owner.present? && owner.active? + # @commenter = commenter + # @plan = plan + # @answer = answer + # FastGettext.with_locale FastGettext.default_locale do + # mail(to: plan.owner.email, subject: + # _('%{tool_name}: A new comment was added to %{plan_title}') %{ :tool_name => Rails.configuration.branding[:application][:name], :plan_title => plan.title }) + # end + # end + # end + # end def admin_privileges(user) @user = user diff --git a/lib/dmpopidor/controllers/notes.rb b/lib/dmpopidor/controllers/notes.rb index 8e9b71a..af2d123 100644 --- a/lib/dmpopidor/controllers/notes.rb +++ b/lib/dmpopidor/controllers/notes.rb @@ -43,10 +43,8 @@ answer = @note.answer plan = answer.plan collaborators = plan.users.reject { |u| u == current_user || !u.active } - collaborators.uniq.each do |collaborator| - deliver_if(recipients: collaborator, key: 'users.new_comment') do |r| - UserMailer.new_comment(current_user, plan, answer).deliver_later - end + deliver_if(recipients: collaborators, key: 'users.new_comment') do |r| + UserMailer.new_comment(current_user, plan, answer, r).deliver_now() end @notice = success_message(@note, _("created")) render(json: { diff --git a/lib/dmpopidor/mailers/user_mailer.rb b/lib/dmpopidor/mailers/user_mailer.rb new file mode 100644 index 0000000..ca9d9c4 --- /dev/null +++ b/lib/dmpopidor/mailers/user_mailer.rb @@ -0,0 +1,24 @@ +module Dmpopidor + module Mailers + module UserMailer + # commenter - User who wrote the comment + # plan - Plan for which the comment is associated to + # answer - Answer commented on + # collaborator - User to send the notification to + def new_comment(commenter, plan, answer, collaborator) + if commenter.is_a?(User) && plan.is_a?(Plan) + owner = plan.owner + if owner.present? && owner.active? + @commenter = commenter + @plan = plan + @answer = answer + FastGettext.with_locale FastGettext.default_locale do + mail(to: collaborator.email, subject: + _('%{tool_name}: A new comment was added to %{plan_title}') %{ :tool_name => Rails.configuration.branding[:application][:name], :plan_title => plan.title }) + end + end + end + end + end + end + end \ No newline at end of file