Commit 68f90013 authored by Jarka Košanová's avatar Jarka Košanová

Rename GroupHierarchy into ObjectHierarchy

- we now use the hierarchy class also for epics
- also rename supports_nested_groups? into supports_nested_objects?
  - move it to a concern
- add checks for epics
parent 9b5b41b9
...@@ -4,6 +4,7 @@ class Groups::EpicLinksController < Groups::EpicsController ...@@ -4,6 +4,7 @@ class Groups::EpicLinksController < Groups::EpicsController
include EpicRelations include EpicRelations
before_action :check_feature_flag! before_action :check_feature_flag!
before_action :check_nested_support!
before_action do before_action do
push_frontend_feature_flag(:epic_links) push_frontend_feature_flag(:epic_links)
...@@ -32,4 +33,8 @@ class Groups::EpicLinksController < Groups::EpicsController ...@@ -32,4 +33,8 @@ class Groups::EpicLinksController < Groups::EpicsController
def check_feature_flag! def check_feature_flag!
render_404 unless Feature.enabled?(:epic_links, group) render_404 unless Feature.enabled?(:epic_links, group)
end end
def check_nested_support!
render_404 unless Epic.supports_nested_objects?
end
end end
...@@ -108,10 +108,10 @@ module Geo ...@@ -108,10 +108,10 @@ module Geo
def group_uploads def group_uploads
namespace_ids = namespace_ids =
if current_node.selective_sync_by_namespaces? if current_node.selective_sync_by_namespaces?
Gitlab::GroupHierarchy.new(current_node.namespaces).base_and_descendants.select(:id) Gitlab::ObjectHierarchy.new(current_node.namespaces).base_and_descendants.select(:id)
elsif current_node.selective_sync_by_shards? elsif current_node.selective_sync_by_shards?
leaf_groups = Namespace.where(id: current_node.projects.select(:namespace_id)) leaf_groups = Namespace.where(id: current_node.projects.select(:namespace_id))
Gitlab::GroupHierarchy.new(leaf_groups).base_and_ancestors.select(:id) Gitlab::ObjectHierarchy.new(leaf_groups).base_and_ancestors.select(:id)
else else
Namespace.none Namespace.none
end end
......
...@@ -21,6 +21,7 @@ module EE ...@@ -21,6 +21,7 @@ module EE
if parent.is_a?(Group) if parent.is_a?(Group)
data[:issueLinksEndpoint] = group_epic_issues_path(parent, issuable) data[:issueLinksEndpoint] = group_epic_issues_path(parent, issuable)
data[:epicLinksEndpoint] = group_epic_links_path(parent, issuable) data[:epicLinksEndpoint] = group_epic_links_path(parent, issuable)
data[:subepicsSupported] = ::Epic.supports_nested_objects?
end end
data data
......
...@@ -12,6 +12,7 @@ module EE ...@@ -12,6 +12,7 @@ module EE
include Referable include Referable
include Awardable include Awardable
include LabelEventable include LabelEventable
include Descendant
enum state: { opened: 1, closed: 2 } enum state: { opened: 1, closed: 2 }
...@@ -228,8 +229,7 @@ module EE ...@@ -228,8 +229,7 @@ module EE
end end
def hierarchy def hierarchy
::Gitlab::GroupHierarchy ::Gitlab::ObjectHierarchy.new(self.class.where(id: id))
.new(self.class.where(id: id))
end end
# we don't support project epics for epics yet, planned in the future #4019 # we don't support project epics for epics yet, planned in the future #4019
......
...@@ -186,7 +186,7 @@ module EE ...@@ -186,7 +186,7 @@ module EE
project_creation_levels << nil project_creation_levels << nil
end end
developer_groups_hierarchy = ::Gitlab::GroupHierarchy.new(developer_groups).base_and_descendants developer_groups_hierarchy = ::Gitlab::ObjectHierarchy.new(developer_groups).base_and_descendants
::Group.where(id: developer_groups_hierarchy.select(:id), ::Group.where(id: developer_groups_hierarchy.select(:id),
project_creation_level: project_creation_levels) project_creation_level: project_creation_levels)
end end
......
...@@ -187,7 +187,7 @@ class GeoNode < ActiveRecord::Base ...@@ -187,7 +187,7 @@ class GeoNode < ActiveRecord::Base
return Project.all unless selective_sync? return Project.all unless selective_sync?
if selective_sync_by_namespaces? if selective_sync_by_namespaces?
query = Gitlab::GroupHierarchy.new(namespaces).base_and_descendants query = Gitlab::ObjectHierarchy.new(namespaces).base_and_descendants
Project.where(namespace_id: query.select(:id)) Project.where(namespace_id: query.select(:id))
elsif selective_sync_by_shards? elsif selective_sync_by_shards?
Project.where(repository_storage: selective_sync_shards) Project.where(repository_storage: selective_sync_shards)
......
...@@ -52,7 +52,7 @@ module EE ...@@ -52,7 +52,7 @@ module EE
namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id') namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id')
if ::Feature.enabled?(:shared_runner_minutes_on_root_namespace) if ::Feature.enabled?(:shared_runner_minutes_on_root_namespace)
namespaces = ::Gitlab::GroupHierarchy.new(namespaces).roots namespaces = ::Gitlab::ObjectHierarchy.new(namespaces).roots
end end
namespaces namespaces
......
...@@ -58,7 +58,7 @@ module Gitlab ...@@ -58,7 +58,7 @@ module Gitlab
# Returns an ActiveRecord::Relation that includes the given groups, and all # Returns an ActiveRecord::Relation that includes the given groups, and all
# their (recursive) ancestors. # their (recursive) ancestors.
def groups_and_ancestors_for(groups) def groups_and_ancestors_for(groups)
Gitlab::GroupHierarchy Gitlab::ObjectHierarchy
.new(groups) .new(groups)
.base_and_ancestors .base_and_ancestors
.select(:id, :parent_id, :plan_id) .select(:id, :parent_id, :plan_id)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Groups::EpicLinksController do describe Groups::EpicLinksController, :postgresql do
let(:group) { create(:group, :public) } let(:group) { create(:group, :public) }
let(:parent_epic) { create(:epic, group: group) } let(:parent_epic) { create(:epic, group: group) }
let(:epic1) { create(:epic, group: group) } let(:epic1) { create(:epic, group: group) }
......
...@@ -188,7 +188,7 @@ describe Namespace do ...@@ -188,7 +188,7 @@ describe Namespace do
end end
end end
if Group.supports_nested_groups? if Group.supports_nested_objects?
context 'when license is applied to parent group' do context 'when license is applied to parent group' do
let(:child_group) { create :group, parent: group } let(:child_group) { create :group, parent: group }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe EpicLinks::CreateService, :nested_groups do describe EpicLinks::CreateService, :postgresql do
describe '#execute' do describe '#execute' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe EpicLinks::ListService do describe EpicLinks::ListService, :postgresql do
let(:user) { create :user } let(:user) { create :user }
let(:group) { create(:group, :public) } let(:group) { create(:group, :public) }
let(:parent_epic) { create(:epic, group: group) } let(:parent_epic) { create(:epic, group: group) }
...@@ -51,7 +51,7 @@ describe EpicLinks::ListService do ...@@ -51,7 +51,7 @@ describe EpicLinks::ListService do
end end
end end
context 'with nested groups', :nested_groups do context 'with nested groups' do
let(:subgroup1) { create(:group, :private, parent: group) } let(:subgroup1) { create(:group, :private, parent: group) }
let(:subgroup2) { create(:group, :private, parent: group) } let(:subgroup2) { create(:group, :private, parent: group) }
let!(:epic_subgroup1) { create :epic, group: subgroup1, parent: parent_epic } let!(:epic_subgroup1) { create :epic, group: subgroup1, parent: parent_epic }
......
...@@ -45,7 +45,7 @@ module Gitlab ...@@ -45,7 +45,7 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of groups # Returns a relation that includes the ancestors_base set of objects
# and all their ancestors (recursively). # and all their ancestors (recursively).
# #
# Passing an `upto` will stop the recursion once the specified parent_id is # Passing an `upto` will stop the recursion once the specified parent_id is
......
...@@ -220,7 +220,8 @@ describe IssuablesHelper do ...@@ -220,7 +220,8 @@ describe IssuablesHelper do
initialTitleText: epic.title, initialTitleText: epic.title,
initialDescriptionHtml: '<p dir="auto">epic text</p>', initialDescriptionHtml: '<p dir="auto">epic text</p>',
initialDescriptionText: 'epic text', initialDescriptionText: 'epic text',
initialTaskStatus: '0 of 0 tasks completed' initialTaskStatus: '0 of 0 tasks completed',
subepicsSupported: Gitlab::Database.postgresql? ? true : false
} }
expect(helper.issuable_initial_data(epic)).to eq(expected_data) expect(helper.issuable_initial_data(epic)).to eq(expected_data)
end end
......
...@@ -119,7 +119,7 @@ describe Gitlab::ObjectHierarchy, :postgresql do ...@@ -119,7 +119,7 @@ describe Gitlab::ObjectHierarchy, :postgresql do
end end
end end
describe '#all_groups' do describe '#all_objects' do
let(:relation) do let(:relation) do
described_class.new(Group.where(id: child1.id)).all_objects described_class.new(Group.where(id: child1.id)).all_objects
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