Commit 138725b9 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'vij-externally-shared-projects' into 'master'

Update group#shared_externally to include projects

See merge request gitlab-org/gitlab!78270
parents d28b278e 14197fbf
...@@ -525,9 +525,17 @@ module EE ...@@ -525,9 +525,17 @@ module EE
def shared_externally? def shared_externally?
strong_memoize(:shared_externally) do strong_memoize(:shared_externally) do
invited_group_in_groups internal_groups = ::Group.groups_including_descendants_by([self])
.where.not(group_group_links: { shared_with_group_id: ::Group.groups_including_descendants_by([self]) })
.limit(1).any? 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
end end
......
...@@ -1577,6 +1577,7 @@ RSpec.describe Group do ...@@ -1577,6 +1577,7 @@ RSpec.describe Group do
let_it_be(:subgroup_1) { create(:group, parent: group) } let_it_be(:subgroup_1) { create(:group, parent: group) }
let_it_be(:subgroup_2) { create(:group, parent: group) } let_it_be(:subgroup_2) { create(:group, parent: group) }
let_it_be(:external_group) { create(:group) } let_it_be(:external_group) { create(:group) }
let_it_be(:project) { create(:project, group: subgroup_1) }
subject(:shared_externally?) { group.shared_externally? } subject(:shared_externally?) { group.shared_externally? }
...@@ -1607,6 +1608,18 @@ RSpec.describe Group do ...@@ -1607,6 +1608,18 @@ RSpec.describe Group do
expect(shared_externally?).to be false expect(shared_externally?).to be false
end 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 end
it_behaves_like 'can move repository storage' do 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