Commit 14197fbf authored by Vijay Hawoldar's avatar Vijay Hawoldar

Update group#shared_externally to include projects

Correctly determine if a group or it's subgroups or projects have
been shared externally

Changelog: changed
EE: true
parent dbf2aac0
......@@ -525,9 +525,17 @@ module EE
def shared_externally?
strong_memoize(:shared_externally) do
invited_group_in_groups
.where.not(group_group_links: { shared_with_group_id: ::Group.groups_including_descendants_by([self]) })
.limit(1).any?
internal_groups = ::Group.groups_including_descendants_by([self])
group_links = invited_group_in_groups
.where.not(group_group_links: { shared_with_group_id: internal_groups })
.limit(1)
project_links = invited_groups_in_projects
.where.not(project_group_links: { group_id: internal_groups })
.limit(1)
group_links.any? || project_links.any?
end
end
......
......@@ -1577,6 +1577,7 @@ RSpec.describe Group do
let_it_be(:subgroup_1) { create(:group, parent: group) }
let_it_be(:subgroup_2) { create(:group, parent: group) }
let_it_be(:external_group) { create(:group) }
let_it_be(:project) { create(:project, group: subgroup_1) }
subject(:shared_externally?) { group.shared_externally? }
......@@ -1607,6 +1608,18 @@ RSpec.describe Group do
expect(shared_externally?).to be false
end
it 'returns true when the group project is shared outside of the namespace hierarchy' do
create(:project_group_link, project: project, group: external_group)
expect(shared_externally?).to be true
end
it 'returns false when the group project is only shared internally within the namespace hierarchy' do
create(:project_group_link, project: project, group: subgroup_2)
expect(shared_externally?).to be false
end
end
it_behaves_like 'can move repository storage' do
......
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