FIX: Add a page limit to directory_items endpoint (#37496)

This commit is contained in:
Jarek Radosz
2026-02-03 20:02:44 +01:00
committed by GitHub
parent d29d38332f
commit 844bd89719
2 changed files with 8 additions and 1 deletions
@@ -2,6 +2,8 @@
class DirectoryItemsController < ApplicationController
PAGE_SIZE = 50
PAGE_LIMIT = 10
before_action :set_groups_exclusion, if: -> { params[:exclude_groups].present? }
def index
@@ -58,7 +60,7 @@ class DirectoryItemsController < ApplicationController
end
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
if params[:name].present?
@@ -43,6 +43,11 @@ RSpec.describe DirectoryItemsController do
get "/directory_items.json", params: { period: "all", page: 0 }
expect(response.status).to eq(200)
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
context "with exclude_groups parameter" do