summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2019-01-27 20:38:35 +0530
committerrpereira2 <rpereira@gitlab.com>2019-02-07 10:37:06 +0530
commit045fbf273ef865a451be548ce149d07f04230ab8 (patch)
tree660a4d24a35ef780006b22f85bbcca04b9ada7cc
parent0bb9e3d550f4ce0b29a23cc0c377dde327fa7d2a (diff)
downloadgitlab-ce-045fbf273ef865a451be548ce149d07f04230ab8.tar.gz
Update the operations settings update endpoint
Update the operations settings save endpoint to handle the new error_tracking settings (api_host, project selection dropdown).
-rw-r--r--app/controllers/projects/settings/operations_controller.rb9
-rw-r--r--app/services/projects/operations/update_service.rb28
-rw-r--r--spec/controllers/projects/settings/operations_controller_spec.rb10
-rw-r--r--spec/services/projects/operations/update_service_spec.rb36
4 files changed, 69 insertions, 14 deletions
diff --git a/app/controllers/projects/settings/operations_controller.rb b/app/controllers/projects/settings/operations_controller.rb
index 521ec2acebb..56d0c8228b3 100644
--- a/app/controllers/projects/settings/operations_controller.rb
+++ b/app/controllers/projects/settings/operations_controller.rb
@@ -35,7 +35,14 @@ module Projects
# overridden in EE
def permitted_project_params
- { error_tracking_setting_attributes: [:enabled, :api_url, :token] }
+ {
+ error_tracking_setting_attributes: [
+ :enabled,
+ :api_host,
+ :token,
+ project: [:slug, :name, :organization_slug, :organization_name]
+ ]
+ }
end
def check_license
diff --git a/app/services/projects/operations/update_service.rb b/app/services/projects/operations/update_service.rb
index abd6d8de750..642a43e83d1 100644
--- a/app/services/projects/operations/update_service.rb
+++ b/app/services/projects/operations/update_service.rb
@@ -12,7 +12,33 @@ module Projects
private
def project_update_params
- params.slice(:error_tracking_setting_attributes)
+ attribs = params.slice(:error_tracking_setting_attributes)
+
+ if attribs[:error_tracking_setting_attributes].present?
+ attribs[:error_tracking_setting_attributes] =
+ construct_error_tracking_setting_params(attribs[:error_tracking_setting_attributes])
+ end
+
+ attribs
+ end
+
+ def construct_error_tracking_setting_params(settings)
+ settings[:api_url] = ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from(
+ api_host: settings[:api_host],
+ project_slug: settings.dig(:project, :slug),
+ organization_slug: settings.dig(:project, :organization_slug)
+ )
+
+ settings[:project_name] = settings.dig(:project, :name).presence
+ settings[:organization_name] = settings.dig(:project, :organization_name).presence
+
+ settings.slice(
+ :api_url,
+ :token,
+ :enabled,
+ :project_name,
+ :organization_name
+ )
end
end
end
diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb
index d989ec22481..4ee0c4eeeda 100644
--- a/spec/controllers/projects/settings/operations_controller_spec.rb
+++ b/spec/controllers/projects/settings/operations_controller_spec.rb
@@ -74,8 +74,14 @@ describe Projects::Settings::OperationsController do
{
error_tracking_setting_attributes: {
enabled: '1',
- api_url: 'http://url',
- token: 'token'
+ api_host: 'http://url',
+ token: 'token',
+ project: {
+ slug: 'sentry-project',
+ name: 'Sentry Project',
+ organization_slug: 'sentry-org',
+ organization_name: 'Sentry Org'
+ }
}
}
end
diff --git a/spec/services/projects/operations/update_service_spec.rb b/spec/services/projects/operations/update_service_spec.rb
index 6afae3da80c..f40b4aa5ce9 100644
--- a/spec/services/projects/operations/update_service_spec.rb
+++ b/spec/services/projects/operations/update_service_spec.rb
@@ -14,13 +14,19 @@ describe Projects::Operations::UpdateService do
context 'error tracking' do
context 'with existing error tracking setting' do
let(:params) do
- {
+ ActionController::Parameters.new({
error_tracking_setting_attributes: {
enabled: false,
- api_url: 'http://gitlab.com/api/0/projects/org/project',
- token: 'token'
+ api_host: 'http://gitlab.com/',
+ token: 'token',
+ project: {
+ slug: 'project',
+ name: 'Project',
+ organization_slug: 'org',
+ organization_name: 'Org'
+ }
}
- }
+ }).permit!
end
before do
@@ -32,28 +38,38 @@ describe Projects::Operations::UpdateService do
project.reload
expect(project.error_tracking_setting).not_to be_enabled
- expect(project.error_tracking_setting.api_url).to eq('http://gitlab.com/api/0/projects/org/project')
+ expect(project.error_tracking_setting.api_url).to eq('http://gitlab.com/api/0/projects/org/project/')
expect(project.error_tracking_setting.token).to eq('token')
+ expect(project.error_tracking_setting.read_attribute(:project_name)).to eq('Project')
+ expect(project.error_tracking_setting.read_attribute(:organization_name)).to eq('Org')
end
end
context 'without an existing error tracking setting' do
let(:params) do
- {
+ ActionController::Parameters.new({
error_tracking_setting_attributes: {
enabled: true,
- api_url: 'http://gitlab.com/api/0/projects/org/project',
- token: 'token'
+ api_host: 'http://gitlab.com/',
+ token: 'token',
+ project: {
+ slug: 'project',
+ name: 'Project',
+ organization_slug: 'org',
+ organization_name: 'Org'
+ }
}
- }
+ }).permit!
end
it 'creates a setting' do
expect(result[:status]).to eq(:success)
expect(project.error_tracking_setting).to be_enabled
- expect(project.error_tracking_setting.api_url).to eq('http://gitlab.com/api/0/projects/org/project')
+ expect(project.error_tracking_setting.api_url).to eq('http://gitlab.com/api/0/projects/org/project/')
expect(project.error_tracking_setting.token).to eq('token')
+ expect(project.error_tracking_setting.read_attribute(:project_name)).to eq('Project')
+ expect(project.error_tracking_setting.read_attribute(:organization_name)).to eq('Org')
end
end