2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Boards
|
|
|
|
class IssuesController < Boards::ApplicationController
|
|
|
|
include BoardsResponses
|
2018-03-27 19:54:05 +05:30
|
|
|
include ControllerWithCrossProjectAccessCheck
|
|
|
|
|
|
|
|
requires_cross_project_access if: -> { board&.group_board? }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before_action :whitelist_query_limiting, only: [:index, :update]
|
|
|
|
before_action :authorize_read_issue, only: [:index]
|
|
|
|
before_action :authorize_create_issue, only: [:create]
|
|
|
|
before_action :authorize_update_issue, only: [:update]
|
|
|
|
skip_before_action :authenticate_user!, only: [:index]
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
def index
|
2018-11-18 11:00:15 +05:30
|
|
|
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
|
2018-12-13 13:39:08 +05:30
|
|
|
Issue.move_to_end(issues) if Gitlab::Database.read_write?
|
|
|
|
issues = issues.preload(:milestone,
|
2018-03-17 18:26:18 +05:30
|
|
|
:assignees,
|
2018-12-13 13:39:08 +05:30
|
|
|
project: [
|
|
|
|
:route,
|
|
|
|
{
|
|
|
|
namespace: [:route]
|
|
|
|
}
|
|
|
|
],
|
2018-03-17 18:26:18 +05:30
|
|
|
labels: [:priorities],
|
|
|
|
notes: [:award_emoji, :author]
|
|
|
|
)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
render_issues(issues, list_service.metadata)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
def render_issues(issues, metadata)
|
|
|
|
data = { issues: serialize_as_json(issues) }
|
|
|
|
data.merge!(metadata)
|
|
|
|
|
|
|
|
render json: data
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def issue
|
2018-03-27 19:54:05 +05:30
|
|
|
@issue ||= issues_finder.find(params[:id])
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
|
|
|
params.merge(board_id: params[:board_id], id: params[:list_id])
|
|
|
|
.reject { |_, value| value.nil? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_finder
|
2018-03-27 19:54:05 +05:30
|
|
|
if board.group_board?
|
|
|
|
IssuesFinder.new(current_user, group_id: board_parent.id)
|
|
|
|
else
|
|
|
|
IssuesFinder.new(current_user, project_id: board_parent.id)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2018-03-27 19:54:05 +05:30
|
|
|
@project ||= if board.group_board?
|
|
|
|
Project.find(issue_params[:project_id])
|
|
|
|
else
|
|
|
|
board_parent
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def move_params
|
|
|
|
params.permit(:board_id, :id, :from_list_id, :to_list_id, :move_before_id, :move_after_id)
|
|
|
|
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-23 12:14:25 +05:30
|
|
|
def serializer
|
|
|
|
IssueSerializer.new(current_user: current_user)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def serialize_as_json(resource)
|
2018-12-23 12:14:25 +05:30
|
|
|
serializer.represent(resource, serializer: 'board', include_full_project_path: board.group_board?)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
# Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42439
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42428')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|