2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe GroupMembersFinder, '#execute' do
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:group) { create(:group) }
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:nested_group) { create(:group, parent: group) }
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:deeper_nested_group) { create(:group, parent: nested_group) }
|
|
|
|
let(:user1) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:user3) { create(:user) }
|
|
|
|
let(:user4) { create(:user) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:user5) { create(:user, :two_factor_via_otp) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it 'returns members for top-level group' do
|
2018-11-18 11:00:15 +05:30
|
|
|
member1 = group.add_maintainer(user1)
|
|
|
|
member2 = group.add_maintainer(user2)
|
|
|
|
member3 = group.add_maintainer(user3)
|
2020-11-24 15:15:51 +05:30
|
|
|
create(:group_member, :minimal_access, user: create(:user), source: group)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
result = described_class.new(group).execute
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(result.to_a).to match_array([member3, member2, member1])
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns members & inherited members for nested group by default' do
|
2019-02-15 15:39:39 +05:30
|
|
|
group.add_developer(user2)
|
2017-08-17 22:00:37 +05:30
|
|
|
nested_group.request_access(user4)
|
2018-11-18 11:00:15 +05:30
|
|
|
member1 = group.add_maintainer(user1)
|
|
|
|
member3 = nested_group.add_maintainer(user2)
|
|
|
|
member4 = nested_group.add_maintainer(user3)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
result = described_class.new(nested_group).execute
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(result.to_a).to match_array([member1, member3, member4])
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'does not return inherited members for nested group if requested' do
|
|
|
|
group.add_maintainer(user1)
|
|
|
|
group.add_developer(user2)
|
|
|
|
member2 = nested_group.add_maintainer(user2)
|
|
|
|
member3 = nested_group.add_maintainer(user3)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group).execute(include_relations: [:direct])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member2, member3])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns only inherited members for nested group if requested' do
|
|
|
|
group.add_developer(user2)
|
|
|
|
nested_group.request_access(user4)
|
|
|
|
member1 = group.add_maintainer(user1)
|
|
|
|
nested_group.add_maintainer(user2)
|
|
|
|
nested_group.add_maintainer(user3)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group).execute(include_relations: [:inherited])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member1])
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'does not return nil if `inherited only` relation is requested on root group' do
|
|
|
|
group.add_developer(user2)
|
|
|
|
|
|
|
|
result = described_class.new(group).execute(include_relations: [:inherited])
|
|
|
|
|
|
|
|
expect(result).not_to be_nil
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns members for descendant groups if requested' do
|
2018-11-18 11:00:15 +05:30
|
|
|
member1 = group.add_maintainer(user2)
|
|
|
|
member2 = group.add_maintainer(user1)
|
|
|
|
nested_group.add_maintainer(user2)
|
|
|
|
member3 = nested_group.add_maintainer(user3)
|
|
|
|
member4 = nested_group.add_maintainer(user4)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
result = described_class.new(group).execute(include_relations: [:direct, :descendants])
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member1, member2, member3, member4])
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'returns searched members if requested' do
|
|
|
|
group.add_maintainer(user2)
|
|
|
|
group.add_developer(user3)
|
|
|
|
member = group.add_maintainer(user1)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result = described_class.new(group, params: { search: user1.name }).execute
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nothing if search only in inherited relation' do
|
|
|
|
group.add_maintainer(user2)
|
|
|
|
group.add_developer(user3)
|
|
|
|
group.add_maintainer(user1)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result = described_class.new(group, params: { search: user1.name }).execute(include_relations: [:inherited])
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(result.to_a).to match_array([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns searched member only from nested_group if search only in inherited relation' do
|
|
|
|
group.add_maintainer(user2)
|
|
|
|
group.add_developer(user3)
|
|
|
|
nested_group.add_maintainer(create(:user, name: user1.name))
|
|
|
|
member = group.add_maintainer(user1)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result = described_class.new(nested_group, params: { search: member.user.name }).execute(include_relations: [:inherited])
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(result.to_a).to contain_exactly(member)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns members with two-factor auth if requested by owner' do
|
|
|
|
group.add_owner(user2)
|
|
|
|
group.add_maintainer(user1)
|
|
|
|
member = group.add_maintainer(user5)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result = described_class.new(group, user2, params: { two_factor: 'enabled' }).execute
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(result.to_a).to contain_exactly(member)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns members without two-factor auth if requested by owner' do
|
|
|
|
member1 = group.add_owner(user2)
|
|
|
|
member2 = group.add_maintainer(user1)
|
|
|
|
member_with_2fa = group.add_maintainer(user5)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
result = described_class.new(group, user2, params: { two_factor: 'disabled' }).execute
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(result.to_a).not_to include(member_with_2fa)
|
|
|
|
expect(result.to_a).to match_array([member1, member2])
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
it 'returns direct members with two-factor auth if requested by owner' do
|
|
|
|
group.add_owner(user1)
|
|
|
|
group.add_maintainer(user2)
|
|
|
|
nested_group.add_maintainer(user3)
|
|
|
|
member_with_2fa = nested_group.add_maintainer(user5)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group, user1, params: { two_factor: 'enabled' }).execute(include_relations: [:direct])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member_with_2fa])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns inherited members with two-factor auth if requested by owner' do
|
|
|
|
group.add_owner(user1)
|
|
|
|
member_with_2fa = group.add_maintainer(user5)
|
|
|
|
nested_group.add_maintainer(user2)
|
|
|
|
nested_group.add_maintainer(user3)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group, user1, params: { two_factor: 'enabled' }).execute(include_relations: [:inherited])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member_with_2fa])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns direct members without two-factor auth if requested by owner' do
|
|
|
|
group.add_owner(user1)
|
|
|
|
group.add_maintainer(user2)
|
|
|
|
member3 = nested_group.add_maintainer(user3)
|
|
|
|
nested_group.add_maintainer(user5)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group, user1, params: { two_factor: 'disabled' }).execute(include_relations: [:direct])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member3])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns inherited members without two-factor auth if requested by owner' do
|
|
|
|
member1 = group.add_owner(user1)
|
|
|
|
group.add_maintainer(user5)
|
|
|
|
nested_group.add_maintainer(user2)
|
|
|
|
nested_group.add_maintainer(user3)
|
|
|
|
|
|
|
|
result = described_class.new(nested_group, user1, params: { two_factor: 'disabled' }).execute(include_relations: [:inherited])
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([member1])
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|