DEV: Add `search_log` modifier to prevent search log logging (#28279)
This commit is contained in:
parent
93a10b3b2e
commit
2527f4599d
|
@ -38,6 +38,10 @@ class SearchLog < ActiveRecord::Base
|
||||||
def self.log(term:, search_type:, ip_address:, user_agent: nil, user_id: nil)
|
def self.log(term:, search_type:, ip_address:, user_agent: nil, user_id: nil)
|
||||||
return [:error] if term.blank?
|
return [:error] if term.blank?
|
||||||
|
|
||||||
|
can_log_search =
|
||||||
|
DiscoursePluginRegistry.apply_modifier(:search_log_can_log, term: term, user_id: user_id)
|
||||||
|
return if !can_log_search
|
||||||
|
|
||||||
search_type = search_types[search_type]
|
search_type = search_types[search_type]
|
||||||
return [:error] if search_type.blank? || ip_address.blank?
|
return [:error] if search_type.blank? || ip_address.blank?
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,10 @@ RSpec.describe SearchLog, type: :model do
|
||||||
|
|
||||||
context "when logged in" do
|
context "when logged in" do
|
||||||
fab!(:user)
|
fab!(:user)
|
||||||
|
let!(:plugin) { Plugin::Instance.new }
|
||||||
|
let!(:modifier) { :search_log_can_log }
|
||||||
|
let!(:deny_block) { Proc.new { false } }
|
||||||
|
let!(:allow_block) { Proc.new { true } }
|
||||||
|
|
||||||
it "logs and updates the search" do
|
it "logs and updates the search" do
|
||||||
freeze_time
|
freeze_time
|
||||||
|
@ -155,6 +159,31 @@ RSpec.describe SearchLog, type: :model do
|
||||||
)
|
)
|
||||||
expect(action).to eq(:created)
|
expect(action).to eq(:created)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows plugins to control logging" do
|
||||||
|
DiscoursePluginRegistry.register_modifier(plugin, modifier, &deny_block)
|
||||||
|
action, _ =
|
||||||
|
SearchLog.log(
|
||||||
|
term: "hello dolly",
|
||||||
|
search_type: :full_page,
|
||||||
|
ip_address: "192.168.0.1",
|
||||||
|
user_id: Fabricate(:user).id,
|
||||||
|
)
|
||||||
|
expect(action).to_not eq(:created)
|
||||||
|
|
||||||
|
DiscoursePluginRegistry.register_modifier(plugin, modifier, &allow_block)
|
||||||
|
action, _ =
|
||||||
|
SearchLog.log(
|
||||||
|
term: "hello dolly",
|
||||||
|
search_type: :full_page,
|
||||||
|
ip_address: "192.168.0.1",
|
||||||
|
user_id: Fabricate(:user).id,
|
||||||
|
)
|
||||||
|
expect(action).to eq(:created)
|
||||||
|
ensure
|
||||||
|
DiscoursePluginRegistry.unregister_modifier(plugin, modifier, &deny_block)
|
||||||
|
DiscoursePluginRegistry.unregister_modifier(plugin, modifier, &allow_block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue