FEATURE: solved topic auto close setting per category (#233)
* FEATURE: solved topic auto close setting per category This commit adds per category "solved topics auto close hours" setting. The plugin would use the existing "solved topics auto close hours" setting, except if there was a setting for the relevant category in which case that would take precedence. * minor changes per feedback
This commit is contained in:
parent
4ae1841479
commit
bffc46858a
|
@ -1,5 +1,6 @@
|
|||
<h3>{{i18n "solved.title"}}</h3>
|
||||
|
||||
{{#unless siteSettings.allow_solved_on_all_topics}}
|
||||
<h3>{{i18n "solved.title"}}</h3>
|
||||
<section class="field">
|
||||
<div class="enable-accepted-answer">
|
||||
<label class="checkbox-label">
|
||||
|
@ -13,3 +14,15 @@
|
|||
</div>
|
||||
</section>
|
||||
{{/unless}}
|
||||
|
||||
<section class="field auto-close-solved-topics">
|
||||
<label for="auto-close-solved-topics">
|
||||
{{i18n "solved.solved_topics_auto_close_hours"}}
|
||||
</label>
|
||||
<NumberField
|
||||
@number={{this.category.custom_fields.solved_topics_auto_close_hours}}
|
||||
@id="auto-close-solved-topics"
|
||||
@type="number"
|
||||
@min="0"
|
||||
/>
|
||||
</section>
|
|
@ -9,6 +9,7 @@ en:
|
|||
solved:
|
||||
title: "Solved"
|
||||
allow_accepted_answers: "Allow topic owner and staff to mark a reply as the solution"
|
||||
solved_topics_auto_close_hours: "Auto close topic (n) hours after the last reply once the topic has been marked as solved."
|
||||
accept_answer: "Select if this reply solves the problem"
|
||||
accepted_description: "This is the accepted solution to this topic"
|
||||
has_no_accepted_answer: "This topic has no solution"
|
||||
|
|
|
@ -133,7 +133,13 @@ SQL
|
|||
)
|
||||
end
|
||||
|
||||
auto_close_hours = SiteSetting.solved_topics_auto_close_hours
|
||||
auto_close_hours = 0
|
||||
if topic&.category.present?
|
||||
auto_close_hours = topic.category.custom_fields["solved_topics_auto_close_hours"].to_i
|
||||
auto_close_hours = 175_200 if auto_close_hours > 175_200 # 20 years
|
||||
end
|
||||
|
||||
auto_close_hours = SiteSetting.solved_topics_auto_close_hours if auto_close_hours == 0
|
||||
|
||||
if (auto_close_hours > 0) && !topic.closed
|
||||
topic_timer =
|
||||
|
|
|
@ -61,6 +61,32 @@ RSpec.describe "Managing Posts solved status" do
|
|||
expect(topic.public_topic_timer.based_on_last_post).to eq(true)
|
||||
end
|
||||
|
||||
it "gives priority to category's solved_topics_auto_close_hours setting" do
|
||||
freeze_time
|
||||
custom_auto_close_category = Fabricate(:category)
|
||||
topic_2 = Fabricate(:topic, category: custom_auto_close_category)
|
||||
post_2 = Fabricate(:post, topic: topic_2)
|
||||
custom_auto_close_category.custom_fields["solved_topics_auto_close_hours"] = 4
|
||||
custom_auto_close_category.save_custom_fields
|
||||
|
||||
post "/solution/accept.json", params: { id: post_2.id }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(post_2.reload.custom_fields["is_accepted_answer"]).to eq("true")
|
||||
|
||||
topic_2.reload
|
||||
|
||||
expect(topic_2.public_topic_timer.status_type).to eq(TopicTimer.types[:silent_close])
|
||||
|
||||
expect(
|
||||
topic_2.custom_fields[DiscourseSolved::AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD].to_i,
|
||||
).to eq(topic_2.public_topic_timer.id)
|
||||
|
||||
expect(topic_2.public_topic_timer.execute_at).to eq_time(Time.zone.now + 4.hours)
|
||||
|
||||
expect(topic_2.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)
|
||||
|
|
Loading…
Reference in New Issue