mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 02:43:08 -05:00
DEV: Normalize route and namespace setup in plugins (#34962)
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
module ::AdPlugin
|
||||
class HouseAdSettingsController < ::ApplicationController
|
||||
requires_plugin AdPlugin.plugin_name
|
||||
requires_plugin AdPlugin::PLUGIN_NAME
|
||||
|
||||
def update
|
||||
HouseAdSetting.update(params[:id], params[:value])
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
module ::AdPlugin
|
||||
class HouseAdsController < ::ApplicationController
|
||||
requires_plugin AdPlugin.plugin_name
|
||||
requires_plugin AdPlugin::PLUGIN_NAME
|
||||
|
||||
def index
|
||||
render_json_dump(
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
|
||||
class AdstxtController < ::ApplicationController
|
||||
requires_plugin AdPlugin.plugin_name
|
||||
requires_plugin AdPlugin::PLUGIN_NAME
|
||||
|
||||
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
||||
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ module ::AdPlugin
|
||||
|
||||
def self.all
|
||||
PluginStoreRow
|
||||
.where(plugin_name: AdPlugin.plugin_name)
|
||||
.where(plugin_name: AdPlugin::PLUGIN_NAME)
|
||||
.where("key LIKE 'ad:%'")
|
||||
.where("key != 'ad:_id'")
|
||||
.map { |psr| from_hash(PluginStore.cast_value(psr.type_name, psr.value)) }
|
||||
+1
-1
@@ -14,7 +14,7 @@ module ::AdPlugin
|
||||
settings = DEFAULTS.dup
|
||||
|
||||
PluginStoreRow
|
||||
.where(plugin_name: AdPlugin.plugin_name)
|
||||
.where(plugin_name: AdPlugin::PLUGIN_NAME)
|
||||
.where("key LIKE 'ad-setting:%'")
|
||||
.each { |psr| settings[psr.key[11..-1].to_sym] = psr.value }
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
AdPlugin::Engine.routes.draw do
|
||||
root to: "house_ads#index"
|
||||
resources :house_creatives, except: %i[new edit], controller: "house_ads"
|
||||
resources :house_settings, only: [:update], controller: "house_ad_settings"
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ::AdPlugin
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name PLUGIN_NAME
|
||||
isolate_namespace AdPlugin
|
||||
end
|
||||
|
||||
def self.pstore_get(key)
|
||||
PluginStore.get(PLUGIN_NAME, key)
|
||||
end
|
||||
|
||||
def self.pstore_set(key, value)
|
||||
PluginStore.set(PLUGIN_NAME, key, value)
|
||||
end
|
||||
|
||||
def self.pstore_delete(key)
|
||||
PluginStore.remove(PLUGIN_NAME, key)
|
||||
end
|
||||
end
|
||||
@@ -14,33 +14,26 @@ add_admin_route "admin.adplugin.house_ads.title", "houseAds"
|
||||
enabled_site_setting :discourse_adplugin_enabled
|
||||
|
||||
module ::AdPlugin
|
||||
def self.plugin_name
|
||||
"discourse-adplugin".freeze
|
||||
end
|
||||
|
||||
def self.pstore_get(key)
|
||||
PluginStore.get(AdPlugin.plugin_name, key)
|
||||
end
|
||||
|
||||
def self.pstore_set(key, value)
|
||||
PluginStore.set(AdPlugin.plugin_name, key, value)
|
||||
end
|
||||
|
||||
def self.pstore_delete(key)
|
||||
PluginStore.remove(AdPlugin.plugin_name, key)
|
||||
end
|
||||
PLUGIN_NAME = "discourse-adplugin"
|
||||
end
|
||||
|
||||
require_relative "lib/adplugin/engine"
|
||||
|
||||
after_initialize do
|
||||
require_relative "app/models/house_ad"
|
||||
require_relative "app/models/house_ad_setting"
|
||||
require_relative "app/controllers/house_ads_controller"
|
||||
require_relative "app/controllers/house_ad_settings_controller"
|
||||
require_relative "app/controllers/ad_plugin/house_ad_settings_controller"
|
||||
require_relative "app/controllers/ad_plugin/house_ads_controller"
|
||||
require_relative "app/controllers/adstxt_controller"
|
||||
require_relative "app/models/ad_plugin/house_ad_setting"
|
||||
require_relative "app/models/ad_plugin/house_ad"
|
||||
require_relative "lib/adplugin/guardian_extensions"
|
||||
|
||||
reloadable_patch { Guardian.prepend ::AdPlugin::GuardianExtensions }
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
get "/ads.txt" => "adstxt#index"
|
||||
mount ::AdPlugin::Engine, at: "/admin/plugins/pluginad", constraints: AdminConstraint.new
|
||||
end
|
||||
|
||||
add_to_serializer :site, :house_creatives do
|
||||
AdPlugin::HouseAdSetting.settings_and_ads(for_anons: scope.anonymous?, scope: scope)
|
||||
end
|
||||
@@ -74,20 +67,4 @@ after_initialize do
|
||||
add_to_serializer :current_user, :show_to_groups do
|
||||
scope.show_to_groups?
|
||||
end
|
||||
|
||||
class AdPlugin::Engine < ::Rails::Engine
|
||||
engine_name "adplugin"
|
||||
isolate_namespace AdPlugin
|
||||
end
|
||||
|
||||
AdPlugin::Engine.routes.draw do
|
||||
root to: "house_ads#index"
|
||||
resources :house_creatives, only: %i[index show create update destroy], controller: "house_ads"
|
||||
resources :house_settings, only: [:update], controller: "house_ad_settings"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
get "/ads.txt" => "adstxt#index"
|
||||
mount ::AdPlugin::Engine, at: "/admin/plugins/pluginad", constraints: AdminConstraint.new
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user