Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discourse_solved:
solved_enabled:
default: true
default: false
client: true
show_who_marked_solved:
default: false
Expand Down Expand Up @@ -59,4 +59,3 @@ discourse_solved:
enable_solved_tags:
type: tag_list
default: ""

23 changes: 23 additions & 0 deletions db/migrate/20250721192553_enable_solved_if_already_installed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class EnableSolvedIfAlreadyInstalled < ActiveRecord::Migration[7.2]
def up
installed_at = DB.query_single(<<~SQL)&.first
SELECT created_at FROM schema_migration_details WHERE version='20191209095548'
SQL

if installed_at && installed_at < 1.hour.ago
# The plugin was installed before we changed it to be disabled-by-default
# Therefore, if there is no existing database value, enable the plugin
execute <<~SQL
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
VALUES('solved_enabled', 5, 't', NOW(), NOW())
ON CONFLICT (name) DO NOTHING
SQL
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
5 changes: 4 additions & 1 deletion spec/components/composer_messages_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, user: Fabricate(:user)) }

before { SiteSetting.disable_solved_education_message = false }
before do
enable_current_plugin
SiteSetting.disable_solved_education_message = false
end

it "does not show message without a topic id" do
expect(
Expand Down
2 changes: 2 additions & 0 deletions spec/components/post_revisor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
category
end

before { enable_current_plugin }

it "refreshes post stream when topic category changes to a solved category" do
topic = Fabricate(:topic, category: Fabricate(:category_with_definition))
post = Fabricate(:post, topic: topic)
Expand Down
5 changes: 4 additions & 1 deletion spec/integration/solved_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
fab!(:user) { Fabricate(:trust_level_4) }
let(:p1) { Fabricate(:post, topic: topic) }

before { SiteSetting.allow_solved_on_all_topics = true }
before do
enable_current_plugin
SiteSetting.allow_solved_on_all_topics = true
end

describe "customer filters" do
before do
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/first_accepted_post_solution_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
describe DiscourseSolved::FirstAcceptedPostSolutionValidator do
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }

before { enable_current_plugin }

context "when trust level is 'any'" do
it "validates the post" do
post = Fabricate(:post, user: user_tl1)
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/guardian_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

let(:guardian) { user.guardian }

before { SiteSetting.allow_solved_on_all_topics = true }
before do
enable_current_plugin
SiteSetting.allow_solved_on_all_topics = true
end

describe ".can_accept_answer?" do
it "returns false for anon users" do
Expand Down
2 changes: 2 additions & 0 deletions spec/models/copy_solved_topic_custom_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
RSpec.describe CopySolvedTopicCustomFieldToDiscourseSolvedSolvedTopics, type: :migration do
let(:migration) { described_class.new }

before { enable_current_plugin }

describe "handling duplicates" do
it "ensures only unique topic_id and answer_post_id are inserted" do
topic = Fabricate(:topic)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/directory_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
fab!(:pm) { Fabricate(:topic, archetype: "private_message", user:, category_id: nil) }
fab!(:pm_post) { Fabricate(:post, topic: pm, user:) }

before { SiteSetting.solved_enabled = true }
before { enable_current_plugin }

it "excludes PM post solutions from solutions" do
DiscourseSolved.accept_answer!(topic_post1, admin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:migration) { described_class.new }

before do
enable_current_plugin
# temp drop unique constraints to allow testing duplicate entries
ActiveRecord::Base.connection.execute(
"DROP INDEX IF EXISTS index_discourse_solved_solved_topics_on_topic_id;",
Expand Down
5 changes: 4 additions & 1 deletion spec/models/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
let(:category) { Fabricate(:category) }
let(:guardian) { Guardian.new }

before { SiteSetting.show_filter_by_solved_status = true }
before do
enable_current_plugin
SiteSetting.show_filter_by_solved_status = true
end

it "includes `enable_accepted_answers` custom field for categories" do
category.custom_fields["enable_accepted_answers"] = true
Expand Down
2 changes: 2 additions & 0 deletions spec/models/user_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
describe UserSummary do
fab!(:admin)

before { enable_current_plugin }

describe "solved_count" do
it "indicates the number of times a user's post is a topic's solution" do
topic = Fabricate(:topic)
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/answer_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
fab!(:solution_post) { Fabricate(:post, topic: topic) }

before do
SiteSetting.solved_enabled = true
enable_current_plugin
SiteSetting.allow_solved_on_all_topics = true
category.custom_fields[DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD] = "true"
category.save_custom_fields
Expand Down
5 changes: 4 additions & 1 deletion spec/requests/list_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
fab!(:p2) { Fabricate(:post, topic: p1.topic) }
fab!(:p3) { Fabricate(:post, topic: p1.topic) }

before { SiteSetting.allow_solved_on_all_topics = true }
before do
enable_current_plugin
SiteSetting.allow_solved_on_all_topics = true
end

it "shows the user who posted the accepted answer second" do
TopicFeaturedUsers.ensure_consistency!
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/solved_topics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
fab!(:answer_post) { Fabricate(:post, topic:, user:) }
fab!(:solved_topic) { Fabricate(:solved_topic, topic:, answer_post:) }

before { enable_current_plugin }

describe "#by_user" do
context "when accessing with username" do
it "returns solved posts for the specified user" do
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/topics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
let(:topic) { p1.topic }
let(:p2) { Fabricate(:post, like_count: 2, topic: topic, user: Fabricate(:user)) }

before { enable_current_plugin }

def schema_json(answerCount)
if answerCount > 0
answer_json =
Expand Down
5 changes: 4 additions & 1 deletion spec/serializers/topic_answer_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
let(:post) { Fabricate(:post, topic: topic) }
let(:guardian) { Guardian.new }

before { Fabricate(:solved_topic, topic: topic, answer_post: post) }
before do
enable_current_plugin
Fabricate(:solved_topic, topic: topic, answer_post: post)
end

it "should have true for `has_accepted_answer` field in each serializer" do
[
Expand Down
2 changes: 1 addition & 1 deletion spec/serializers/topic_view_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
fab!(:post2) { Fabricate(:post, topic:) }
fab!(:user)

before { SiteSetting.solved_enabled = true }
before { enable_current_plugin }

describe "#accepted_answer" do
it "returns the accepted answer post when the topic has an accepted answer" do
Expand Down
2 changes: 2 additions & 0 deletions spec/serializers/user_card_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
let(:serializer) { described_class.new(user, scope: Guardian.new, root: false) }
let(:json) { serializer.as_json }

before { enable_current_plugin }

it "accepted_answers serializes number of accepted answers" do
expect(serializer.as_json[:accepted_answers]).to eq(0)

Expand Down
2 changes: 1 addition & 1 deletion spec/system/solved_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:topic_page) { PageObjects::Pages::Topic.new }

before do
SiteSetting.solved_enabled = true
enable_current_plugin
SiteSetting.allow_solved_on_all_topics = true
SiteSetting.accept_all_solutions_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.show_who_marked_solved = true
Expand Down