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 @@
<%= f.label :feedback_email_subject, _('Subject'), class: "control-label" %> - <%= f.text_field :feedback_email_subject, class: "form-control" %> + + <%= f.text_field :feedback_email_subject, class: "form-control", placeholder: _(feedback_confirmation_default_subject) % { application_name: Rails.configuration.branding[:application][:name] } %>
-
+ <% tip = _(feedback_confirmation_default_message) % { user_name: _('%{user_name}'), plan_name: _('%{plan_name}'), organisation_email: @org.contact_email } %> +
<%= f.label :feedback_email_msg, _('Message'), class: "control-label" %> <%= f.text_area :feedback_email_msg, class: "form-control" %>
@@ -24,9 +26,6 @@
<%= f.button(_('Save'), id:"save_org_submit", class: "btn btn-primary", type: "submit") %> - <%= f.button(_('Reset to defaults'), id:"reset-to-default-feedback-email", class: "btn btn-default", type: "button") %> -
<%= UserMailer.feedback_confirmation_default_subject %>
-
<%= UserMailer.feedback_confirmation_default_message %>
<% end %> \ No newline at end of file diff --git a/lib/assets/javascripts/views/orgs/admin_edit.js b/lib/assets/javascripts/views/orgs/admin_edit.js index 7650013..64866ff 100644 --- a/lib/assets/javascripts/views/orgs/admin_edit.js +++ b/lib/assets/javascripts/views/orgs/admin_edit.js @@ -67,13 +67,6 @@ // Initialises tinymce for any target element with class tinymce_answer Tinymce.init({ selector: '#org_feedback_email_msg' }); - $('#reset-to-default-feedback-email').click((e) => { - e.preventDefault(); - $('#org_feedback_email_subject').val($('#feedback-email-default-subject').html()); - const editor = Tinymce.findEditorById('org_feedback_email_msg'); - editor.setContent($('#feedback-email-default-message').text()); - }); - // Convert the max number of URLs constant to text and display for user $('#max-nbr-urls').text(convertToText(MAX_NUMBER_ORG_URLS).toLowerCase());