Add notification mailer preview

This commit is contained in:
Luka Murn 2016-10-13 08:54:29 +02:00
parent 78f7879c04
commit bdaeb4db13
4 changed files with 77 additions and 12 deletions

View file

@ -557,7 +557,7 @@ class Users::SettingsController < ApplicationController
end end
def generate_notification(user, target_user, role, org) def generate_notification(user, target_user, role, org)
title = I18n.t('activities.assign_user_to_organization', title = I18n.t('notifications.assign_user_to_organization',
assigned_user: target_user.name, assigned_user: target_user.name,
role: role, role: role,
organization: org.name, organization: org.name,

View file

@ -5,13 +5,13 @@ class AppMailer < Devise::Mailer
default from: ENV["MAIL_FROM"] default from: ENV["MAIL_FROM"]
default reply: ENV["MAIL_REPLYTO"] default reply: ENV["MAIL_REPLYTO"]
def notification(user, notification) def notification(user, notification, opts = {})
@user = user @user = user
@notification = notification @notification = notification
headers = { headers = {
to: @user.email, to: @user.email,
subject: I18n.t('notifications.email_title') subject: I18n.t('notifications.email_title')
} }.merge(opts)
mail(headers) mail(headers)
end end
end end

View file

@ -1056,7 +1056,6 @@ en:
delete_step_comment: "<i>%{user}</i> deleted comment on Step %{step} <strong>%{step_name}</strong>." delete_step_comment: "<i>%{user}</i> deleted comment on Step %{step} <strong>%{step_name}</strong>."
edit_result_comment: "<i>%{user}</i> edited comment on result <strong>%{result}</strong>." edit_result_comment: "<i>%{user}</i> edited comment on result <strong>%{result}</strong>."
delete_result_comment: "<i>%{user}</i> deleted comment on result <strong>%{result}</strong>." delete_result_comment: "<i>%{user}</i> deleted comment on result <strong>%{result}</strong>."
assign_user_to_organization: "<i>%{assigned_user}</i> was added as %{role} to organization <strong>%{organization}</strong> by <i>%{assigned_by_user}</i>."
user_my_modules: user_my_modules:
new: new:
@ -1509,6 +1508,8 @@ en:
recent_changes: "Recent changes" recent_changes: "Recent changes"
system_message: "sciNote system message" system_message: "sciNote system message"
email_title: "You've received a sciNote notification!" email_title: "You've received a sciNote notification!"
assign_user_to_organization: "<i>%{assigned_user}</i> was added as %{role} to organization <strong>%{organization}</strong> by <i>%{assigned_by_user}</i>."
# This section contains general words that can be used in any parts of # This section contains general words that can be used in any parts of
# application. # application.

View file

@ -1,30 +1,94 @@
class AppMailerPreview < ActionMailer::Preview class AppMailerPreview < ActionMailer::Preview
def confirmation_instructions def confirmation_instructions
AppMailer.confirmation_instructions(fake_user, "faketoken", {}) AppMailer.confirmation_instructions(fake_user, 'faketoken', {})
end end
def reset_password_instructions def reset_password_instructions
AppMailer.reset_password_instructions(fake_user, "faketoken", {}) AppMailer.reset_password_instructions(fake_user, 'faketoken', {})
end end
def unlock_instructions def unlock_instructions
AppMailer.unlock_instructions(fake_user, "faketoken", {}) AppMailer.unlock_instructions(fake_user, 'faketoken', {})
end end
def invitation_instructions def invitation_instructions
AppMailer.invitation_instructions(fake_user, "faketoken", {}) AppMailer.invitation_instructions(fake_user, 'faketoken', {})
end
def assignment_notification
AppMailer.notification(
fake_user,
Notification.new(
type_of: :assignment,
title: I18n.t(
'notifications.assign_user_to_organization',
assigned_user: fake_user_2.full_name,
role: 'Administrator',
organization: fake_org.name,
assigned_by_user: fake_user.full_name
),
message: ActionController::Base.helpers.sanitize(
"<a href='#' target='_blank'>#{fake_org.name}</a>"
)
)
)
end
def recent_changes_notification
AppMailer.notification(
fake_user,
Notification.new(
type_of: :recent_changes,
title: I18n.t(
'activities.create_module',
user: fake_user.full_name,
module: 'How to shred'
),
message: ActionController::Base.helpers.sanitize(
'<a href="#" target="_blank">School of Rock</a>'
)
)
)
end
def system_message_notification
AppMailer.notification(
fake_user,
Notification.new(
type_of: :system_message,
title: 'sciNote 9.1 released!',
message: '<a href="#" target="_blank">View release notes</a>'
)
)
end end
private private
def fake_user def fake_user
User.new( User.new(
full_name: "Johny Cash", full_name: 'Johny Cash',
initials: "JC", initials: 'JC',
email: "johny.cash@gmail.com", email: 'johny.cash@gmail.com',
created_at: Time.now, created_at: Time.now,
updated_at: Time.now, updated_at: Time.now,
confirmed_at: Time.now confirmed_at: Time.now
) )
end end
def fake_user_2
User.new(
full_name: 'Bob Dylan',
initials: 'BD',
email: 'bob.dylan@gmail.com',
created_at: Time.now,
updated_at: Time.now,
confirmed_at: Time.now
)
end
def fake_org
Organization.new(
name: 'Greatest musicians of all time'
)
end
end end