Skip to content

Commit 0285039

Browse files
author
John Pinto
committed
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.
1 parent 235624d commit 0285039

File tree

10 files changed

+115
-77
lines changed

10 files changed

+115
-77
lines changed

app/controllers/orgs_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def org_params
219219
:remove_logo, :managed, :feedback_enabled, :org_links,
220220
:funder, :institution, :organisation,
221221
:feedback_msg, :org_id, :org_name, :org_crosswalk,
222+
:helpdesk_email,
222223
identifiers_attributes: %i[identifier_scheme_id value],
223224
tracker_attributes: %i[code id])
224225
end

app/helpers/mailer_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ def tool_name
88
@tool_name ||= ApplicationService.application_name
99
end
1010

11-
def helpdesk_email
12-
@helpdesk_email ||= Rails.configuration.x.organisation.helpdesk_email
11+
def helpdesk_email(org = nil)
12+
if org.present? && org.helpdesk_email.present?
13+
@helpdesk_email = org.helpdesk_email
14+
else
15+
Rails.configuration.x.organisation.helpdesk_email
16+
end
1317
end
1418

1519
# Returns an unordered HTML list with the permissions associated to the user passed

app/mailers/user_mailer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def welcome_notification(user)
1818
# Override the default Rails route helper for the contact_us page IF an alternate contact_us
1919
# url was defined in the dmproadmap.rb initializer file
2020
@contact_us = Rails.application.config.x.organisation.contact_us_url || contact_us_url
21+
@helpdesk_email = helpdesk_email(@user.org)
2122

2223
I18n.with_locale I18n.default_locale do
2324
mail(to: @user.email,
@@ -38,6 +39,7 @@ def question_answered(data, user, answer, _options_string)
3839
@recipient_name = @data['name'].to_s
3940
@message = @data['message'].to_s
4041
@answer_text = @options_string.to_s
42+
@helpdesk_email = helpdesk_email(@user.org)
4143

4244
I18n.with_locale I18n.default_locale do
4345
mail(to: data['email'],
@@ -53,6 +55,7 @@ def sharing_notification(role, user, inviter:)
5355
@username = @user.name
5456
@inviter = inviter
5557
@link = url_for(action: 'show', controller: 'plans', id: @role.plan.id)
58+
@helpdesk_email = helpdesk_email(@inviter.org)
5659

5760
I18n.with_locale I18n.default_locale do
5861
mail(to: @role.user.email,
@@ -69,6 +72,7 @@ def permissions_change_notification(role, user)
6972
@user = user
7073
@recepient = @role.user
7174
@messaging = role_text(@role)
75+
@helpdesk_email = helpdesk_email(@user.org)
7276

7377
I18n.with_locale I18n.default_locale do
7478
mail(to: @recepient.email,
@@ -83,6 +87,7 @@ def plan_access_removed(user, plan, current_user)
8387
@user = user
8488
@plan = plan
8589
@current_user = current_user
90+
@helpdesk_email = helpdesk_email(@plan.org)
8691

8792
I18n.with_locale I18n.default_locale do
8893
mail(to: @user.email,
@@ -100,6 +105,7 @@ def feedback_notification(recipient, plan, requestor)
100105
@recipient_name = @recipient.name(false)
101106
@requestor_name = @user.name(false)
102107
@plan_name = @plan.title
108+
@helpdesk_email = helpdesk_email(@plan.org)
103109

104110
I18n.with_locale I18n.default_locale do
105111
mail(to: @recipient.email,
@@ -118,6 +124,7 @@ def feedback_complete(recipient, plan, requestor)
118124
@plan = plan
119125
@phase = @plan.phases.first
120126
@plan_name = @plan.title
127+
@helpdesk_email = helpdesk_email(@plan.org)
121128

122129
I18n.with_locale I18n.default_locale do
123130
sender = Rails.configuration.x.organisation.do_not_reply_email ||
@@ -139,6 +146,7 @@ def plan_visibility(user, plan)
139146
@plan = plan
140147
@plan_title = @plan.title
141148
@plan_visibility = Plan::VISIBILITY_MESSAGE[@plan.visibility.to_sym]
149+
@helpdesk_email = helpdesk_email(@plan.org)
142150

143151
I18n.with_locale I18n.default_locale do
144152
mail(to: @user.email,
@@ -167,6 +175,7 @@ def new_comment(commenter, plan, answer)
167175
@section_title = @question.section.title
168176
@phase_id = @question.section.phase.id
169177
@phase_link = url_for(action: 'edit', controller: 'plans', id: @plan.id, phase_id: @phase_id)
178+
@helpdesk_email = helpdesk_email(@plan.org)
170179

171180
I18n.with_locale I18n.default_locale do
172181
mail(to: @plan.owner.email,
@@ -182,6 +191,7 @@ def admin_privileges(user)
182191
@user = user
183192
@username = @user.name
184193
@ul_list = privileges_list(@user)
194+
@helpdesk_email = helpdesk_email(@user.org)
185195

186196
I18n.with_locale I18n.default_locale do
187197
mail(to: user.email,
@@ -199,6 +209,8 @@ def api_credentials(api_client)
199209

200210
@name = @api_client.contact_name.present? ? @api_client.contact_name : @api_client.contact_email
201211

212+
@helpdesk_email = helpdesk_email(@api_client.org)
213+
202214
I18n.with_locale I18n.default_locale do
203215
mail(to: @api_client.contact_email,
204216
subject: format(_('%{tool_name} API changes'), tool_name: tool_name))

app/models/org.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# language_id :integer
2525
# region_id :integer
2626
# managed :boolean default(false), not null
27+
# helpdesk_email :string
2728
#
2829
# Foreign Keys
2930
#

app/views/devise/mailer/invitation_instructions.html.erb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
<%
22
tool_name = ApplicationService.application_name
33
link = accept_invitation_url(@resource, :invitation_token => @token)
4-
helpdesk_email = Rails.configuration.x.organisation.helpdesk_email
54
contact_us = (Rails.configuration.x.organisation.contact_us_url || contact_us_url)
65
email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name }
76
user_name = User.find_by(email: @resource.email).nil? ? @resource.email : User.find_by(email: @resource.email).name(false)
8-
inviter_name = @resource.invited_by.name
7+
inviter = @resource.invited_by
8+
inviter_name = inviter.name
9+
helpdesk_email = inviter.org.present? &&
10+
inviter.org.helpdesk_email.present? ?
11+
inviter.org.helpdesk_email :
12+
Rails.configuration.x.organisation.helpdesk_email
913
%>
1014
<% I18n.with_locale I18n.default_locale do %>
15+
<p>
16+
17+
18+
</p>
1119
<p>
12-
<%= _('Hello %{user_name}') %{ :user_name => user_name } %>
20+
<%= _("Hello %{user_name}"") %{ :user_name => user_name } %>
1321
</p>
1422
<p>
1523
<%= _("Your colleague %{inviter_name} has invited you to contribute to "\

app/views/devise/mailer/reset_password_instructions.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
helpdesk_email = Rails.configuration.x.organisation.helpdesk_email
44
contact_us = Rails.configuration.x.organisation.contact_us_url || contact_us_url
55
email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name }
6+
user = User.find_by(email: @resource.email)
7+
helpdesk_email = user.org.present? &&
8+
user.org.helpdesk_email.present? ?
9+
user.org.helpdesk_email :
10+
Rails.configuration.x.organisation.helpdesk_email
611
%>
712
<% I18n.with_locale I18n.default_locale do %>
813
<p>

app/views/orgs/_profile_form.html.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@
8686

8787
<hr>
8888

89+
<div class="row">
90+
<div class="form-group col-xs-8">
91+
<h3><%= _("Help Desk email") %></h3>
92+
</div>
93+
</div>
94+
<div class="row">
95+
<div class="form-group col-xs-4">
96+
<%= f.label :helpdesk_email, _('Help Desk email'), class: "control-label" %>
97+
<%= f.email_field :helpdesk_email, class: "form-control" %>
98+
</div>
99+
</div>
100+
101+
<hr>
102+
89103
<div class="row">
90104
<div class="form-group col-xs-8">
91105
<h3><%= _("Administrator contact") %></h3>

app/views/user_mailer/_email_signature.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<% end %>
1818
<%= _('Please do not reply to this email.') %>
1919
<%= sanitize(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us}') % {
20-
helpdesk_email: mail_to(helpdesk_email, helpdesk_email,
20+
helpdesk_email: mail_to(@helpdesk_email, @helpdesk_email,
2121
subject: email_subject),
2222
contact_us: link_to(contact_us, contact_us)
2323
}) %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddHelpdeskEmailToOrgs < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :orgs, :helpdesk_email, :string
4+
end
5+
end

0 commit comments

Comments
 (0)