From 7eae937a041b9729a9e76219ce19b4dd0017de96 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Wed, 6 Apr 2022 09:41:51 +0100 Subject: [PATCH 1/6] DCC Feature #345 - Allow Orgs to set a different Help Desk Email Address from the default address. Feature asked for by DCC https://github.com/DigitalCurationCentre/DMPonline-Service/issues/345 Changes: - added helpdesk_email attribute to Org model with migration. - added a Help Desk email field to app/views/orgs/_profile_form.html.erb. - added a method helpdesk_mail(org = nil) to app/helpers/mailer_helper.rb. - added a variable @helpdesk_email to each method in app/mailers/user_mailer.rb. - updated app/views/user_mailer/_email_signature.html.erb to accept @helpdesk_mail variable. - altered helpdesk_email variable in Devise email fragments to use Org helpdesk_email if present. --- app/controllers/orgs_controller.rb | 1 + app/helpers/mailer_helper.rb | 4 ++-- app/mailers/user_mailer.rb | 12 ++++++++++++ app/models/org.rb | 1 + .../devise/mailer/invitation_instructions.html.erb | 12 +++++++++--- .../mailer/reset_password_instructions.html.erb | 3 +++ app/views/orgs/_profile_form.html.erb | 14 ++++++++++++++ app/views/user_mailer/_email_signature.html.erb | 2 +- .../20220315104737_add_helpdesk_email_to_orgs.rb | 5 +++++ db/schema.rb | 1 + 10 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20220315104737_add_helpdesk_email_to_orgs.rb diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 78ad6f1777..e4f2423886 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -219,6 +219,7 @@ def org_params :remove_logo, :managed, :feedback_enabled, :org_links, :funder, :institution, :organisation, :feedback_msg, :org_id, :org_name, :org_crosswalk, + :helpdesk_email, identifiers_attributes: %i[identifier_scheme_id value], tracker_attributes: %i[code id]) end diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index 7824d66081..b3850648b2 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -8,8 +8,8 @@ def tool_name @tool_name ||= ApplicationService.application_name end - def helpdesk_email - @helpdesk_email ||= Rails.configuration.x.organisation.helpdesk_email + def helpdesk_email(org) + org&.helpdesk_email || Rails.configuration.x.organisation.helpdesk_email end # Returns an unordered HTML list with the permissions associated to the user passed diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index fe68f2e708..ad13bc9e53 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -18,6 +18,7 @@ def welcome_notification(user) # Override the default Rails route helper for the contact_us page IF an alternate contact_us # url was defined in the dmproadmap.rb initializer file @contact_us = Rails.application.config.x.organisation.contact_us_url || contact_us_url + @helpdesk_email = helpdesk_email(@user.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -38,6 +39,7 @@ def question_answered(data, user, answer, _options_string) @recipient_name = @data['name'].to_s @message = @data['message'].to_s @answer_text = @options_string.to_s + @helpdesk_email = helpdesk_email(@user.org) I18n.with_locale I18n.default_locale do mail(to: data['email'], @@ -53,6 +55,7 @@ def sharing_notification(role, user, inviter:) @username = @user.name @inviter = inviter @link = url_for(action: 'show', controller: 'plans', id: @role.plan.id) + @helpdesk_email = helpdesk_email(@inviter.org) I18n.with_locale I18n.default_locale do mail(to: @role.user.email, @@ -69,6 +72,7 @@ def permissions_change_notification(role, user) @user = user @recepient = @role.user @messaging = role_text(@role) + @helpdesk_email = helpdesk_email(@user.org) I18n.with_locale I18n.default_locale do mail(to: @recepient.email, @@ -83,6 +87,7 @@ def plan_access_removed(user, plan, current_user) @user = user @plan = plan @current_user = current_user + @helpdesk_email = helpdesk_email(@plan.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -100,6 +105,7 @@ def feedback_notification(recipient, plan, requestor) @recipient_name = @recipient.name(false) @requestor_name = @user.name(false) @plan_name = @plan.title + @helpdesk_email = helpdesk_email(@plan.org) I18n.with_locale I18n.default_locale do mail(to: @recipient.email, @@ -118,6 +124,7 @@ def feedback_complete(recipient, plan, requestor) @plan = plan @phase = @plan.phases.first @plan_name = @plan.title + @helpdesk_email = helpdesk_email(@plan.org) I18n.with_locale I18n.default_locale do sender = Rails.configuration.x.organisation.do_not_reply_email || @@ -139,6 +146,7 @@ def plan_visibility(user, plan) @plan = plan @plan_title = @plan.title @plan_visibility = Plan::VISIBILITY_MESSAGE[@plan.visibility.to_sym] + @helpdesk_email = helpdesk_email(@plan.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -167,6 +175,7 @@ def new_comment(commenter, plan, answer) @section_title = @question.section.title @phase_id = @question.section.phase.id @phase_link = url_for(action: 'edit', controller: 'plans', id: @plan.id, phase_id: @phase_id) + @helpdesk_email = helpdesk_email(@plan.org) I18n.with_locale I18n.default_locale do mail(to: @plan.owner.email, @@ -182,6 +191,7 @@ def admin_privileges(user) @user = user @username = @user.name @ul_list = privileges_list(@user) + @helpdesk_email = helpdesk_email(@user.org) I18n.with_locale I18n.default_locale do mail(to: user.email, @@ -199,6 +209,8 @@ def api_credentials(api_client) @name = @api_client.contact_name.present? ? @api_client.contact_name : @api_client.contact_email + @helpdesk_email = helpdesk_email(@api_client.org) + I18n.with_locale I18n.default_locale do mail(to: @api_client.contact_email, subject: format(_('%{tool_name} API changes'), tool_name: tool_name)) diff --git a/app/models/org.rb b/app/models/org.rb index 8f25d00e79..6b2a48525c 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -24,6 +24,7 @@ # language_id :integer # region_id :integer # managed :boolean default(false), not null +# helpdesk_email :string # # Foreign Keys # diff --git a/app/views/devise/mailer/invitation_instructions.html.erb b/app/views/devise/mailer/invitation_instructions.html.erb index a9e0989c4d..1e1af1af3e 100644 --- a/app/views/devise/mailer/invitation_instructions.html.erb +++ b/app/views/devise/mailer/invitation_instructions.html.erb @@ -1,15 +1,21 @@ <% tool_name = ApplicationService.application_name link = accept_invitation_url(@resource, :invitation_token => @token) - helpdesk_email = Rails.configuration.x.organisation.helpdesk_email contact_us = (Rails.configuration.x.organisation.contact_us_url || contact_us_url) email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } user_name = User.find_by(email: @resource.email).nil? ? @resource.email : User.find_by(email: @resource.email).name(false) - inviter_name = @resource.invited_by.name + inviter = @resource.invited_by + inviter_name = inviter.name + helpdesk_email = inviter.org&.helpdesk_email || + Rails.configuration.x.organisation.helpdesk_email %> <% I18n.with_locale I18n.default_locale do %> +

+ + +

- <%= _('Hello %{user_name}') %{ :user_name => user_name } %> + <%= _("Hello %{user_name}") %{ :user_name => user_name } %>

<%= _("Your colleague %{inviter_name} has invited you to contribute to "\ diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index d7ee54d126..b5c41e5b85 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -3,6 +3,9 @@ helpdesk_email = Rails.configuration.x.organisation.helpdesk_email contact_us = Rails.configuration.x.organisation.contact_us_url || contact_us_url email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } + user = User.find_by(email: @resource.email) + helpdesk_email = user.org&.helpdesk_email || + Rails.configuration.x.organisation.helpdesk_email %> <% I18n.with_locale I18n.default_locale do %>

diff --git a/app/views/orgs/_profile_form.html.erb b/app/views/orgs/_profile_form.html.erb index 5226143c6d..8dd20013ba 100644 --- a/app/views/orgs/_profile_form.html.erb +++ b/app/views/orgs/_profile_form.html.erb @@ -86,6 +86,20 @@


+
+
+

<%= _("Help Desk email") %>

+
+
+
+
+ <%= f.label :helpdesk_email, _('Help Desk email'), class: "control-label" %> + <%= f.email_field :helpdesk_email, class: "form-control" %> +
+
+ +
+

<%= _("Administrator contact") %>

diff --git a/app/views/user_mailer/_email_signature.html.erb b/app/views/user_mailer/_email_signature.html.erb index 7594d71d93..a1b64abd30 100644 --- a/app/views/user_mailer/_email_signature.html.erb +++ b/app/views/user_mailer/_email_signature.html.erb @@ -17,7 +17,7 @@ <% end %> <%= _('Please do not reply to this email.') %> <%= sanitize(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us}') % { - helpdesk_email: mail_to(helpdesk_email, helpdesk_email, + helpdesk_email: mail_to(@helpdesk_email, @helpdesk_email, subject: email_subject), contact_us: link_to(contact_us, contact_us) }) %> diff --git a/db/migrate/20220315104737_add_helpdesk_email_to_orgs.rb b/db/migrate/20220315104737_add_helpdesk_email_to_orgs.rb new file mode 100644 index 0000000000..e646e9bf6d --- /dev/null +++ b/db/migrate/20220315104737_add_helpdesk_email_to_orgs.rb @@ -0,0 +1,5 @@ +class AddHelpdeskEmailToOrgs < ActiveRecord::Migration[5.2] + def change + add_column :orgs, :helpdesk_email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ab5a3608e3..c3827f639a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -219,6 +219,7 @@ t.boolean "managed", default: false, null: false t.index ["language_id"], name: "fk_rails_5640112cab" t.index ["region_id"], name: "fk_rails_5a6adf6bab" + t.string "helpdesk_email" end create_table "perms", id: :integer, force: :cascade do |t| From 935d3de20cda10d051c54101c2d515735d3ef190 Mon Sep 17 00:00:00 2001 From: Brian Riley Date: Wed, 6 Apr 2022 07:33:20 -0700 Subject: [PATCH 2/6] Update schema.rb Updated schema.rb to have the timestamp of the new migration --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index c3827f639a..e7a5e1d068 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_19_160319) do +ActiveRecord::Schema.define(version: 2022_03_15_104737) do create_table "annotations", id: :integer, force: :cascade do |t| t.integer "question_id" From 8ca9b704397eff4d59bf5939c8e9a6f0807dd1df Mon Sep 17 00:00:00 2001 From: briri Date: Wed, 6 Apr 2022 09:22:37 -0700 Subject: [PATCH 3/6] switched helper to use named args and have a default --- app/helpers/mailer_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index b3850648b2..f692a8ae04 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -8,7 +8,7 @@ def tool_name @tool_name ||= ApplicationService.application_name end - def helpdesk_email(org) + def helpdesk_email(org: = nil) org&.helpdesk_email || Rails.configuration.x.organisation.helpdesk_email end From 20a2ea79c93a246583a7e9cc47122819372ce951 Mon Sep 17 00:00:00 2001 From: briri Date: Wed, 6 Apr 2022 09:29:53 -0700 Subject: [PATCH 4/6] fixed typo --- app/helpers/mailer_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index f692a8ae04..f133706dd5 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -8,7 +8,7 @@ def tool_name @tool_name ||= ApplicationService.application_name end - def helpdesk_email(org: = nil) + def helpdesk_email(org: nil) org&.helpdesk_email || Rails.configuration.x.organisation.helpdesk_email end From 04ae2c5e6c6671aa8277eddac2fede2615215d30 Mon Sep 17 00:00:00 2001 From: briri Date: Wed, 6 Apr 2022 09:38:43 -0700 Subject: [PATCH 5/6] tweak to email_signature to reduce confusion over helpdesk_email var vs method --- app/views/user_mailer/_email_signature.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/user_mailer/_email_signature.html.erb b/app/views/user_mailer/_email_signature.html.erb index a1b64abd30..518a95b090 100644 --- a/app/views/user_mailer/_email_signature.html.erb +++ b/app/views/user_mailer/_email_signature.html.erb @@ -5,6 +5,8 @@ # Override the default Rails route helper for the contact_us page IF an alternate contact_us url was defined # in the dmproadmap.rb initializer contact_us = Rails.configuration.x.organisation.contact_us_url || contact_us_url + + helpdesk = @helpdesk_email || helpdesk_email() %>

<%= _('All the best') %> From f3836fe04e185b877103cb528788296873ee99be Mon Sep 17 00:00:00 2001 From: briri Date: Wed, 6 Apr 2022 09:48:11 -0700 Subject: [PATCH 6/6] updated mailer to use named arg for helpdesk_emai --- app/mailers/user_mailer.rb | 22 +++++++++---------- .../user_mailer/_email_signature.html.erb | 2 -- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index ad13bc9e53..56267ee547 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -18,7 +18,7 @@ def welcome_notification(user) # Override the default Rails route helper for the contact_us page IF an alternate contact_us # url was defined in the dmproadmap.rb initializer file @contact_us = Rails.application.config.x.organisation.contact_us_url || contact_us_url - @helpdesk_email = helpdesk_email(@user.org) + @helpdesk_email = helpdesk_email(org: @user.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -39,7 +39,7 @@ def question_answered(data, user, answer, _options_string) @recipient_name = @data['name'].to_s @message = @data['message'].to_s @answer_text = @options_string.to_s - @helpdesk_email = helpdesk_email(@user.org) + @helpdesk_email = helpdesk_email(org: @user.org) I18n.with_locale I18n.default_locale do mail(to: data['email'], @@ -55,7 +55,7 @@ def sharing_notification(role, user, inviter:) @username = @user.name @inviter = inviter @link = url_for(action: 'show', controller: 'plans', id: @role.plan.id) - @helpdesk_email = helpdesk_email(@inviter.org) + @helpdesk_email = helpdesk_email(org: @inviter.org) I18n.with_locale I18n.default_locale do mail(to: @role.user.email, @@ -72,7 +72,7 @@ def permissions_change_notification(role, user) @user = user @recepient = @role.user @messaging = role_text(@role) - @helpdesk_email = helpdesk_email(@user.org) + @helpdesk_email = helpdesk_email(org: @user.org) I18n.with_locale I18n.default_locale do mail(to: @recepient.email, @@ -87,7 +87,7 @@ def plan_access_removed(user, plan, current_user) @user = user @plan = plan @current_user = current_user - @helpdesk_email = helpdesk_email(@plan.org) + @helpdesk_email = helpdesk_email(org: @plan.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -105,7 +105,7 @@ def feedback_notification(recipient, plan, requestor) @recipient_name = @recipient.name(false) @requestor_name = @user.name(false) @plan_name = @plan.title - @helpdesk_email = helpdesk_email(@plan.org) + @helpdesk_email = helpdesk_email(org: @plan.org) I18n.with_locale I18n.default_locale do mail(to: @recipient.email, @@ -124,7 +124,7 @@ def feedback_complete(recipient, plan, requestor) @plan = plan @phase = @plan.phases.first @plan_name = @plan.title - @helpdesk_email = helpdesk_email(@plan.org) + @helpdesk_email = helpdesk_email(org: @plan.org) I18n.with_locale I18n.default_locale do sender = Rails.configuration.x.organisation.do_not_reply_email || @@ -146,7 +146,7 @@ def plan_visibility(user, plan) @plan = plan @plan_title = @plan.title @plan_visibility = Plan::VISIBILITY_MESSAGE[@plan.visibility.to_sym] - @helpdesk_email = helpdesk_email(@plan.org) + @helpdesk_email = helpdesk_email(org: @plan.org) I18n.with_locale I18n.default_locale do mail(to: @user.email, @@ -175,7 +175,7 @@ def new_comment(commenter, plan, answer) @section_title = @question.section.title @phase_id = @question.section.phase.id @phase_link = url_for(action: 'edit', controller: 'plans', id: @plan.id, phase_id: @phase_id) - @helpdesk_email = helpdesk_email(@plan.org) + @helpdesk_email = helpdesk_email(org: @plan.org) I18n.with_locale I18n.default_locale do mail(to: @plan.owner.email, @@ -191,7 +191,7 @@ def admin_privileges(user) @user = user @username = @user.name @ul_list = privileges_list(@user) - @helpdesk_email = helpdesk_email(@user.org) + @helpdesk_email = helpdesk_email(org: @user.org) I18n.with_locale I18n.default_locale do mail(to: user.email, @@ -209,7 +209,7 @@ def api_credentials(api_client) @name = @api_client.contact_name.present? ? @api_client.contact_name : @api_client.contact_email - @helpdesk_email = helpdesk_email(@api_client.org) + @helpdesk_email = helpdesk_email(org: @api_client.org) I18n.with_locale I18n.default_locale do mail(to: @api_client.contact_email, diff --git a/app/views/user_mailer/_email_signature.html.erb b/app/views/user_mailer/_email_signature.html.erb index 518a95b090..a1b64abd30 100644 --- a/app/views/user_mailer/_email_signature.html.erb +++ b/app/views/user_mailer/_email_signature.html.erb @@ -5,8 +5,6 @@ # Override the default Rails route helper for the contact_us page IF an alternate contact_us url was defined # in the dmproadmap.rb initializer contact_us = Rails.configuration.x.organisation.contact_us_url || contact_us_url - - helpdesk = @helpdesk_email || helpdesk_email() %>

<%= _('All the best') %>