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

Commit e9c3c33

Browse files
authored
DEV: Disable the plugin by default (#252)
…and preserve the current setting on existing sites
1 parent 0171ad8 commit e9c3c33

9 files changed

+40
-5
lines changed

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ad_plugin:
22
discourse_adplugin_enabled:
33
client: true
4-
default: true
4+
default: false
55
no_ads_for_personal_messages:
66
client: true
77
default: 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 EnableAdpluginIfAlreadyInstalled < 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='20190603112536'
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_adplugin_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/models/house_ad_setting_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
describe AdPlugin::HouseAdSetting do
44
let(:defaults) { AdPlugin::HouseAdSetting::DEFAULTS }
55

6+
before { enable_current_plugin }
7+
68
describe ".all" do
79
subject { AdPlugin::HouseAdSetting.all }
810

spec/models/house_ad_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
}
1010
end
1111

12+
before { enable_current_plugin }
13+
1214
def create_anon_ad
1315
AdPlugin::HouseAd.create(
1416
name: "anon-ad",

spec/requests/house_ad_controller_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
)
1717
end
1818

19+
before { enable_current_plugin }
20+
1921
describe "#update" do
2022
context "when used by admins" do
2123
before { sign_in(admin) }

spec/requests/house_ad_settings_controller_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
describe AdPlugin::HouseAdSettingsController do
44
let(:admin) { Fabricate(:admin) }
55

6-
before { AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>") }
6+
before do
7+
enable_current_plugin
8+
AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>")
9+
end
710

811
describe "update" do
912
let(:valid_params) { { value: "Banner" } }

spec/requests/site_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
RSpec.describe SiteController do
44
fab!(:group)
55
fab!(:private_category) { Fabricate(:private_category, group: group) }
6-
76
fab!(:user)
87
fab!(:group_2) { Fabricate(:group) }
98
fab!(:user_with_group) { Fabricate(:user, group_ids: [group.id]) }
@@ -75,6 +74,7 @@
7574
end
7675

7776
before do
77+
enable_current_plugin
7878
AdPlugin::HouseAdSetting.update(
7979
"topic_list_top",
8080
"logged-in-ad|anon-ad|everyone-ad|logged-in-ad-with-category|logged-in-ad-with-group|everyone-group-ad",

spec/serializer/current_user_serializer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
let(:admin_serializer) { described_class.new(admin, scope: Guardian.new(admin), root: false) }
1616

17-
before { SiteSetting.discourse_adplugin_enabled = true }
17+
before { enable_current_plugin }
1818

1919
describe "#adsense" do
2020
it "is displayed for TL0 by default" do

spec/system/admin_house_ad_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
)
1212
end
1313

14-
before { sign_in(admin) }
14+
before do
15+
enable_current_plugin
16+
sign_in(admin)
17+
end
1518

1619
describe "when visiting the page for creating new ads" do
1720
it "has the visibility checkboxes on by default" do

0 commit comments

Comments
 (0)