gitlab-org--gitlab-foss/app/controllers/projects/error_tracking_controller.rb

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

109 lines
2.4 KiB
Ruby
Raw Normal View History

2019-01-09 16:04:27 -05:00
# frozen_string_literal: true
class Projects::ErrorTrackingController < Projects::ErrorTracking::BaseController
respond_to :json
2019-01-09 16:04:27 -05:00
before_action :authorize_read_sentry_issue!
before_action :set_issue_id, only: :details
2019-01-09 16:04:27 -05:00
before_action only: [:index] do
push_frontend_feature_flag(:integrated_error_tracking, project)
end
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
def details
respond_to do |format|
format.html
format.json do
set_polling_interval
render_issue_detail_json
end
end
end
def update
service = ::ErrorTracking::IssueUpdateService.new(project, current_user, issue_update_params)
result = service.execute
return if render_errors(result)
render json: {
result: result
}
end
2019-01-09 16:04:27 -05:00
private
def render_index_json
service = ::ErrorTracking::ListIssuesService.new(
project,
current_user,
list_issues_params
)
2019-01-09 16:04:27 -05:00
result = service.execute
return if render_errors(result)
2019-01-09 16:04:27 -05:00
render json: {
errors: serialize_errors(result[:issues]),
pagination: result[:pagination],
2019-01-09 16:04:27 -05:00
external_url: service.external_url
}
end
def render_issue_detail_json
service = ::ErrorTracking::IssueDetailsService.new(project, current_user, issue_details_params)
result = service.execute
return if render_errors(result)
render json: {
error: serialize_detailed_error(result[:issue])
}
end
def render_errors(result)
unless result[:status] == :success
render json: { message: result[:message] },
status: result[:http_status] || :bad_request
end
end
def list_issues_params
params.permit(:search_term, :sort, :cursor, :issue_status).merge(tracking_event: :error_tracking_view_list)
end
def issue_update_params
params.permit(:issue_id, :status)
end
def issue_details_params
params.permit(:issue_id).merge(tracking_event: :error_tracking_view_details)
end
def set_issue_id
@issue_id = issue_details_params[:issue_id]
end
2019-01-09 16:04:27 -05:00
def serialize_errors(errors)
::ErrorTracking::ErrorSerializer
2019-01-09 16:04:27 -05:00
.new(project: project, user: current_user)
.represent(errors)
end
def serialize_detailed_error(error)
::ErrorTracking::DetailedErrorSerializer
.new(project: project, user: current_user)
.represent(error)
end
2019-01-09 16:04:27 -05:00
end