Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: solved topic auto close setting per category #233

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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">
Expand All @@ -12,4 +13,16 @@
</label>
</div>
</section>
{{/unless}}
{{/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>
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ def self.accept_answer!(post, acting_user, topic: nil)
)
end

auto_close_hours = SiteSetting.solved_topics_auto_close_hours
if topic&.category.present?
auto_close_hours =
topic&.category&.custom_fields&.[]("solved_topics_auto_close_hours").to_i
arpitjalan marked this conversation as resolved.
Show resolved Hide resolved
auto_close_hours = 175_200 if auto_close_hours > 175_200 # 20 years
end

if auto_close_hours.nil? || auto_close_hours == 0
arpitjalan marked this conversation as resolved.
Show resolved Hide resolved
auto_close_hours = SiteSetting.solved_topics_auto_close_hours
end

if (auto_close_hours > 0) && !topic.closed
topic_timer =
Expand Down
26 changes: 26 additions & 0 deletions spec/integration/solved_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@
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)
Expand Down