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
path: root/app
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-09-08 20:22:33 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 23:49:41 +0300
commit8f6dac4991ba7f5771a24175784f19dc1bbd4103 (patch)
tree5d4f4c06f6bd56db03474dd5d97002d82331a91e /app
parent518216c0627cb6c4b3db62f10877b44d0e912ddb (diff)
Allow filtering children for a group
When fetching children for a group with a filter, we will search all nested groups for results and render them in an expanded tree
Diffstat (limited to 'app')
-rw-r--r--app/controllers/groups_controller.rb10
-rw-r--r--app/serializers/group_child_serializer.rb14
2 files changed, 14 insertions, 10 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index a714f2cc7b0..575d5476867 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -74,11 +74,11 @@ class GroupsController < Groups::ApplicationController
respond_to do |format|
format.json do
- render json: GroupChildSerializer
- .new(current_user: current_user)
- .with_pagination(request, response)
- .hierarchy_base(parent, open_hierarchy: filter[:filter].present)
- .represent(@children)
+ serializer = GroupChildSerializer
+ .new(current_user: current_user)
+ .with_pagination(request, response)
+ serializer.expand_hierarchy(parent) if params[:filter].present?
+ render json: serializer.represent(@children)
end
end
end
diff --git a/app/serializers/group_child_serializer.rb b/app/serializers/group_child_serializer.rb
index ed84c3ae1d7..363f0c9b3d8 100644
--- a/app/serializers/group_child_serializer.rb
+++ b/app/serializers/group_child_serializer.rb
@@ -18,11 +18,14 @@ class GroupChildSerializer < BaseSerializer
end
end
+ protected
+
def represent_hierarchies(children, opts)
if children.is_a?(GroupHierarchy)
- represent_hierarchy(children.hierarchy(hierarchy_root), opts)
+ represent_hierarchy(children.hierarchy(hierarchy_root), opts).first
else
- children.map { |child| represent_hierarchy(child.hierarchy(hierarchy_root), opts) }
+ hierarchies = Array.wrap(GroupHierarchy.merge_hierarchies(children, hierarchy_root))
+ hierarchies.map { |hierarchy| represent_hierarchy(hierarchy, opts) }.flatten
end
end
@@ -30,9 +33,10 @@ class GroupChildSerializer < BaseSerializer
serializer = self.class.new(parameters)
result = if hierarchy.is_a?(Hash)
- parent = hierarchy.keys.first
- serializer.represent(parent, opts)
- .merge(children: [serializer.represent_hierarchy(hierarchy[parent], opts)])
+ hierarchy.map do |parent, children|
+ serializer.represent(parent, opts)
+ .merge(children: Array.wrap(serializer.represent_hierarchy(children, opts)))
+ end
else
serializer.represent(hierarchy, opts)
end