Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Filter reviewables by id. (#12213)

Roman Rizzibb3d5e9758c1
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index c83e8800ce8..c2b2d43ed3a 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -24,6 +24,7 @@ class ReviewablesController < ApplicationController
custom_keys = Reviewable.custom_filters.map(&:first)
additional_filters = JSON.parse(params.fetch(:additional_filters, {}), symbolize_names: true).slice(*custom_keys)
filters = {
+ ids: params[:ids],
status: status,
category_id: category_id,
topic_id: topic_id,
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 7f3535816cc..438fb51524b 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -429,6 +429,7 @@ class Reviewable < ActiveRecord::Base
def self.list_for(
user,
+ ids: nil,
status: :pending,
category_id: nil,
topic_id: nil,
@@ -465,6 +466,7 @@ class Reviewable < ActiveRecord::Base
result = viewable_by(user, order: order)
result = by_status(result, status)
+ result = result.where(id: ids) if ids
result = result.where('reviewables.type = ?', type) if type
result = result.where('reviewables.category_id = ?', category_id) if category_id
result = result.where('reviewables.topic_id = ?', topic_id) if topic_id
diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb
index 708add4968d..2504a7c2a54 100644
--- a/spec/requests/reviewables_controller_spec.rb
+++ b/spec/requests/reviewables_controller_spec.rb
@@ -223,6 +223,18 @@ describe ReviewablesController do
expect(json['users'].any? { |u| u['id'] == reviewable.target_created_by_id && u['custom_fields']['private_field'] == 'private' }).to eq(false)
end
end
+
+ it 'supports filtering by id' do
+ reviewable_a = Fabricate(:reviewable)
+ reviewable_b = Fabricate(:reviewable)
+
+ get "/review.json?ids[]=#{reviewable_a.id}"
+
+ expect(response.code).to eq("200")
+ json = response.parsed_body
+ expect(json['reviewables']).to be_present
+ expect(json['reviewables'].size).to eq(1)
+ end
end
context "#show" do