Class: Groups::UserGroupsFinder

Inherits:
Base
  • Object
show all
Defined in:
app/finders/groups/user_groups_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_user, target_user, params = {}) ⇒ UserGroupsFinder

Returns a new instance of UserGroupsFinder.



19
20
21
22
23
# File 'app/finders/groups/user_groups_finder.rb', line 19

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

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/finders/groups/user_groups_finder.rb', line 25

def execute
  return Group.none unless current_user&.can?(:read_user_groups, target_user)
  return Group.none if target_user.blank?

  items = by_permission_scope
  items = by_organization(items)

  # Search will perform an ORDER BY to ensure exact matches are returned first.
  return by_search(items, exact_matches_first: true) if exact_matches_first_enabled?

  items = by_search(items)
  sort(items)
end