-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7615 from fjordllc/feature/article-publication-no…
…tifications ブログ(articles)が公開されたら、管理者、メンター、現役一般受講生、現役研修生に通知する
- Loading branch information
Showing
12 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class ArticleNotificationDestroyer | ||
def call(payload) | ||
article = payload[:article] | ||
Notification.where(link: "/articles/#{article.id}").destroy_all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class ArticleNotifier | ||
def call(payload) | ||
article = payload[:article] | ||
return if article.wip? | ||
|
||
receivers = User.students_trainees_mentors_and_admins.reject { |receiver| receiver == article.user } | ||
send_notification(article:, receivers:) | ||
end | ||
|
||
private | ||
|
||
def send_notification(article:, receivers:) | ||
receivers.each do |receiver| | ||
ActivityDelivery.with(article:, receiver:).notify(:create_article) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= render '/notification_mailer/notification_mailer_template', | ||
title: "#{@article.user.login_name}さんがブログに「#{@article.title}」を投稿しました。", | ||
link_url: @link_url, link_text: 'ブログへ' do | ||
= md2html(@article.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1135,4 +1135,66 @@ class ActivityMailerTest < ActionMailer::TestCase | |
|
||
assert_empty ActionMailer::Base.deliveries | ||
end | ||
|
||
test 'create_article notifies students, trainees, mentors, and admins' do | ||
target_users = %i[hatsuno kensyu mentormentaro machida] | ||
|
||
target_users.each do |target_user| | ||
article = articles(:article1) | ||
receiver = users(target_user) | ||
|
||
ActivityMailer.create_article( | ||
article:, | ||
receiver: | ||
).deliver_now | ||
|
||
assert_not ActionMailer::Base.deliveries.empty? | ||
email = ActionMailer::Base.deliveries.last | ||
query = CGI.escapeHTML({ kind: 24, link: "/articles/#{article.id}" }.to_param) | ||
assert_equal ['[email protected]'], email.from | ||
assert_equal [receiver.email], email.to | ||
assert_equal "新しいブログ「#{article.title}」を#{article.user.login_name}さんが投稿しました!", email.subject | ||
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">ブログへ</a>}, email.body.to_s) | ||
end | ||
end | ||
|
||
test 'create_article notifies students, trainees, mentors, and admins with params' do | ||
target_users = %i[hatsuno kensyu mentormentaro machida] | ||
|
||
target_users.each do |target_user| | ||
article = articles(:article1) | ||
receiver = users(target_user) | ||
|
||
mailer = ActivityMailer.with( | ||
article:, | ||
receiver: | ||
).create_article | ||
|
||
perform_enqueued_jobs do | ||
mailer.deliver_later | ||
end | ||
|
||
assert_not ActionMailer::Base.deliveries.empty? | ||
email = ActionMailer::Base.deliveries.last | ||
query = CGI.escapeHTML({ kind: 24, link: "/articles/#{article.id}" }.to_param) | ||
assert_equal ['[email protected]'], email.from | ||
assert_equal [receiver.email], email.to | ||
assert_equal "新しいブログ「#{article.title}」を#{article.user.login_name}さんが投稿しました!", email.subject | ||
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">ブログへ</a>}, email.body.to_s) | ||
end | ||
end | ||
|
||
test 'create_article notifies students, trainees, mentors, and admins with mail_notification off' do | ||
article = articles(:article1) | ||
receiver = users(:mentormentaro) | ||
receiver.update(mail_notification: false) | ||
|
||
ActivityMailer.create_article( | ||
sender: article.user, | ||
receiver:, | ||
article: | ||
).deliver_now | ||
|
||
assert_empty ActionMailer::Base.deliveries | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters