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

children_controller.rb « groups « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b474f5d15eef041eb8b09291c0126c78bbe10b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Groups
  class ChildrenController < Groups::ApplicationController
    before_action :group

    def index
      parent = if params[:parent_id].present?
                 GroupFinder.new(current_user).execute(id: params[:parent_id])
               else
                 @group
               end

      if parent.nil?
        render_404
        return
      end

      setup_children(parent)

      respond_to do |format|
        format.json do
          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

    protected

    def setup_children(parent)
      @children = GroupDescendantsFinder.new(current_user: current_user,
                                             parent_group: parent,
                                             params: params).execute
      @children = @children.page(params[:page])
    end
  end
end