mirror of
https://github.com/discourse/discourse.git
synced 2026-08-12 05:55:39 -05:00
FIX: Add a page limit to directory_items endpoint (#37496)
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
class DirectoryItemsController < ApplicationController
|
class DirectoryItemsController < ApplicationController
|
||||||
PAGE_SIZE = 50
|
PAGE_SIZE = 50
|
||||||
|
PAGE_LIMIT = 10
|
||||||
|
|
||||||
before_action :set_groups_exclusion, if: -> { params[:exclude_groups].present? }
|
before_action :set_groups_exclusion, if: -> { params[:exclude_groups].present? }
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@@ -58,7 +60,7 @@ class DirectoryItemsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
result = result.includes(:user_stat) if period_type == DirectoryItem.period_types[:all]
|
result = result.includes(:user_stat) if period_type == DirectoryItem.period_types[:all]
|
||||||
page = fetch_int_from_params(:page, default: 0)
|
page = fetch_int_from_params(:page, default: 0, max: PAGE_LIMIT)
|
||||||
|
|
||||||
user_ids = nil
|
user_ids = nil
|
||||||
if params[:name].present?
|
if params[:name].present?
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ RSpec.describe DirectoryItemsController do
|
|||||||
get "/directory_items.json", params: { period: "all", page: 0 }
|
get "/directory_items.json", params: { period: "all", page: 0 }
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "has a page number limit" do
|
||||||
|
get "/directory_items.json", params: { period: "all", page: described_class::PAGE_LIMIT + 1 }
|
||||||
|
expect(response.status).to eq(400)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with exclude_groups parameter" do
|
context "with exclude_groups parameter" do
|
||||||
|
|||||||
Reference in New Issue
Block a user