Make it possible to retrieve both resolved and unresolved reports by api (#38323)
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Check for relevant changes (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / test (3.4) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (3.4) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-05-23 13:07:02 +02:00
committed by GitHub
parent 6a4d14b178
commit 6b2616453f
3 changed files with 25 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ class Api::V1::Admin::ReportsController < Api::BaseController
FILTER_PARAMS = %i(
resolved
unresolved
account_id
target_account_id
).freeze

View File

@@ -3,6 +3,7 @@
class ReportFilter
KEYS = %i(
resolved
unresolved
account_id
target_account_id
by_target_domain
@@ -16,7 +17,7 @@ class ReportFilter
end
def results
scope = Report.unresolved
scope = status_scope
relevant_params.each do |key, value|
scope = scope.merge scope_for(key, value)
@@ -28,7 +29,7 @@ class ReportFilter
private
def relevant_params
params.tap do |args|
params.except(:resolved, :unresolved).tap do |args|
args.delete(:target_origin) if origin_is_remote_and_domain_present?
end
end
@@ -37,12 +38,20 @@ class ReportFilter
params[:target_origin] == 'remote' && params[:by_target_domain].present?
end
def status_scope
resolved = params.key?(:resolved)
unresolved = params.key?(:unresolved)
return Report.all if resolved && unresolved
return Report.resolved if resolved
Report.unresolved
end
def scope_for(key, value)
case key.to_sym
when :by_target_domain
Report.where(target_account: Account.where(domain: value))
when :resolved
Report.resolved
when :account_id
Report.where(account_id: value)
when :target_account_id

View File

@@ -78,6 +78,17 @@ RSpec.describe 'Reports' do
end
end
context 'with both resolved and unresolved params' do
let(:params) { { resolved: true, unresolved: true } }
let(:scope) { Report.all }
it 'returns all reports' do
subject
expect(response.parsed_body).to match_array(expected_response)
end
end
context 'with account_id param' do
let(:params) { { account_id: reporter.id } }
let(:scope) { Report.unresolved.where(account: reporter) }