Class: GroupMembersFinder

Inherits:
UnionFinder show all
Includes:
CreatedAtFilter
Defined in:
app/finders/group_members_finder.rb

Constant Summary collapse

RELATIONS =
%i(direct inherited descendants shared_from_groups).freeze
DEFAULT_RELATIONS =
%i(direct inherited).freeze
INVALID_RELATION_TYPE_ERROR_MSG =
"is not a valid relation type. Valid relation types are #{RELATIONS.join(', ')}."
RELATIONS_DESCRIPTIONS =
{
  direct: 'Members in the group itself',
  inherited: "Members in the group's ancestor groups",
  descendants: "Members in the group's subgroups",
  shared_from_groups: "Invited group's members"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CreatedAtFilter

#by_created_at

Methods inherited from UnionFinder

#find_union

Constructor Details

#initialize(group, user = nil, params: {}) ⇒ GroupMembersFinder

Returns a new instance of GroupMembersFinder.


25
26
27
28
29
# File 'app/finders/group_members_finder.rb', line 25

def initialize(group, user = nil, params: {})
  @group = group
  @user = user
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Params can be any of the following:

two_factor: string. 'enabled' or 'disabled' are returning different set of data, other values are not effective.
sort:       string
search:     string
created_after: datetime
created_before: datetime

23
24
25
# File 'app/finders/group_members_finder.rb', line 23

def params
  @params
end

Instance Method Details

#execute(include_relations: DEFAULT_RELATIONS) ⇒ Object


31
32
33
34
35
36
# File 'app/finders/group_members_finder.rb', line 31

def execute(include_relations: DEFAULT_RELATIONS)
  groups = groups_by_relations(include_relations)
  members = all_group_members(groups).distinct_on_user_with_max_access_level

  filter_members(members)
end