FEATURE: send notification to OP when staff marked a post as solution. (#97)

Previously, we won't send any notification to the original poster when a staff user marked a post as the solution on behalf of OP.
This commit is contained in:
Vinoth Kannan 2020-10-30 22:01:27 +05:30 committed by GitHub
parent f1c417d693
commit f04ccbd4e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 5 deletions

View File

@ -7,6 +7,7 @@ en:
solved_quote_length: "Number of characters to quote when displaying the solution under the first post"
solved_topics_auto_close_hours: "Auto close topic (n) hours after the last reply once the topic has been marked as solved. Set to 0 to disable auto closing."
show_filter_by_solved_status: "Show a dropdown to filter a topic list by solved status."
notify_on_staff_accept_solved: "Send notification to the topic creator when a post is marked as solution by a staff."
reports:
accepted_solutions:
title: "Accepted solutions"

View File

@ -19,3 +19,5 @@ plugins:
show_filter_by_solved_status:
default: false
client: true
notify_on_staff_accept_solved:
default: false

View File

@ -108,17 +108,29 @@ SQL
)
end
notification_data = {
message: 'solved.accepted_notification',
display_username: acting_user.username,
topic_title: topic.title
}.to_json
unless acting_user.id == post.user_id
Notification.create!(
notification_type: Notification.types[:custom],
user_id: post.user_id,
topic_id: post.topic_id,
post_number: post.post_number,
data: {
message: 'solved.accepted_notification',
display_username: acting_user.username,
topic_title: topic.title
}.to_json
data: notification_data
)
end
if SiteSetting.notify_on_staff_accept_solved && acting_user.id != topic.user_id
Notification.create!(
notification_type: Notification.types[:custom],
user_id: topic.user_id,
topic_id: post.topic_id,
post_number: post.post_number,
data: notification_data
)
end

View File

@ -64,6 +64,32 @@ RSpec.describe "Managing Posts solved status" do
expect(topic.public_topic_timer.based_on_last_post).to eq(true)
end
it 'sends notifications to correct users' do
SiteSetting.notify_on_staff_accept_solved = true
user = Fabricate(:user)
topic = Fabricate(:topic, user: user)
post = Fabricate(:post, post_number: 2, topic: topic)
op = topic.user
user = post.user
expect {
DiscourseSolved.accept_answer!(post, Discourse.system_user)
}.to \
change { user.notifications.count }.by(1) &
change { op.notifications.count }.by(1)
notification = user.notifications.last
expect(notification.notification_type).to eq(Notification.types[:custom])
expect(notification.topic_id).to eq(post.topic_id)
expect(notification.post_number).to eq(post.post_number)
notification = op.notifications.last
expect(notification.notification_type).to eq(Notification.types[:custom])
expect(notification.topic_id).to eq(post.topic_id)
expect(notification.post_number).to eq(post.post_number)
end
it 'does not set a timer when the topic is closed' do
topic.update!(closed: true)
post "/solution/accept.json", params: { id: p1.id }