diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 32211b3..ef85730 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -36,9 +36,11 @@ @status = true answer = @note.answer plan = answer.plan - owner = plan.owner - deliver_if(recipients: owner, key: 'users.new_comment') do |r| - UserMailer.new_comment(current_user, plan).deliver_now() + 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, collaborator).deliver_later + end end @notice = success_message(_('comment'), _('created')) render(json: { diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 3dcd176..ce67a86 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -12,12 +12,12 @@ subject: _('Welcome to %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end - + def sharing_notification(role, user, inviter:) @role = role @user = user @inviter = inviter - subject = d_('dmpopidor', '%{user_name} has shared a Data Management Plan with you in %{tool_name}') % { + subject = d_('dmpopidor', '%{user_name} has shared a Data Management Plan with you in %{tool_name}') % { :user_name => @inviter.name(false), :tool_name => Rails.configuration.branding[:application][:name] } @@ -110,16 +110,15 @@ # @param commenter - User who wrote the comment # @param plan - Plan for which the comment is associated to - def new_comment(commenter, plan) + # @param collaborator - Collaborator to whom the email is sent + def new_comment(commenter, plan, collaborator) if commenter.is_a?(User) && plan.is_a?(Plan) - owner = plan.owner - if owner.present? && owner.active? && owner.email != commenter.email - @commenter = commenter - @plan = plan - 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 + @commenter = commenter + @plan = plan + @collaborator = collaborator + 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 @@ -138,7 +137,7 @@ @user = user @end_date = (@user.last_sign_in_at + 5.years).to_date FastGettext.with_locale FastGettext.default_locale do - mail(to: @user.email, subject: + mail(to: @user.email, subject: d_('dmpopidor', 'Account expiration in %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end @@ -146,7 +145,7 @@ def anonymization_notice(user) @user = user FastGettext.with_locale FastGettext.default_locale do - mail(to: @user.email, subject: + mail(to: @user.email, subject: d_('dmpopidor', 'Account expired in %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end diff --git a/app/views/user_mailer/new_comment.html.erb b/app/views/user_mailer/new_comment.html.erb index 8b6c4d6..b922759 100644 --- a/app/views/user_mailer/new_comment.html.erb +++ b/app/views/user_mailer/new_comment.html.erb @@ -2,7 +2,7 @@ tool_name = Rails.configuration.branding[:application][:name] commenter_name = @commenter.name plan_title = @plan.title - user_name = @plan.owner.name + user_name = @collaborator.name %> <% FastGettext.with_locale FastGettext.default_locale do %>

@@ -14,4 +14,4 @@ :commenter_name => commenter_name, :tool_name => tool_name } %>

<%= render partial: 'email_signature' %> -<% end %> \ No newline at end of file +<% end %>