Commit 72cd61d6 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'ag-pass-params-on-init' into 'master'

Pass params on initializing GroupMemberFinder

See merge request gitlab-org/gitlab!28014
parents 9e3e4353 70dac459
......@@ -57,7 +57,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
def find_members
filter_params = params.slice(:two_factor, :search).merge(sort: @sort)
GroupMembersFinder.new(@group, current_user).execute(include_relations: requested_relations, params: filter_params)
GroupMembersFinder.new(@group, current_user, params: filter_params).execute(include_relations: requested_relations)
end
def can_manage_members
......
......@@ -10,13 +10,16 @@ class GroupMembersFinder < UnionFinder
# created_after: datetime
# created_before: datetime
def initialize(group, user = nil)
attr_reader :params
def initialize(group, user = nil, params: {})
@group = group
@user = user
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_relations: [:inherited, :direct], params: {})
def execute(include_relations: [:inherited, :direct])
group_members = group.members
relations = []
@params = params
......@@ -50,7 +53,7 @@ class GroupMembersFinder < UnionFinder
private
attr_reader :user, :group, :params
attr_reader :user, :group
def filter_members(members)
members = members.search(params[:search]) if params[:search].present?
......
......@@ -21,11 +21,11 @@ module Analytics
def new_members_count
@new_members_count ||=
GroupMembersFinder.new(@group, @current_user)
.execute(
include_relations: [:direct, :descendants],
params: { created_after: DURATION.ago }
).count
GroupMembersFinder.new(
@group,
@current_user,
params: { created_after: DURATION.ago }
).execute(include_relations: [:direct, :descendants]).count
end
private
......
......@@ -82,7 +82,7 @@ describe GroupMembersFinder, '#execute' do
group.add_developer(user3)
member = group.add_maintainer(user1)
result = described_class.new(group).execute(params: { search: user1.name })
result = described_class.new(group, params: { search: user1.name }).execute
expect(result.to_a).to match_array([member])
end
......@@ -92,7 +92,7 @@ describe GroupMembersFinder, '#execute' do
group.add_developer(user3)
group.add_maintainer(user1)
result = described_class.new(group).execute(include_relations: [:inherited], params: { search: user1.name })
result = described_class.new(group, params: { search: user1.name }).execute(include_relations: [:inherited])
expect(result.to_a).to match_array([])
end
......@@ -103,7 +103,7 @@ describe GroupMembersFinder, '#execute' do
nested_group.add_maintainer(create(:user, name: user1.name))
member = group.add_maintainer(user1)
result = described_class.new(nested_group).execute(include_relations: [:inherited], params: { search: member.user.name })
result = described_class.new(nested_group, params: { search: member.user.name }).execute(include_relations: [:inherited])
expect(result.to_a).to contain_exactly(member)
end
......@@ -113,7 +113,7 @@ describe GroupMembersFinder, '#execute' do
group.add_maintainer(user1)
member = group.add_maintainer(user5)
result = described_class.new(group, user2).execute(params: { two_factor: 'enabled' })
result = described_class.new(group, user2, params: { two_factor: 'enabled' }).execute
expect(result.to_a).to contain_exactly(member)
end
......@@ -123,7 +123,7 @@ describe GroupMembersFinder, '#execute' do
member2 = group.add_maintainer(user1)
member_with_2fa = group.add_maintainer(user5)
result = described_class.new(group, user2).execute(params: { two_factor: 'disabled' })
result = described_class.new(group, user2, params: { two_factor: 'disabled' }).execute
expect(result.to_a).not_to include(member_with_2fa)
expect(result.to_a).to match_array([member1, member2])
......
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