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:
parent
f1c417d693
commit
f04ccbd4e6
|
@ -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"
|
||||
|
|
|
@ -19,3 +19,5 @@ plugins:
|
|||
show_filter_by_solved_status:
|
||||
default: false
|
||||
client: true
|
||||
notify_on_staff_accept_solved:
|
||||
default: false
|
||||
|
|
22
plugin.rb
22
plugin.rb
|
@ -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
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue