Class: GroupsFinder

Inherits:
UnionFinder show all
Includes:
CustomAttributesFilter, Namespaces::GroupsFilter
Defined in:
app/finders/groups_finder.rb

Overview

GroupsFinder

Used to filter Groups by a set of params

Arguments:

current_user - which user is requesting groups
params:
  owned: boolean
  parent: Group
  all_available: boolean (defaults to true)
  min_access_level: integer
  search: string
  exclude_group_ids: array of integers
  filter_group_ids: array of integers - only include groups from the specified list of ids
  include_parent_descendants: boolean (defaults to false) - includes descendant groups when
                              filtering by parent. The parent param must be present.
  include_parent_shared_groups: boolean (defaults to false) - includes shared groups of a parent group
                              when filtering by parent.
                              Both parent and include_parent_descendants params must be present.
  include_ancestors: boolean (defaults to true)
  organization: Scope the groups to the Organizations::Organization
  active: boolean - filters for active groups.
  archived: boolean - default is nil which returns all groups, true returns only archived groups, and false returns
                      non archived groups
  with_statistics - load project statistics.

Users with full private access can see all groups. The owned and parent params can be used to restrict the groups that are returned.

Anonymous users will never return any owned groups. They will return all public groups instead, even if all_available is set to false.

Direct Known Subclasses

Organizations::GroupsFinder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CustomAttributesFilter

#by_custom_attributes

Methods inherited from UnionFinder

#find_union

Constructor Details

#initialize(current_user = nil, params = {}) ⇒ GroupsFinder

Returns a new instance of GroupsFinder.



40
41
42
43
# File 'app/finders/groups_finder.rb', line 40

def initialize(current_user = nil, params = {})
  @current_user = current_user
  @params = params
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



38
39
40
# File 'app/finders/groups_finder.rb', line 38

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



38
39
40
# File 'app/finders/groups_finder.rb', line 38

def params
  @params
end

Instance Method Details

#executeObject



45
46
47
48
49
50
51
# File 'app/finders/groups_finder.rb', line 45

def execute
  # filtered_groups can contain an array of scopes, so these
  # are combined into a single query using UNION.
  groups = find_union(filtered_groups, Group)
  groups = groups.with_statistics if params[:with_statistics] == true
  sort(groups).with_route
end