FEATURE: Send an email notification when a post is approved. (#12665)
We now send an email when a queued post is approved, and we create a notification.
This commit is contained in:
parent
045adb76f2
commit
958fbfb719
|
@ -37,6 +37,20 @@ class UserNotifications < ActionMailer::Base
|
|||
new_user_tips: tips)
|
||||
end
|
||||
|
||||
def post_approved(user, opts = {})
|
||||
post_url = opts.dig(:notification_data_hash, :post_url)
|
||||
|
||||
return if post_url.nil?
|
||||
|
||||
locale = user_locale(user)
|
||||
build_email(user.email,
|
||||
template: 'user_notifications.post_approved',
|
||||
locale: locale,
|
||||
base_url: Discourse.base_url,
|
||||
post_url: post_url
|
||||
)
|
||||
end
|
||||
|
||||
def signup_after_reject(user, opts = {})
|
||||
locale = user_locale(user)
|
||||
build_email(user.email,
|
||||
|
|
|
@ -97,7 +97,7 @@ class ReviewableQueuedPost < Reviewable
|
|||
Notification.create!(
|
||||
notification_type: Notification.types[:post_approved],
|
||||
user_id: created_by.id,
|
||||
data: {},
|
||||
data: { post_url: created_post.url }.to_json,
|
||||
topic_id: created_post.topic_id,
|
||||
post_number: created_post.post_number
|
||||
)
|
||||
|
|
|
@ -38,6 +38,10 @@ class NotificationEmailer
|
|||
enqueue :user_watching_first_post
|
||||
end
|
||||
|
||||
def post_approved
|
||||
enqueue :post_approved
|
||||
end
|
||||
|
||||
def private_message
|
||||
enqueue_private(:user_private_message)
|
||||
end
|
||||
|
@ -52,16 +56,17 @@ class NotificationEmailer
|
|||
|
||||
def self.notification_params(notification, type)
|
||||
post_id = (notification.data_hash[:original_post_id] || notification.post_id).to_i
|
||||
notification_type = Notification.types[notification.notification_type]
|
||||
|
||||
hash = {
|
||||
type: type,
|
||||
user_id: notification.user_id,
|
||||
notification_id: notification.id,
|
||||
notification_data_hash: notification.data_hash,
|
||||
notification_type: Notification.types[notification.notification_type],
|
||||
notification_type: notification_type,
|
||||
}
|
||||
|
||||
hash[:post_id] = post_id if post_id > 0
|
||||
hash[:post_id] = post_id if post_id > 0 && notification_type != :post_approved
|
||||
hash
|
||||
end
|
||||
|
||||
|
|
|
@ -3924,6 +3924,13 @@ en:
|
|||
|
||||
If this was not you, please [review your existing sessions](%{base_url}/my/preferences/account) and consider changing your password.
|
||||
|
||||
post_approved:
|
||||
title: "Your post was approved"
|
||||
subject_template: "[%{site_name}] Your post was approved"
|
||||
text_body_template: |
|
||||
Hello,
|
||||
|
||||
This is an automated message from %{site_name} to let you know that [your post](%{base_url}%{post_url}) was approved.
|
||||
page_forbidden:
|
||||
title: "Oops! That page is private."
|
||||
|
||||
|
|
|
@ -80,6 +80,19 @@ describe UserNotifications do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.post_approved' do
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
|
||||
it 'works' do
|
||||
subject = UserNotifications.post_approved(user, { notification_data_hash: { post_url: post.url } })
|
||||
|
||||
expect(subject.to).to eq([user.email])
|
||||
expect(subject.subject).to be_present
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.body).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe ".confirm_new_email" do
|
||||
let(:opts) do
|
||||
{ requested_by_admin: requested_by_admin, email_token: token }
|
||||
|
|
|
@ -244,5 +244,14 @@ describe NotificationEmailer do
|
|||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'post_approved' do
|
||||
let(:no_delay) { no_delay }
|
||||
let(:type) { :post_approved }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:post_approved) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue