Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f231aad

Browse files
authored
DEV: Disable the plugin by default (#1511)
…and preserve the current setting on existing sites
1 parent cc77e73 commit f231aad

File tree

238 files changed

+570
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+570
-128
lines changed

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
discourse_ai:
22
discourse_ai_enabled:
3-
default: true
3+
default: false
44
client: true
55
ai_artifact_security:
66
client: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
class EnableAiIfAlreadyInstalled < ActiveRecord::Migration[7.2]
4+
def up
5+
installed_at = DB.query_single(<<~SQL)&.first
6+
SELECT created_at FROM schema_migration_details WHERE version='20230224165056'
7+
SQL
8+
9+
if installed_at && installed_at < 1.hour.ago
10+
# The plugin was installed before we changed it to be disabled-by-default
11+
# Therefore, if there is no existing database value, enable the plugin
12+
execute <<~SQL
13+
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
14+
VALUES('discourse_ai_enabled', 5, 't', NOW(), NOW())
15+
ON CONFLICT (name) DO NOTHING
16+
SQL
17+
end
18+
end
19+
20+
def down
21+
raise ActiveRecord::IrreversibleMigration
22+
end
23+
end

spec/configuration/feature_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def allow_configuring_setting(&block)
1010
DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) { block.call }
1111
end
1212

13+
before { enable_current_plugin }
14+
1315
describe "#llm_model" do
1416
context "when persona is not found" do
1517
it "returns nil when persona_id is invalid" do

spec/configuration/llm_enumerator_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Fabricate(:automation, script: "llm_report", name: "some automation", enabled: true)
99
end
1010

11+
before { enable_current_plugin }
12+
1113
describe "#values_for_serialization" do
1214
it "returns an array for that can be used for serialization" do
1315
fake_model.destroy!

spec/configuration/llm_validator_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
RSpec.describe DiscourseAi::Configuration::LlmValidator do
4+
before { enable_current_plugin }
5+
46
describe "#valid_value?" do
57
context "when the parent module is enabled and we try to reset the selected model" do
68
before do

spec/configuration/spam_detection_validator_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
RSpec.describe DiscourseAi::Configuration::SpamDetectionValidator do
44
let(:validator) { described_class.new }
55

6+
before { enable_current_plugin }
7+
68
it "always returns true if setting the value to false" do
79
expect(validator.valid_value?("f")).to eq(true)
810
end

spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
RSpec.describe MigrateSentimentClassificationResultFormat do
99
let(:connection) { ActiveRecord::Base.connection }
1010

11-
before { connection.execute(<<~SQL) }
11+
before do
12+
enable_current_plugin
13+
connection.execute(<<~SQL)
1214
INSERT INTO classification_results (model_used, classification, created_at, updated_at) VALUES
1315
('sentiment', '{"neutral": 65, "negative": 20, "positive": 14}', NOW(), NOW()),
1416
('emotion', '{"sadness": 10, "surprise": 15, "fear": 5, "anger": 20, "joy": 30, "disgust": 8, "neutral": 10}', NOW(), NOW());
1517
SQL
18+
end
1619

1720
after { connection.execute("DELETE FROM classification_results") }
1821

@@ -21,7 +24,7 @@
2124

2225
it "migrates sentiment classifications correctly" do
2326
sentiment_result = connection.execute(<<~SQL).first
24-
SELECT * FROM classification_results
27+
SELECT * FROM classification_results
2528
WHERE model_used = 'cardiffnlp/twitter-roberta-base-sentiment-latest';
2629
SQL
2730

@@ -32,7 +35,7 @@
3235

3336
it "migrates emotion classifications correctly" do
3437
emotion_result = connection.execute(<<~SQL).first
35-
SELECT * FROM classification_results
38+
SELECT * FROM classification_results
3639
WHERE model_used = 'j-hartmann/emotion-english-distilroberta-base';
3740
SQL
3841

spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def configured_model_id
2121
).first
2222
end
2323

24+
before { enable_current_plugin }
25+
2426
describe "#up" do
2527
context "when embeddings are already configured" do
2628
fab!(:embedding_definition)

spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
RSpec.describe CleanUnusedEmbeddingSearchIndexes do
99
let(:connection) { ActiveRecord::Base.connection }
1010

11+
before { enable_current_plugin }
12+
1113
describe "#up" do
1214
before do
1315
# Copied from 20241008054440_create_binary_indexes_for_embeddings

spec/jobs/regular/detect_translate_post_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
let(:locales) { %w[en ja] }
88

99
before do
10-
SiteSetting.discourse_ai_enabled = true
10+
enable_current_plugin
1111
Fabricate(:fake_model).tap do |fake_llm|
1212
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
1313
end

0 commit comments

Comments
 (0)