From bffc46858a212091252aff185ac583eea7244947 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 19 Apr 2023 19:44:33 +0530 Subject: [PATCH] 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 --- .../solved-settings.hbs | 17 ++++++++++-- config/locales/client.en.yml | 1 + plugin.rb | 8 +++++- spec/integration/solved_spec.rb | 26 +++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.hbs index b78a359..aaf30ae 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings.hbs @@ -1,5 +1,6 @@ +

{{i18n "solved.title"}}

+ {{#unless siteSettings.allow_solved_on_all_topics}} -

{{i18n "solved.title"}}

-{{/unless}} \ No newline at end of file +{{/unless}} + +
+ + +
\ No newline at end of file diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 631381b..f5af30a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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" diff --git a/plugin.rb b/plugin.rb index 30d2982..a712428 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 = diff --git a/spec/integration/solved_spec.rb b/spec/integration/solved_spec.rb index 40013cf..0de7146 100644 --- a/spec/integration/solved_spec.rb +++ b/spec/integration/solved_spec.rb @@ -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)