2019-01-09 21:04:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-01-07 00:07:50 +00:00
|
|
|
class Projects::ErrorTrackingController < Projects::ErrorTracking::BaseController
|
2020-01-09 21:07:48 +00:00
|
|
|
respond_to :json
|
|
|
|
|
2019-01-09 21:04:27 +00:00
|
|
|
before_action :authorize_read_sentry_issue!
|
2020-01-06 21:07:43 +00:00
|
|
|
before_action :set_issue_id, only: :details
|
2019-01-09 21:04:27 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
set_polling_interval
|
|
|
|
render_index_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-08 21:06:38 +00:00
|
|
|
def details
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2020-01-07 00:07:50 +00:00
|
|
|
set_polling_interval
|
2019-11-08 21:06:38 +00:00
|
|
|
render_issue_detail_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-09 21:07:48 +00:00
|
|
|
def update
|
|
|
|
service = ErrorTracking::IssueUpdateService.new(project, current_user, issue_update_params)
|
|
|
|
result = service.execute
|
|
|
|
|
2020-01-28 21:08:56 +00:00
|
|
|
return if render_errors(result)
|
2020-01-09 21:07:48 +00:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
result: result
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-01-09 21:04:27 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def render_index_json
|
2019-11-19 15:06:24 +00:00
|
|
|
service = ErrorTracking::ListIssuesService.new(
|
|
|
|
project,
|
|
|
|
current_user,
|
|
|
|
list_issues_params
|
|
|
|
)
|
2019-01-09 21:04:27 +00:00
|
|
|
result = service.execute
|
|
|
|
|
2020-01-28 21:08:56 +00:00
|
|
|
return if render_errors(result)
|
2019-01-09 21:04:27 +00:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
errors: serialize_errors(result[:issues]),
|
2019-12-02 12:06:45 +00:00
|
|
|
pagination: result[:pagination],
|
2019-01-09 21:04:27 +00:00
|
|
|
external_url: service.external_url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-11-08 21:06:38 +00:00
|
|
|
def render_issue_detail_json
|
|
|
|
service = ErrorTracking::IssueDetailsService.new(project, current_user, issue_details_params)
|
|
|
|
result = service.execute
|
|
|
|
|
2020-01-28 21:08:56 +00:00
|
|
|
return if render_errors(result)
|
2019-11-08 21:06:38 +00:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
error: serialize_detailed_error(result[:issue])
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-28 21:08:56 +00:00
|
|
|
def render_errors(result)
|
2019-11-08 21:06:38 +00:00
|
|
|
unless result[:status] == :success
|
|
|
|
render json: { message: result[:message] },
|
|
|
|
status: result[:http_status] || :bad_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-19 15:06:24 +00:00
|
|
|
def list_issues_params
|
2020-01-28 21:08:56 +00:00
|
|
|
params.permit(:search_term, :sort, :cursor, :issue_status)
|
2019-11-19 15:06:24 +00:00
|
|
|
end
|
|
|
|
|
2020-01-09 21:07:48 +00:00
|
|
|
def issue_update_params
|
|
|
|
params.permit(:issue_id, :status)
|
|
|
|
end
|
|
|
|
|
2019-11-08 21:06:38 +00:00
|
|
|
def issue_details_params
|
|
|
|
params.permit(:issue_id)
|
|
|
|
end
|
|
|
|
|
2019-11-19 03:06:07 +00:00
|
|
|
def set_issue_id
|
|
|
|
@issue_id = issue_details_params[:issue_id]
|
|
|
|
end
|
|
|
|
|
2019-01-09 21:04:27 +00:00
|
|
|
def serialize_errors(errors)
|
|
|
|
ErrorTracking::ErrorSerializer
|
|
|
|
.new(project: project, user: current_user)
|
|
|
|
.represent(errors)
|
|
|
|
end
|
2019-02-06 16:27:18 +00:00
|
|
|
|
2019-11-08 21:06:38 +00:00
|
|
|
def serialize_detailed_error(error)
|
|
|
|
ErrorTracking::DetailedErrorSerializer
|
|
|
|
.new(project: project, user: current_user)
|
|
|
|
.represent(error)
|
|
|
|
end
|
2019-01-09 21:04:27 +00:00
|
|
|
end
|