diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 7a86565e3..c1cc604f7 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -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, diff --git a/app/mailers/app_mailer.rb b/app/mailers/app_mailer.rb index 56a8e5a3e..4c0df34a1 100644 --- a/app/mailers/app_mailer.rb +++ b/app/mailers/app_mailer.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f958b1e63..7380c1e15 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1056,7 +1056,6 @@ en: delete_step_comment: "%{user} deleted comment on Step %{step} %{step_name}." edit_result_comment: "%{user} edited comment on result %{result}." delete_result_comment: "%{user} deleted comment on result %{result}." - assign_user_to_organization: "%{assigned_user} was added as %{role} to organization %{organization} by %{assigned_by_user}." 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: "%{assigned_user} was added as %{role} to organization %{organization} by %{assigned_by_user}." + # This section contains general words that can be used in any parts of # application. diff --git a/test/mailers/previews/app_mailer_preview.rb b/test/mailers/previews/app_mailer_preview.rb index 8bb5e72b4..3aa8fb8a2 100644 --- a/test/mailers/previews/app_mailer_preview.rb +++ b/test/mailers/previews/app_mailer_preview.rb @@ -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( + "#{fake_org.name}" + ) + ) + ) + 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( + 'School of Rock' + ) + ) + ) + end + + def system_message_notification + AppMailer.notification( + fake_user, + Notification.new( + type_of: :system_message, + title: 'sciNote 9.1 released!', + message: 'View release notes' + ) + ) 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 -end \ No newline at end of file + + 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