Class: GroupDescendantsFinder
- Inherits:
-
Object
- Object
- GroupDescendantsFinder
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/finders/group_descendants_finder.rb
Overview
GroupDescendantsFinder
Used to find and filter all subgroups and projects of a passed parent group visible to a specified user.
Arguments:
current_user: The user for which the children should be visible
parent_group: The group to find children of
params:
Supports all params that the `ProjectsFinder` and `GroupProjectsFinder`
support.
active: boolean - filters for active descendants. When `false`, the search is performed over
all nested levels of the `parent group` and all inactive ancestors are loaded.
filter: string - aliased to `search` for consistency with the frontend. When a filter is
passed, the search is performed over all nested levels of the `parent_group`.
All ancestors for a search result are loaded
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#parent_group ⇒ Object
readonly
Returns the value of attribute parent_group.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(parent_group:, current_user: nil, params: {}) ⇒ GroupDescendantsFinder
constructor
A new instance of GroupDescendantsFinder.
Constructor Details
#initialize(parent_group:, current_user: nil, params: {}) ⇒ GroupDescendantsFinder
Returns a new instance of GroupDescendantsFinder.
25 26 27 28 29 |
# File 'app/finders/group_descendants_finder.rb', line 25 def initialize(parent_group:, current_user: nil, params: {}) @current_user = current_user @parent_group = parent_group @params = params end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
23 24 25 |
# File 'app/finders/group_descendants_finder.rb', line 23 def current_user @current_user end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
23 24 25 |
# File 'app/finders/group_descendants_finder.rb', line 23 def params @params end |
#parent_group ⇒ Object (readonly)
Returns the value of attribute parent_group.
23 24 25 |
# File 'app/finders/group_descendants_finder.rb', line 23 def parent_group @parent_group end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/finders/group_descendants_finder.rb', line 31 def execute # First paginate and then include the ancestors of the filtered children to: # - Avoid truncating children or preloaded ancestors due to per_page limit # - Ensure correct pagination headers are returned all_required_elements = Kaminari.paginate_array(children, total_count: paginator.total_count) .page(page) preloaded_ancestors = [] if search_descendants? preloaded_ancestors |= ancestors_of_filtered_subgroups preloaded_ancestors |= ancestors_of_filtered_projects end all_required_elements.concat(preloaded_ancestors - children) end |