2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-11-18 22:05:49 +05:30
|
|
|
class ErrorTracking::ProjectSettings < ::API::Base
|
2020-03-13 15:44:24 +05:30
|
|
|
before { authenticate! }
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
ERROR_TRACKING_PROJECT_SETTINGS_TAGS = %w[error_tracking_project_settings].freeze
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
feature_category :error_tracking
|
2022-07-23 23:45:48 +05:30
|
|
|
urgency :low
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
helpers do
|
|
|
|
def project_setting
|
|
|
|
@project_setting ||= user_project.error_tracking_setting
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :id, types: [String, Integer],
|
|
|
|
desc: 'The ID or URL-encoded path of the project owned by the authenticated user'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2021-11-11 11:23:49 +05:30
|
|
|
before do
|
|
|
|
authorize! :admin_operations, user_project
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Get Error Tracking settings' do
|
|
|
|
detail 'Get error tracking settings for the project. This feature was introduced in GitLab 12.7.'
|
2020-03-13 15:44:24 +05:30
|
|
|
success Entities::ErrorTracking::ProjectSetting
|
2023-01-13 00:05:48 +05:30
|
|
|
tags ERROR_TRACKING_PROJECT_SETTINGS_TAGS
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
get ':id/error_tracking/settings' do
|
2023-05-27 22:25:52 +05:30
|
|
|
not_found!('Error Tracking Setting') unless project_setting
|
2021-11-11 11:23:49 +05:30
|
|
|
present project_setting, with: Entities::ErrorTracking::ProjectSetting
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Enable or disable the Error Tracking project settings' do
|
|
|
|
detail 'The API allows you to enable or disable the Error Tracking settings for a project.'\
|
|
|
|
'Only for users with the Maintainer role for the project.'
|
2020-03-13 15:44:24 +05:30
|
|
|
success Entities::ErrorTracking::ProjectSetting
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags ERROR_TRACKING_PROJECT_SETTINGS_TAGS
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :active,
|
|
|
|
type: Boolean,
|
|
|
|
desc: 'Pass true to enable the already configured Error Tracking settings or false to disable it.',
|
|
|
|
allow_blank: false
|
|
|
|
optional :integrated,
|
|
|
|
type: Boolean,
|
|
|
|
desc: 'Pass true to enable the integrated Error Tracking backend. Available in GitLab 14.2 and later.'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
patch ':id/error_tracking/settings/' do
|
2023-05-27 22:25:52 +05:30
|
|
|
not_found!('Error Tracking Setting') unless project_setting
|
2020-03-13 15:44:24 +05:30
|
|
|
update_params = {
|
|
|
|
error_tracking_setting_attributes: { enabled: params[:active] }
|
|
|
|
}
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
unless params[:integrated].nil?
|
|
|
|
update_params[:error_tracking_setting_attributes][:integrated] = params[:integrated]
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
2021-11-11 11:23:49 +05:30
|
|
|
present project_setting, with: Entities::ErrorTracking::ProjectSetting
|
2020-03-13 15:44:24 +05:30
|
|
|
else
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
desc 'Update Error Tracking project settings. Available in GitLab 15.10 and later.' do
|
|
|
|
detail 'Update Error Tracking settings for a project. ' \
|
|
|
|
'Only for users with Maintainer role for the project.'
|
|
|
|
success Entities::ErrorTracking::ProjectSetting
|
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags ERROR_TRACKING_PROJECT_SETTINGS_TAGS
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :active, type: Boolean,
|
|
|
|
desc: 'Pass true to enable the configured Error Tracking settings or false to disable it.',
|
|
|
|
allow_blank: false
|
|
|
|
requires :integrated,
|
|
|
|
type: Boolean,
|
|
|
|
desc: 'Pass true to enable the integrated Error Tracking backend.'
|
|
|
|
end
|
|
|
|
|
|
|
|
put ':id/error_tracking/settings' do
|
|
|
|
not_found! unless Feature.enabled?(:integrated_error_tracking, user_project)
|
|
|
|
update_params = {
|
|
|
|
error_tracking_setting_attributes: { enabled: params[:active] }
|
|
|
|
}
|
|
|
|
|
|
|
|
update_params[:error_tracking_setting_attributes][:integrated] = params[:integrated]
|
|
|
|
|
|
|
|
result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute
|
|
|
|
if result[:status] == :success
|
|
|
|
present project_setting, with: Entities::ErrorTracking::ProjectSetting
|
|
|
|
else
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|