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

Pass params on initializing GroupMemberFinder

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