Commit c2ac5bc3 authored by Aakriti Gupta's avatar Aakriti Gupta Committed by Bob Van Landuyt

Use CreatedAtFilter in GroupMemberFinder

parent 760c9334
# frozen_string_literal: true # frozen_string_literal: true
class GroupMembersFinder < UnionFinder class GroupMembersFinder < UnionFinder
include CreatedAtFilter
# Params can be any of the following: # Params can be any of the following:
# two_factor: string. 'enabled' or 'disabled' are returning different set of data, other values are not effective. # two_factor: string. 'enabled' or 'disabled' are returning different set of data, other values are not effective.
# sort: string # sort: string
# search: string # search: string
# created_after: datetime
# created_before: datetime
def initialize(group, user = nil) def initialize(group, user = nil)
@group = group @group = group
...@@ -15,6 +19,7 @@ class GroupMembersFinder < UnionFinder ...@@ -15,6 +19,7 @@ class GroupMembersFinder < UnionFinder
def execute(include_relations: [:inherited, :direct], params: {}) def execute(include_relations: [:inherited, :direct], params: {})
group_members = group.members group_members = group.members
relations = [] relations = []
@params = params
return group_members if include_relations == [:direct] return group_members if include_relations == [:direct]
...@@ -39,15 +44,15 @@ class GroupMembersFinder < UnionFinder ...@@ -39,15 +44,15 @@ class GroupMembersFinder < UnionFinder
return GroupMember.none if relations.empty? return GroupMember.none if relations.empty?
members = find_union(relations, GroupMember) members = find_union(relations, GroupMember)
filter_members(members, params) filter_members(members)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
private private
attr_reader :user, :group attr_reader :user, :group, :params
def filter_members(members, params) def filter_members(members)
members = members.search(params[:search]) if params[:search].present? members = members.search(params[:search]) if params[:search].present?
members = members.sort_by_attribute(params[:sort]) if params[:sort].present? members = members.sort_by_attribute(params[:sort]) if params[:sort].present?
...@@ -55,7 +60,7 @@ class GroupMembersFinder < UnionFinder ...@@ -55,7 +60,7 @@ class GroupMembersFinder < UnionFinder
members = members.filter_by_2fa(params[:two_factor]) members = members.filter_by_2fa(params[:two_factor])
end end
members by_created_at(members)
end end
def can_manage_members def can_manage_members
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class GroupMember < Member class GroupMember < Member
include FromUnion include FromUnion
include CreatedAtFilterable
SOURCE_TYPE = 'Namespace' SOURCE_TYPE = 'Namespace'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment