debian-mirror-gitlab/app/controllers/groups/children_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Groups
class ChildrenController < Groups::ApplicationController
2021-02-22 17:27:13 +05:30
extend ::Gitlab::Utils::Override
2018-03-17 18:26:18 +05:30
before_action :group
2023-05-27 22:25:52 +05:30
before_action :validate_per_page
2018-03-27 19:54:05 +05:30
skip_cross_project_access_check :index
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
feature_category :subgroups
2022-06-21 17:19:12 +05:30
# TODO: Set to higher urgency after resolving https://gitlab.com/gitlab-org/gitlab/-/issues/331494
urgency :low, [:index]
2018-03-17 18:26:18 +05:30
def index
2021-02-22 17:27:13 +05:30
params[:sort] ||= @group_projects_sort
2018-03-17 18:26:18 +05:30
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)
2023-05-27 22:25:52 +05:30
@children = GroupDescendantsFinder.new(
current_user: current_user,
parent_group: parent,
params: group_descendants_params
).execute.page(params[:page])
2018-03-17 18:26:18 +05:30
end
2021-02-22 17:27:13 +05:30
private
override :has_project_list?
def has_project_list?
true
end
2023-05-27 22:25:52 +05:30
def group_descendants_params
@group_descendants_params ||= params.to_unsafe_h.compact
end
def validate_per_page
return unless group_descendants_params.key?(:per_page)
per_page = begin
Integer(group_descendants_params[:per_page])
rescue ArgumentError, TypeError
0
end
respond_to do |format|
format.json do
render status: :bad_request, json: { message: 'per_page does not have a valid value' } if per_page < 1
end
end
end
2018-03-17 18:26:18 +05:30
end
end