Skip to content

Commit

Permalink
DCC Feature #345 - Allow Orgs to set a different Help Desk Email Address
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
John Pinto committed Apr 5, 2022
1 parent 235624d commit 0285039
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 77 deletions.
1 change: 1 addition & 0 deletions app/controllers/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ def tool_name
@tool_name ||= ApplicationService.application_name
end

def helpdesk_email
@helpdesk_email ||= Rails.configuration.x.organisation.helpdesk_email
def helpdesk_email(org = nil)
if org.present? && org.helpdesk_email.present?
@helpdesk_email = org.helpdesk_email
else
Rails.configuration.x.organisation.helpdesk_email
end
end

# Returns an unordered HTML list with the permissions associated to the user passed
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'],
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 ||
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions app/models/org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# language_id :integer
# region_id :integer
# managed :boolean default(false), not null
# helpdesk_email :string
#
# Foreign Keys
#
Expand Down
14 changes: 11 additions & 3 deletions app/views/devise/mailer/invitation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<%
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.present? &&
inviter.org.helpdesk_email.present? ?
inviter.org.helpdesk_email :
Rails.configuration.x.organisation.helpdesk_email
%>
<% I18n.with_locale I18n.default_locale do %>
<p>


</p>
<p>
<%= _('Hello %{user_name}') %{ :user_name => user_name } %>
<%= _("Hello %{user_name}"") %{ :user_name => user_name } %>
</p>
<p>
<%= _("Your colleague %{inviter_name} has invited you to contribute to "\
Expand Down
5 changes: 5 additions & 0 deletions app/views/devise/mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
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.present? &&
user.org.helpdesk_email.present? ?
user.org.helpdesk_email :
Rails.configuration.x.organisation.helpdesk_email
%>
<% I18n.with_locale I18n.default_locale do %>
<p>
Expand Down
14 changes: 14 additions & 0 deletions app/views/orgs/_profile_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@

<hr>

<div class="row">
<div class="form-group col-xs-8">
<h3><%= _("Help Desk email") %></h3>
</div>
</div>
<div class="row">
<div class="form-group col-xs-4">
<%= f.label :helpdesk_email, _('Help Desk email'), class: "control-label" %>
<%= f.email_field :helpdesk_email, class: "form-control" %>
</div>
</div>

<hr>

<div class="row">
<div class="form-group col-xs-8">
<h3><%= _("Administrator contact") %></h3>
Expand Down
2 changes: 1 addition & 1 deletion app/views/user_mailer/_email_signature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}) %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220315104737_add_helpdesk_email_to_orgs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHelpdeskEmailToOrgs < ActiveRecord::Migration[5.2]
def change
add_column :orgs, :helpdesk_email, :string
end
end
Loading

0 comments on commit 0285039

Please sign in to comment.