Class: GroupMembersFinder

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

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.


14
15
16
17
18
# File 'app/finders/group_members_finder.rb', line 14

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

12
13
14
# File 'app/finders/group_members_finder.rb', line 12

def params
  @params
end

Instance Method Details

#execute(include_relations: [:inherited, :direct]) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/finders/group_members_finder.rb', line 21

def execute(include_relations: [:inherited, :direct])
  group_members = group.members
  relations = []

  return group_members if include_relations == [:direct]

  relations << group_members if include_relations.include?(:direct)

  if include_relations.include?(:inherited) && group.parent
    parents_members = GroupMember.non_request.non_minimal_access
      .where(source_id: group.ancestors.select(:id))
      .where.not(user_id: group.users.select(:id))

    relations << parents_members
  end

  if include_relations.include?(:descendants)
    descendant_members = GroupMember.non_request.non_minimal_access
      .where(source_id: group.descendants.select(:id))
      .where.not(user_id: group.users.select(:id))

    relations << descendant_members
  end

  return GroupMember.none if relations.empty?

  members = find_union(relations, GroupMember)
  filter_members(members)
end