2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
module Boards
|
|
|
|
class IssuesController < Boards::ApplicationController
|
2019-07-11 09:29:16 -04:00
|
|
|
# This is the maximum amount of issues which can be moved by one request to
|
|
|
|
# bulk_move for now. This is temporary and might be removed in future by
|
|
|
|
# introducing an alternative (async?) approach.
|
|
|
|
# (related: https://gitlab.com/groups/gitlab-org/-/epics/382)
|
|
|
|
MAX_MOVE_ISSUES_COUNT = 50
|
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
include BoardsResponses
|
2018-02-19 14:06:16 -05:00
|
|
|
include ControllerWithCrossProjectAccessCheck
|
|
|
|
|
|
|
|
requires_cross_project_access if: -> { board&.group_board? }
|
2017-08-28 17:56:49 -04:00
|
|
|
|
2019-10-30 05:27:58 -04:00
|
|
|
before_action :whitelist_query_limiting, only: [:bulk_move]
|
2017-08-28 17:56:49 -04:00
|
|
|
before_action :authorize_read_issue, only: [:index]
|
|
|
|
before_action :authorize_create_issue, only: [:create]
|
|
|
|
before_action :authorize_update_issue, only: [:update]
|
2018-03-05 09:39:24 -05:00
|
|
|
skip_before_action :authenticate_user!, only: [:index]
|
2019-07-11 09:29:16 -04:00
|
|
|
before_action :validate_id_list, only: [:bulk_move]
|
|
|
|
before_action :can_move_issues?, only: [:bulk_move]
|
2020-02-12 16:08:48 -05:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:board_search_optimization, board.group)
|
|
|
|
end
|
2017-08-28 17:56:49 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-28 17:56:49 -04:00
|
|
|
def index
|
2018-07-30 09:44:41 -04:00
|
|
|
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
|
|
|
|
issues = list_service.execute
|
|
|
|
issues = issues.page(params[:page]).per(params[:per] || 20).without_count
|
2019-07-31 13:57:04 -04:00
|
|
|
Issue.move_nulls_to_end(issues) if Gitlab::Database.read_write?
|
2020-01-15 07:08:34 -05:00
|
|
|
issues = issues.preload(associations_to_preload)
|
2017-08-28 17:56:49 -04:00
|
|
|
|
2018-07-30 09:44:41 -04:00
|
|
|
render_issues(issues, list_service.metadata)
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-28 17:56:49 -04:00
|
|
|
|
|
|
|
def create
|
|
|
|
service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params)
|
|
|
|
issue = service.execute
|
|
|
|
|
|
|
|
if issue.valid?
|
|
|
|
render json: serialize_as_json(issue)
|
|
|
|
else
|
|
|
|
render json: issue.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-11 09:29:16 -04:00
|
|
|
def bulk_move
|
|
|
|
service = Boards::Issues::MoveService.new(board_parent, current_user, move_params(true))
|
|
|
|
|
|
|
|
issues = Issue.find(params[:ids])
|
2019-07-05 06:50:20 -04:00
|
|
|
|
|
|
|
render json: service.execute_multiple(issues)
|
2019-07-11 09:29:16 -04:00
|
|
|
end
|
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
def update
|
|
|
|
service = Boards::Issues::MoveService.new(board_parent, current_user, move_params)
|
|
|
|
|
|
|
|
if service.execute(issue)
|
|
|
|
head :ok
|
|
|
|
else
|
|
|
|
head :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-15 07:08:34 -05:00
|
|
|
def associations_to_preload
|
|
|
|
[
|
|
|
|
:milestone,
|
|
|
|
:assignees,
|
|
|
|
project: [
|
|
|
|
:route,
|
|
|
|
{
|
|
|
|
namespace: [:route]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
labels: [:priorities],
|
|
|
|
notes: [:award_emoji, :author]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-07-11 09:29:16 -04:00
|
|
|
def can_move_issues?
|
|
|
|
head(:forbidden) unless can?(current_user, :admin_issue, board)
|
|
|
|
end
|
|
|
|
|
2020-02-17 07:09:20 -05:00
|
|
|
def serializer_options(issues)
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
2018-07-30 09:44:41 -04:00
|
|
|
def render_issues(issues, metadata)
|
2020-02-17 07:09:20 -05:00
|
|
|
data = { issues: serialize_as_json(issues, opts: serializer_options(issues)) }
|
2018-07-30 09:44:41 -04:00
|
|
|
data.merge!(metadata)
|
|
|
|
|
|
|
|
render json: data
|
|
|
|
end
|
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
def issue
|
2017-12-11 09:21:06 -05:00
|
|
|
@issue ||= issues_finder.find(params[:id])
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
2020-01-02 08:03:23 -05:00
|
|
|
params.permit(*Boards::Issues::ListService.valid_params).merge(board_id: params[:board_id], id: params[:list_id])
|
2017-08-28 17:56:49 -04:00
|
|
|
.reject { |_, value| value.nil? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_finder
|
2018-02-19 14:06:16 -05:00
|
|
|
if board.group_board?
|
|
|
|
IssuesFinder.new(current_user, group_id: board_parent.id)
|
|
|
|
else
|
|
|
|
IssuesFinder.new(current_user, project_id: board_parent.id)
|
|
|
|
end
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2018-03-05 09:39:24 -05:00
|
|
|
@project ||= if board.group_board?
|
|
|
|
Project.find(issue_params[:project_id])
|
|
|
|
else
|
|
|
|
board_parent
|
|
|
|
end
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
|
|
|
|
2019-07-11 09:29:16 -04:00
|
|
|
def move_params(multiple = false)
|
|
|
|
id_param = multiple ? :ids : :id
|
|
|
|
params.permit(id_param, :board_id, :from_list_id, :to_list_id, :move_before_id, :move_after_id)
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def issue_params
|
|
|
|
params.require(:issue)
|
|
|
|
.permit(:title, :milestone_id, :project_id)
|
|
|
|
.merge(board_id: params[:board_id], list_id: params[:list_id], request: request)
|
|
|
|
end
|
|
|
|
|
2018-12-03 10:23:38 -05:00
|
|
|
def serializer
|
|
|
|
IssueSerializer.new(current_user: current_user)
|
|
|
|
end
|
|
|
|
|
2020-02-17 07:09:20 -05:00
|
|
|
def serialize_as_json(resource, opts: {})
|
|
|
|
opts.merge!(include_full_project_path: board.group_board?, serializer: 'board')
|
|
|
|
|
|
|
|
serializer.represent(resource, opts)
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
2018-01-15 10:21:04 -05:00
|
|
|
|
|
|
|
def whitelist_query_limiting
|
2019-10-30 05:27:58 -04:00
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab/issues/35174')
|
2018-01-15 10:21:04 -05:00
|
|
|
end
|
2019-07-11 09:29:16 -04:00
|
|
|
|
|
|
|
def validate_id_list
|
|
|
|
head(:bad_request) unless params[:ids].is_a?(Array)
|
|
|
|
head(:unprocessable_entity) if params[:ids].size > MAX_MOVE_ISSUES_COUNT
|
|
|
|
end
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
|
|
|
end
|
2020-01-15 07:08:34 -05:00
|
|
|
|
|
|
|
Boards::IssuesController.prepend_if_ee('EE::Boards::IssuesController')
|