Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 17:57:33 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-05 12:10:57 +0300
commit57bd3bb34a19bf812fd6a74f394a69c491b05dd0 (patch)
tree1407f3824a3d0b22bd64fefdfd8a2b4e6ee2c8f2 /app/models
parent06e00913f505268e0a45f4f1516a93a84600c242 (diff)
Force parents to be preloaded for building a hierarchy
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/group_descendant.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/app/models/concerns/group_descendant.rb b/app/models/concerns/group_descendant.rb
index 6c465079753..8c8f7cb5e0d 100644
--- a/app/models/concerns/group_descendant.rb
+++ b/app/models/concerns/group_descendant.rb
@@ -22,16 +22,22 @@ module GroupDescendant
private
def ancestors_upto(hierarchy_top = nil)
- if hierarchy_top
- Gitlab::GroupHierarchy.new(Group.where(id: hierarchy_top)).base_and_descendants
+ if self.is_a?(Group)
+ Gitlab::GroupHierarchy.new(Group.where(id: id))
+ .ancestors(upto: hierarchy_top)
else
- Gitlab::GroupHierarchy.new(Group.where(id: self)).all_groups
+ Gitlab::GroupHierarchy.new(Group.where(id: parent_id))
+ .base_and_ancestors(upto: hierarchy_top)
end
end
def expand_hierarchy_for_child(child, hierarchy, hierarchy_top, preloaded)
- parent = preloaded.detect { |possible_parent| possible_parent.is_a?(Group) && possible_parent.id == child.parent_id }
- parent ||= child.parent
+ parent = hierarchy_top if hierarchy_top && child.parent_id == hierarchy_top.id
+ parent ||= preloaded.detect { |possible_parent| possible_parent.is_a?(Group) && possible_parent.id == child.parent_id }
+
+ if parent.nil? && !child.parent_id.nil?
+ raise ArgumentError.new('parent was not preloaded')
+ end
if parent.nil? && hierarchy_top.present?
raise ArgumentError.new('specified top is not part of the tree')