mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-23 16:44:04 -05:00
Add relevant_params
to ReportFilter (matches account filter) (#32136)
This commit is contained in:
parent
cf859d151b
commit
2151dfb8d6
@ -18,13 +18,25 @@ class ReportFilter
|
|||||||
def results
|
def results
|
||||||
scope = Report.unresolved
|
scope = Report.unresolved
|
||||||
|
|
||||||
params.each do |key, value|
|
relevant_params.each do |key, value|
|
||||||
scope = scope.merge scope_for(key, value)
|
scope = scope.merge scope_for(key, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def relevant_params
|
||||||
|
params.tap do |args|
|
||||||
|
args.delete(:target_origin) if origin_is_remote_and_domain_present?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def origin_is_remote_and_domain_present?
|
||||||
|
params[:target_origin] == 'remote' && params[:by_target_domain].present?
|
||||||
|
end
|
||||||
|
|
||||||
def scope_for(key, value)
|
def scope_for(key, value)
|
||||||
case key.to_sym
|
case key.to_sym
|
||||||
when :by_target_domain
|
when :by_target_domain
|
||||||
|
@ -30,4 +30,17 @@ RSpec.describe ReportFilter do
|
|||||||
expect(Report).to have_received(:resolved)
|
expect(Report).to have_received(:resolved)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when given remote target_origin and also by_target_domain' do
|
||||||
|
let!(:matching_report) { Fabricate :report, target_account: Fabricate(:account, domain: 'match.example') }
|
||||||
|
let!(:non_matching_report) { Fabricate :report, target_account: Fabricate(:account, domain: 'other.example') }
|
||||||
|
|
||||||
|
it 'preserves the domain value' do
|
||||||
|
filter = described_class.new(by_target_domain: 'match.example', target_origin: 'remote')
|
||||||
|
|
||||||
|
expect(filter.results)
|
||||||
|
.to include(matching_report)
|
||||||
|
.and not_include(non_matching_report)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user