FIX: Filter out secured categories first (#29916)

The hierarchical search for categories is composed of several complex
nested queries. This change ensures that the secured categories are
filtered out as soon as possible to ensure that the default limit of 5
categories is reached.

Without this fix, the search can return less than 5 categories if any
of the first 5 categories cannot be displayed due to permissions.
This commit is contained in:
Bianca Nenciu
2024-11-28 17:09:16 +02:00
committed by GitHub
parent 3c884e693c
commit 5b19e2ca0f
2 changed files with 25 additions and 1 deletions

View File

@ -316,7 +316,12 @@ class CategoriesController < ApplicationController
page = [1, params[:page].to_i].max
offset = params[:offset].to_i
parent_category_id = params[:parent_category_id].to_i if params[:parent_category_id].present?
only = Category.where(id: params[:only].to_a.map(&:to_i)) if params[:only].present?
only =
if params[:only].present?
Category.secured(guardian).where(id: params[:only].to_a.map(&:to_i))
else
Category.secured(guardian)
end
except_ids = params[:except].to_a.map(&:to_i)
include_uncategorized =
(