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.



27
28
29
30
31
# File 'app/finders/group_members_finder.rb', line 27

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
non_invite:      boolean
with_custom_role: boolean


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

def params
  @params
end

Instance Method Details

#execute(include_relations: DEFAULT_RELATIONS) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/finders/group_members_finder.rb', line 33

def execute(include_relations: DEFAULT_RELATIONS)
  groups = groups_by_relations(include_relations)
  shared_from_groups = if include_relations&.include?(:shared_from_groups)
                         Group.shared_into_ancestors(group).public_or_visible_to_user(user)
                       end

  members = all_group_members(groups, shared_from_groups)
  if static_roles_only?
    members = members.distinct_on_user_with_max_access_level
  end

  filter_members(members)
end