1
0
mirror of synced 2026-05-23 14:33:17 +00:00

DEV: Disable the plugin by default (#252)

…and preserve the current setting on existing sites
This commit is contained in:
Jarek Radosz
2025-07-22 11:50:37 +02:00
committed by GitHub
parent 0171ad8d3a
commit e9c3c335f2
9 changed files with 40 additions and 5 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
ad_plugin:
discourse_adplugin_enabled:
client: true
default: true
default: false
no_ads_for_personal_messages:
client: true
default: true
@@ -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
+2
View File
@@ -3,6 +3,8 @@
describe AdPlugin::HouseAdSetting do
let(:defaults) { AdPlugin::HouseAdSetting::DEFAULTS }
before { enable_current_plugin }
describe ".all" do
subject { AdPlugin::HouseAdSetting.all }
+2
View File
@@ -9,6 +9,8 @@ describe AdPlugin::HouseAd do
}
end
before { enable_current_plugin }
def create_anon_ad
AdPlugin::HouseAd.create(
name: "anon-ad",
@@ -16,6 +16,8 @@ describe AdPlugin::HouseAdsController do
)
end
before { enable_current_plugin }
describe "#update" do
context "when used by admins" do
before { sign_in(admin) }
@@ -3,7 +3,10 @@
describe AdPlugin::HouseAdSettingsController do
let(:admin) { Fabricate(:admin) }
before { AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>") }
before do
enable_current_plugin
AdPlugin::HouseAd.create(name: "Banner", html: "<p>Banner</p>")
end
describe "update" do
let(:valid_params) { { value: "Banner" } }
+1 -1
View File
@@ -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 @@ RSpec.describe SiteController do
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",
@@ -14,7 +14,7 @@ RSpec.describe CurrentUserSerializer do
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
+4 -1
View File
@@ -11,7 +11,10 @@ describe "Admin House Ad", type: :system do
)
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