diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index a1f6243..47b02dd 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,11 +1,11 @@ class UserMailer < ActionMailer::Base default from: Rails.configuration.branding[:organisation][:email] - + def welcome_notification(user) @user = user FastGettext.with_locale FastGettext.default_locale do mail(to: @user.email, - subject: "#{_('Welcome to')} #{Rails.configuration.branding[:application][:name]}") + subject: _('Welcome to %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end @@ -14,19 +14,20 @@ @user = user FastGettext.with_locale FastGettext.default_locale do mail(to: @role.user.email, - subject: "#{_('A Data Management Plan in ')} #{Rails.configuration.branding[:application][:name]} #{_(' has been shared with you')}") + subject: _('A Data Management Plan in %{tool_name} has been shared with you') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end - def permissions_change_notification(role, current_user) + def permissions_change_notification(role, user) @role = role - @current_user = current_user + @user = user FastGettext.with_locale FastGettext.default_locale do mail(to: @role.user.email, - subject: "#{_('Changed permissions on a DMP in')} #{Rails.configuration.branding[:application][:name]}") + subject: _('Changed permissions on a Data Management Plan in %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end + # TODO evaluate if it is needed since https://docs.google.com/document/d/1Zt3QfPZ2q6yMOCVFOevXviwRX-XbZeGSxAAvbRa9w-M/edit does not mention it def project_access_removed_notification(user, plan, current_user) @user = user @plan = plan @@ -41,7 +42,7 @@ @user = user FastGettext.with_locale FastGettext.default_locale do mail(to: @user.email, - subject: "#{_('API rights in')} #{Rails.configuration.branding[:application][:name]}") + subject: _('API rights in %{tool_name}') %{ :tool_name => Rails.configuration.branding[:application][:name] }) end end diff --git a/app/models/role.rb b/app/models/role.rb index 588d55c..28f63f1 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -37,6 +37,27 @@ return 1 end end + # Returns a hash of hashes where each key represents an access level (e.g. see access_level method to understand the integers) + # This method becomes useful for generatic template messages (e.g. permissions change notification mailer) + def self.access_level_messages + { + 3 => { + :type => _('co-owner'), + :placeholder1 => _('write and edit the plan in a collaborative manner.'), + :placeholder2 => _('You can also grant rights to other collaborators.') + }, + 2 => { + :type => _('editor'), + :placeholder1 => _('write and edit the plan in a collaborative manner.'), + :placeholder2 => nil, + }, + 1 => { + :type => _('read-only'), + :placeholder1 => _('read the plan and leave comments.'), + :placeholder2 => nil, + } + } + end def set_defaults self.active = true if self.new_record? diff --git a/app/views/devise/mailer/invitation_instructions.html.erb b/app/views/devise/mailer/invitation_instructions.html.erb index c7235c1..9476b25 100644 --- a/app/views/devise/mailer/invitation_instructions.html.erb +++ b/app/views/devise/mailer/invitation_instructions.html.erb @@ -1,8 +1,26 @@ +<% + tool_name = Rails.configuration.branding[:application][:name] + link = accept_invitation_url(@resource, :invitation_token => @token) + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } +%> <% FastGettext.with_locale FastGettext.default_locale do %> -
<%= _("Hello") %> <%= @resource.email %>,
-<%= _("A colleague has invited you to contribute to their Data Management Plan at ") %> <%= link_to Rails.configuration.branding[:application][:name], root_url %>.
-<%= link_to _("Click here to accept the invitation"), accept_invitation_url(@resource, :invitation_token => @token) %> (<%= _("or copy") %> <%= accept_invitation_url(@resource, :invitation_token => @token) %> <%= _("into your browser") %>).
-<%= _("If you don't want to accept the invitation, please ignore this email.") %>
<%= _("Your account won't be created until you access the link above and set your password.") %>
<%=_('All the best,')%>
<%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
+ <%= _('Hello %{user_email}') %{ :user_email => @resource.email } %> +
++ <%= _('A colleague has invited you to contribute to their Data Management Plan in %{tool_name}') %{ :tool_name => tool_name } %> +
++ <%= raw(_('%{click_here} to accept the invitation, (or copy %{link} into your browser). If you don\'t want to accept the invitation, please ignore this email.') %{ :click_here => link_to(_('Click here'), link), :link => link }) %> +
+
+ <%= _('All the best') %>
+
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('Please do not reply to this email.') %> <%= raw(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %> +
+<% end %> \ No newline at end of file diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index 55858c9..27b4a91 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -1,13 +1,24 @@ +<% + tool_name = Rails.configuration.branding[:application][:name] + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } +%> <% FastGettext.with_locale FastGettext.default_locale do %> -<%= _("Hello ") %><%= @resource.email %>
- -<%= _("Someone has requested a link to change your ") %><%= Rails.configuration.branding[:application][:name] %><%= _(" password. You can do this through the link below.") %>
- -<%= link_to _('Change my password'), edit_password_url(@resource, :reset_password_token => @token) %>
- -<%= _("If you didn't request this, please ignore this email.") %>
-
- <%= _("Many thanks,") %>
<%= _('The ') %><%= Rails.configuration.branding[:application][:name] %><%= _(' team') %>
+ <%= _('Hello %{user_email}') %{ :user_email => @resource.email } %>
+
+ <%= _('Someone has requested a link to change your %{tool_name} password. You can do this through the link below.') %{ :tool_name => tool_name } %> +
+<%= link_to _('Change my password'), edit_password_url(@resource, :reset_password_token => @token) %>
+<%= _("If you didn't request this, please ignore this email.") %>
+
+ <%= _('All the best') %>
+
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('Please do not reply to this email.') %> <%= raw(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %>
<% end %> \ No newline at end of file diff --git a/app/views/user_mailer/api_token_granted_notification.html.erb b/app/views/user_mailer/api_token_granted_notification.html.erb index 69051d0..6177c46 100644 --- a/app/views/user_mailer/api_token_granted_notification.html.erb +++ b/app/views/user_mailer/api_token_granted_notification.html.erb @@ -1,12 +1,24 @@ +<% + tool_name = Rails.configuration.branding[:application][:name] + username = @user.name + api_documentation_url = Rails.configuration.branding[:application][:api_documentation_url] + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } +%> <% FastGettext.with_locale FastGettext.default_locale do %> -<% _('Hello ') %><%= @user.name %>
- -<%= _('You have been granted permission by your organisation to use our API. Your API token and instructions for using the API endpoints can be found ')%>here. -
-- <%=_('All the best,')%> + <%= _('Hello %{username}') %{ :username => username } %> +
++ <%= raw(_('You have been granted permission by your organisation to use our API. Your API token and instructions for using the API endpoints can be found at: %{link}') %{ :link => link_to(api_documentation_url, api_documentation_url) }) %> +
+
+ <%= _('All the best') %>
- <%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('Please do not reply to this email.') %> <%= raw(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %>
<% end %> \ No newline at end of file diff --git a/app/views/user_mailer/permissions_change_notification.html.erb b/app/views/user_mailer/permissions_change_notification.html.erb index c2c0740..0987cdb 100644 --- a/app/views/user_mailer/permissions_change_notification.html.erb +++ b/app/views/user_mailer/permissions_change_notification.html.erb @@ -1,18 +1,27 @@ -<% FastGettext.with_locale FastGettext.default_locale do %> -<% - access_level = "read-only" - permissions = "This means you can read the plan and leave comments." - if @role.editor? - access_level = "editor" - permissions = "This means you can write and edit the plan in a collaborative manner." - end - if @role.administrator? - access_level = "co-owner" - permissions = "This means you can write and edit the plan in a collaborative manner. You can also grant rights to other collaborators." - end +<% + tool_name = Rails.configuration.branding[:application][:name] + username = @user.name + plan_title = @role.plan.title + access = nil + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } + access_level = @role.access_level() + access_level_messages = Role.access_level_messages %> -<%= _('Hello ') %><%= @role.user.name %>,
-<%= _('Your permissions relating to ') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%= _(' have been changed by') %><%="#{@current_user.name(false)}. " %><%= _('You now have ') %><%= access_level %><%= _(' access. ') %><%= permissions %>
-<%=_('All the best,')%>
<%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
+ <%= _('Hello %{username}') %{ :username => username } %> +
++ <%= _('Your permissions relating to %{plan_title} have changed. You now have %{type} access. This means you can %{placeholder1} %{placeholder2}') %{ :plan_title => plan_title, :type => access_level_messages[access_level][:type], :placeholder1 => access_level_messages[access_level][:placeholder1], :placeholder2 => access_level_messages[access_level][:placeholder2] } %> +
+
+ <%= _('All the best') %>
+
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('You may change your notification preferences on your profile page.') %> <%= _('Please do not reply to this email.') %> <%= raw(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %> +
<% end %> diff --git a/app/views/user_mailer/sharing_notification.html.erb b/app/views/user_mailer/sharing_notification.html.erb index dc2fed4..2b55207 100644 --- a/app/views/user_mailer/sharing_notification.html.erb +++ b/app/views/user_mailer/sharing_notification.html.erb @@ -1,22 +1,28 @@ -<% FastGettext.with_locale FastGettext.default_locale do %> -<% - access_level = "read-only" - permissions = "This means you can read the plan and leave comments." - if @role.editor? - access_level = "editor" - permissions = "This means you can write and edit the plan in a collaborative manner." - end - if @role.administrator? - access_level = "co-owner" - permissions = "This means you can write and edit the plan in a collaborative manner. You can also grant rights to other collaborators." - end +<% + tool_name = Rails.configuration.branding[:application][:name] + user_email = @user.email + link = url_for(action: 'show', controller: 'plans', id: @role.plan.id) + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } %> -<%= _('Hello ') %><%= @role.user.name %>,
-<%= _('A colleague has invited you to contribute to their Data Management Plan at ') %><%= link_to Rails.configuration.branding[:application][:name], root_url %>.
-<%= _('You have been given ') %><%= access_level %><%= _(' access to') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%=_('by ')%><%= "#{@user.name(false)}" %>.
-<%= link_to _('Click here'), url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' to accept the invitation, (or copy ') %><%= url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' into your browser)')%>
-<%= _('If you don\'t want to accept the invitation, please ignore this email.') %>
-<%=_('All the best,')%>
<%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
+ <%= _('Hello %{user_email}') %{ :user_email => user_email } %> +
++ <%= _('A colleague has invited you to contribute to their Data Management Plan in %{tool_name}') %{ :tool_name => tool_name }%> +
++ <%= raw(_('%{click_here} to accept the invitation, (or copy %{link} into your browser). If you don\'t want to accept the invitation, please ignore this email.') %{ :click_here => link_to(_('Click here'), link), :link => link }) %> +
+
+ <%= _('All the best') %>
+
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('Please do not reply to this email.') %> <%= raw(_('If you have any questions or need help, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %> +
<% end %> diff --git a/app/views/user_mailer/welcome_notification.html.erb b/app/views/user_mailer/welcome_notification.html.erb index 7bda2d0..a02da97 100644 --- a/app/views/user_mailer/welcome_notification.html.erb +++ b/app/views/user_mailer/welcome_notification.html.erb @@ -1,11 +1,23 @@ +<% + tool_name = Rails.configuration.branding[:application][:name] + username = @user.name + helpdesk_email = Rails.configuration.branding[:organisation][:helpdesk_email] + contact_us_url = Rails.configuration.branding[:organisation][:contact_us_url] + email_subject = _('Query or feedback related to %{tool_name}') %{ :tool_name => tool_name } +%> <% FastGettext.with_locale FastGettext.default_locale do %> -<%= _('Welcome to ') %><%= Rails.configuration.branding[:application][:name] %>
- -<%= Rails.configuration.branding[:application][:name] %><%= _(' will help you to develop your Data Management Plan. If you have any queries or feedback as you use the tool, please contact us on ') %><%= Rails.configuration.branding[:application][:email] %>
-- <%=_('All the best,')%> + <%= _('Welcome to %{tool_name}, %{username}') %{ :tool_name => tool_name, :username => username } %> +
++ <%= raw(_('%{tool_name} will help you to develop your Data Management Plan. If you have any queries or feedback as you use the tool, please contact us at %{helpdesk_email} or visit %{contact_us_url}') %{ :tool_name => tool_name, :helpdesk_email => mail_to(helpdesk_email, helpdesk_email, subject: email_subject), :contact_us_url => link_to(contact_us_url, contact_us_url) }) %> +
+
+ <%= _('All the best') %>
- <%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.
+ <%= _('The %{tool_name} team') %{:tool_name => tool_name} %>
+
+ <%= _('You may change your notification preferences on your profile page.') %> <%= _('Please do not reply to this email.') %>
<% end %> \ No newline at end of file diff --git a/config/branding_example.yml b/config/branding_example.yml index 47d0b2c..a81af4c 100644 --- a/config/branding_example.yml +++ b/config/branding_example.yml @@ -8,6 +8,8 @@ url: 'https://github.com/DMPRoadmap/roadmap/wiki' copywrite_name: 'Curation Centre (CC)' email: 'tester@cc_curation_centre.org' + helpdesk_email: 'someone@somewhere.com' + contact_us_url: 'https://somewhere.com/contact-us' application: name: 'DMPRoadmap' @@ -16,6 +18,7 @@ release_notes_url: 'https://github.com/DMPRoadmap/roadmap/wiki/Releases' issue_list_url: 'https://github.com/DMPRoadmap/roadmap/issues' user_group_subscription_url: 'http://listserv.ucop.edu/cgi-bin/wa.exe?SUBED1=ROADMAP-L&A=1' + api_documentation_url: 'https://github.com/DMPRoadmap/roadmap/wiki/API-Documentation' preferences: email: diff --git a/test/mailers/previews/user_mailer_preview.rb b/test/mailers/previews/user_mailer_preview.rb new file mode 100644 index 0000000..a55b3be --- /dev/null +++ b/test/mailers/previews/user_mailer_preview.rb @@ -0,0 +1,17 @@ +class UserMailerPreview < ActionMailer::Preview + def welcome_notification + UserMailer.welcome_notification(User.find_by(email: 'super_admin@example.com')) + end + def sharing_notification + user = User.find_by(email: 'super_admin@example.com') + UserMailer.sharing_notification(Role.find_by(user_id: user.id), user) + end + def permissions_change_notification + user = User.find_by(email: 'super_admin@example.com') + UserMailer.permissions_change_notification(Role.find_by(user_id: user.id), user) + end + def api_token_granted_notification + user = User.find_by(email: 'super_admin@example.com') + UserMailer.api_token_granted_notification(user) + end +end \ No newline at end of file