Commit 2c626c06 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '339227-fj-use-members-finder-ancestors-linear-scopes' into 'master'

Use MembersFinder ancestors linear scopes

See merge request gitlab-org/gitlab!70583
parents dfb0f7e6 ea414318
...@@ -70,11 +70,16 @@ class MembersFinder ...@@ -70,11 +70,16 @@ class MembersFinder
end end
def project_invited_groups def project_invited_groups
invited_groups_ids_including_ancestors = Gitlab::ObjectHierarchy invited_groups_and_ancestors = if ::Feature.enabled?(:linear_members_finder_ancestor_scopes, current_user, default_enabled: :yaml)
.new(project.invited_groups) project.invited_groups
.base_and_ancestors .self_and_ancestors
.public_or_visible_to_user(current_user) else
.select(:id) Gitlab::ObjectHierarchy
.new(project.invited_groups)
.base_and_ancestors
end
invited_groups_ids_including_ancestors = invited_groups_and_ancestors.public_or_visible_to_user(current_user).select(:id)
GroupMember.with_source_id(invited_groups_ids_including_ancestors).non_minimal_access GroupMember.with_source_id(invited_groups_ids_including_ancestors).non_minimal_access
end end
......
---
name: linear_members_finder_ancestor_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70583
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341347
milestone: '14.4'
type: development
group: group::access
default_enabled: false
...@@ -161,42 +161,54 @@ RSpec.describe MembersFinder, '#execute' do ...@@ -161,42 +161,54 @@ RSpec.describe MembersFinder, '#execute' do
end end
context 'when :invited_groups is passed' do context 'when :invited_groups is passed' do
subject { described_class.new(project, user2).execute(include_relations: [:inherited, :direct, :invited_groups]) } shared_examples 'with invited_groups param' do
subject { described_class.new(project, user2).execute(include_relations: [:inherited, :direct, :invited_groups]) }
let_it_be(:linked_group) { create(:group, :public) } let_it_be(:linked_group) { create(:group, :public) }
let_it_be(:nested_linked_group) { create(:group, parent: linked_group) } let_it_be(:nested_linked_group) { create(:group, parent: linked_group) }
let_it_be(:linked_group_member) { linked_group.add_guest(user1) } let_it_be(:linked_group_member) { linked_group.add_guest(user1) }
let_it_be(:nested_linked_group_member) { nested_linked_group.add_guest(user2) } let_it_be(:nested_linked_group_member) { nested_linked_group.add_guest(user2) }
it 'includes all the invited_groups members including members inherited from ancestor groups' do it 'includes all the invited_groups members including members inherited from ancestor groups' do
create(:project_group_link, project: project, group: nested_linked_group) create(:project_group_link, project: project, group: nested_linked_group)
expect(subject).to contain_exactly(linked_group_member, nested_linked_group_member) expect(subject).to contain_exactly(linked_group_member, nested_linked_group_member)
end end
it 'includes all the invited_groups members' do it 'includes all the invited_groups members' do
create(:project_group_link, project: project, group: linked_group) create(:project_group_link, project: project, group: linked_group)
expect(subject).to contain_exactly(linked_group_member) expect(subject).to contain_exactly(linked_group_member)
end end
it 'excludes group_members not visible to the user' do it 'excludes group_members not visible to the user' do
create(:project_group_link, project: project, group: linked_group) create(:project_group_link, project: project, group: linked_group)
private_linked_group = create(:group, :private) private_linked_group = create(:group, :private)
private_linked_group.add_developer(user3) private_linked_group.add_developer(user3)
create(:project_group_link, project: project, group: private_linked_group) create(:project_group_link, project: project, group: private_linked_group)
expect(subject).to contain_exactly(linked_group_member) expect(subject).to contain_exactly(linked_group_member)
end
context 'when the user is a member of invited group and ancestor groups' do
it 'returns the highest access_level for the user limited by project_group_link.group_access', :nested_groups do
create(:project_group_link, project: project, group: nested_linked_group, group_access: Gitlab::Access::REPORTER)
nested_linked_group.add_developer(user1)
expect(subject.map(&:user)).to contain_exactly(user1, user2)
expect(subject.max_by(&:access_level).access_level).to eq(Gitlab::Access::REPORTER)
end
end
end end
context 'when the user is a member of invited group and ancestor groups' do it_behaves_like 'with invited_groups param'
it 'returns the highest access_level for the user limited by project_group_link.group_access', :nested_groups do
create(:project_group_link, project: project, group: nested_linked_group, group_access: Gitlab::Access::REPORTER)
nested_linked_group.add_developer(user1)
expect(subject.map(&:user)).to contain_exactly(user1, user2) context 'when feature flag :linear_members_finder_ancestor_scopes is disabled' do
expect(subject.max_by(&:access_level).access_level).to eq(Gitlab::Access::REPORTER) before do
stub_feature_flags(linear_members_finder_ancestor_scopes: false)
end end
it_behaves_like 'with invited_groups param'
end end
end end
end end
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