diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb new file mode 100644 index 0000000..c924c66 --- /dev/null +++ b/app/helpers/mailer_helper.rb @@ -0,0 +1,20 @@ +module MailerHelper + + def feedback_confirmation_default_subject + _('%{application_name}: Your plan has been submitted for feedback') + end + + def feedback_confirmation_default_message + _('
Hello %{user_name}.
'\ + 'Your plan "%{plan_name}" has been submitted for feedback from an administrator at your organisation. '\ + 'If you have questions pertaining to this action, please contact us at %{organisation_email}.
') + end + + def feedback_constant_to_text(text, user, plan, org) + _("#{text}") % {application_name: Rails.configuration.branding[:application][:name], + user_name: user.name, + plan_name: plan.title, + organisation_email: org.contact_email} + end + +end \ No newline at end of file diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 7bb70e8..9b080b1 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,4 +1,6 @@ class UserMailer < ActionMailer::Base + include MailerHelper + default from: Rails.configuration.branding[:organisation][:email] def welcome_notification(user) @@ -69,11 +71,13 @@ @plan = plan # Use the generic feedback confirmation message unless the Org has specified one - subject = feedback_constant_to_text(@org.feedback_email_subject.present? ? @org.feedback_email_subject : feedback_confirmation_default_subject) - message = feedback_constant_to_text(@org.feedback_email_msg.present? ? @org.feedback_email_msg : feedback_confirmation_default_message) - + subject = (@org.feedback_email_subject.present? ? @org.feedback_email_subject : feedback_confirmation_default_subject) + message = (@org.feedback_email_msg.present? ? @org.feedback_email_msg : feedback_confirmation_default_message) + FastGettext.with_locale FastGettext.default_locale do - mail(to: recipient.email, subject: subject, body: raw(message)) + mail(to: recipient.email, + subject: feedback_constant_to_text(subject, @user, @plan, @org), + body: feedback_constant_to_text(message, @user, @plan, @org).html_safe) end end end @@ -101,22 +105,4 @@ end end end - - def feedback_confirmation_default_subject - _('%{application_name}: Your plan has been submitted for feedback') - end - - def feedback_confirmation_default_message - _('Hello %{user_name}.
'\ - 'Your plan "%{plan_name}" has been submitted for feedback from an administrator at your organisation. '\ - 'If you have questions pertaining to this action, please contact us at %{organisation_email}.
') - end - - private - def feedback_constant_to_text(text) - return _("#{text}") % {application_name: Rails.configuration.branding[:application][:name], - user_name: @user.name, - plan_name: @plan.title, - organisation_email: @org.contact_email} - end end diff --git a/app/models/plan.rb b/app/models/plan.rb index de90f1d..9975dbe 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -202,7 +202,8 @@ # Share the plan with each org admin as the reviewer role admins = user.org.org_admins admins.each do |admin| - self.roles << Role.new(user: admin, access: val) + role = Role.new(user: admin, access: val) + self.roles << role unless self.users.include?(admin) end if self.save! diff --git a/app/views/orgs/_feedback_form.html.erb b/app/views/orgs/_feedback_form.html.erb index 2d651fd..026d1f3 100644 --- a/app/views/orgs/_feedback_form.html.erb +++ b/app/views/orgs/_feedback_form.html.erb @@ -11,11 +11,13 @@