diff --git a/config/settings.yml b/config/settings.yml index 6077dcd3..751ec55f 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,7 +1,7 @@ ad_plugin: discourse_adplugin_enabled: client: true - default: true + default: false no_ads_for_personal_messages: client: true default: true diff --git a/db/migrate/20250721192553_enable_adplugin_if_already_installed.rb b/db/migrate/20250721192553_enable_adplugin_if_already_installed.rb new file mode 100644 index 00000000..69179b67 --- /dev/null +++ b/db/migrate/20250721192553_enable_adplugin_if_already_installed.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class EnableAdpluginIfAlreadyInstalled < ActiveRecord::Migration[7.2] + def up + installed_at = DB.query_single(<<~SQL)&.first + SELECT created_at FROM schema_migration_details WHERE version='20190603112536' + 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('discourse_adplugin_enabled', 5, 't', NOW(), NOW()) + ON CONFLICT (name) DO NOTHING + SQL + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/models/house_ad_setting_spec.rb b/spec/models/house_ad_setting_spec.rb index 9043aaae..1432e2fb 100644 --- a/spec/models/house_ad_setting_spec.rb +++ b/spec/models/house_ad_setting_spec.rb @@ -3,6 +3,8 @@ describe AdPlugin::HouseAdSetting do let(:defaults) { AdPlugin::HouseAdSetting::DEFAULTS } + before { enable_current_plugin } + describe ".all" do subject { AdPlugin::HouseAdSetting.all } diff --git a/spec/models/house_ad_spec.rb b/spec/models/house_ad_spec.rb index f3492aa2..d2977412 100644 --- a/spec/models/house_ad_spec.rb +++ b/spec/models/house_ad_spec.rb @@ -9,6 +9,8 @@ } end + before { enable_current_plugin } + def create_anon_ad AdPlugin::HouseAd.create( name: "anon-ad", diff --git a/spec/requests/house_ad_controller_spec.rb b/spec/requests/house_ad_controller_spec.rb index 3069fe4e..9f2b16c4 100644 --- a/spec/requests/house_ad_controller_spec.rb +++ b/spec/requests/house_ad_controller_spec.rb @@ -16,6 +16,8 @@ ) end + before { enable_current_plugin } + describe "#update" do context "when used by admins" do before { sign_in(admin) } diff --git a/spec/requests/house_ad_settings_controller_spec.rb b/spec/requests/house_ad_settings_controller_spec.rb index bfc7605b..26f130a3 100644 --- a/spec/requests/house_ad_settings_controller_spec.rb +++ b/spec/requests/house_ad_settings_controller_spec.rb @@ -3,7 +3,10 @@ describe AdPlugin::HouseAdSettingsController do let(:admin) { Fabricate(:admin) } - before { AdPlugin::HouseAd.create(name: "Banner", html: "
Banner
") } + before do + enable_current_plugin + AdPlugin::HouseAd.create(name: "Banner", html: "Banner
") + end describe "update" do let(:valid_params) { { value: "Banner" } } diff --git a/spec/requests/site_controller_spec.rb b/spec/requests/site_controller_spec.rb index fced5d43..fb5b36a3 100644 --- a/spec/requests/site_controller_spec.rb +++ b/spec/requests/site_controller_spec.rb @@ -3,7 +3,6 @@ RSpec.describe SiteController do fab!(:group) fab!(:private_category) { Fabricate(:private_category, group: group) } - fab!(:user) fab!(:group_2) { Fabricate(:group) } fab!(:user_with_group) { Fabricate(:user, group_ids: [group.id]) } @@ -75,6 +74,7 @@ end before do + enable_current_plugin AdPlugin::HouseAdSetting.update( "topic_list_top", "logged-in-ad|anon-ad|everyone-ad|logged-in-ad-with-category|logged-in-ad-with-group|everyone-group-ad", diff --git a/spec/serializer/current_user_serializer_spec.rb b/spec/serializer/current_user_serializer_spec.rb index 53ac5b55..f5da55ef 100644 --- a/spec/serializer/current_user_serializer_spec.rb +++ b/spec/serializer/current_user_serializer_spec.rb @@ -14,7 +14,7 @@ let(:admin_serializer) { described_class.new(admin, scope: Guardian.new(admin), root: false) } - before { SiteSetting.discourse_adplugin_enabled = true } + before { enable_current_plugin } describe "#adsense" do it "is displayed for TL0 by default" do diff --git a/spec/system/admin_house_ad_spec.rb b/spec/system/admin_house_ad_spec.rb index 4e046983..e3f9b422 100644 --- a/spec/system/admin_house_ad_spec.rb +++ b/spec/system/admin_house_ad_spec.rb @@ -11,7 +11,10 @@ ) end - before { sign_in(admin) } + before do + enable_current_plugin + sign_in(admin) + end describe "when visiting the page for creating new ads" do it "has the visibility checkboxes on by default" do