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