mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Add notification mailer preview
This commit is contained in:
parent
78f7879c04
commit
bdaeb4db13
|
@ -557,7 +557,7 @@ class Users::SettingsController < ApplicationController
|
|||
end
|
||||
|
||||
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,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
|
|
|
@ -5,13 +5,13 @@ class AppMailer < Devise::Mailer
|
|||
default from: ENV["MAIL_FROM"]
|
||||
default reply: ENV["MAIL_REPLYTO"]
|
||||
|
||||
def notification(user, notification)
|
||||
def notification(user, notification, opts = {})
|
||||
@user = user
|
||||
@notification = notification
|
||||
headers = {
|
||||
to: @user.email,
|
||||
subject: I18n.t('notifications.email_title')
|
||||
}
|
||||
}.merge(opts)
|
||||
mail(headers)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1056,7 +1056,6 @@ en:
|
|||
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>."
|
||||
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:
|
||||
new:
|
||||
|
@ -1509,6 +1508,8 @@ en:
|
|||
recent_changes: "Recent changes"
|
||||
system_message: "sciNote system message"
|
||||
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
|
||||
# application.
|
||||
|
||||
|
|
|
@ -1,30 +1,94 @@
|
|||
class AppMailerPreview < ActionMailer::Preview
|
||||
def confirmation_instructions
|
||||
AppMailer.confirmation_instructions(fake_user, "faketoken", {})
|
||||
AppMailer.confirmation_instructions(fake_user, 'faketoken', {})
|
||||
end
|
||||
|
||||
def reset_password_instructions
|
||||
AppMailer.reset_password_instructions(fake_user, "faketoken", {})
|
||||
AppMailer.reset_password_instructions(fake_user, 'faketoken', {})
|
||||
end
|
||||
|
||||
def unlock_instructions
|
||||
AppMailer.unlock_instructions(fake_user, "faketoken", {})
|
||||
AppMailer.unlock_instructions(fake_user, 'faketoken', {})
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def fake_user
|
||||
User.new(
|
||||
full_name: "Johny Cash",
|
||||
initials: "JC",
|
||||
email: "johny.cash@gmail.com",
|
||||
full_name: 'Johny Cash',
|
||||
initials: 'JC',
|
||||
email: 'johny.cash@gmail.com',
|
||||
created_at: Time.now,
|
||||
updated_at: Time.now,
|
||||
confirmed_at: Time.now
|
||||
)
|
||||
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
|
Loading…
Reference in a new issue