diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-01-07 19:30:09 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-01-07 19:30:09 +0000 |
commit | 329725c2bd2fe024239707878c2d936f07fca05c (patch) | |
tree | d3f21efa3ded17780f93275f4c282f359c413454 | |
parent | 97b365058272ceea69d4cfc6eeb7d4f6bd945b3c (diff) | |
parent | 6710c87434e6d2508dc6b2553594258e77d23723 (diff) | |
download | gitlab-ce-329725c2bd2fe024239707878c2d936f07fca05c.tar.gz |
Merge branch '55177-sentry-configuration' into 'master'
Resolve "Sentry Configuration"
See merge request gitlab-org/gitlab-ce!23724
-rw-r--r-- | app/controllers/projects/settings/operations_controller.rb | 9 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 3 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/services/projects/operations/update_service.rb | 2 | ||||
-rw-r--r-- | app/views/projects/settings/operations/_error_tracking.html.haml | 30 | ||||
-rw-r--r-- | app/views/projects/settings/operations/show.html.haml | 1 | ||||
-rw-r--r-- | locale/gitlab.pot | 21 | ||||
-rw-r--r-- | spec/controllers/projects/settings/operations_controller_spec.rb | 168 | ||||
-rw-r--r-- | spec/features/projects/settings/operations_settings_spec.rb | 39 | ||||
-rw-r--r-- | spec/services/projects/operations/update_service_spec.rb | 61 | ||||
-rw-r--r-- | spec/views/projects/settings/operations/show.html.haml_spec.rb | 39 |
11 files changed, 361 insertions, 14 deletions
diff --git a/app/controllers/projects/settings/operations_controller.rb b/app/controllers/projects/settings/operations_controller.rb index ae8ac61ad46..521ec2acebb 100644 --- a/app/controllers/projects/settings/operations_controller.rb +++ b/app/controllers/projects/settings/operations_controller.rb @@ -6,6 +6,8 @@ module Projects before_action :check_license before_action :authorize_update_environment! + helper_method :error_tracking_setting + def show end @@ -22,13 +24,18 @@ module Projects private + def error_tracking_setting + @error_tracking_setting ||= project.error_tracking_setting || + project.build_error_tracking_setting + end + def update_params params.require(:project).permit(permitted_project_params) end # overridden in EE def permitted_project_params - {} + { error_tracking_setting_attributes: [:enabled, :api_url, :token] } end def check_license diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index af7a262e32c..e67c327f7f8 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -285,7 +285,7 @@ module ProjectsHelper # overridden in EE def settings_operations_available? - false + Feature.enabled?(:error_tracking, @project) && can?(current_user, :read_environment, @project) end private @@ -549,6 +549,7 @@ module ProjectsHelper services#edit repository#show ci_cd#show + operations#show badges#index pages#show ] diff --git a/app/models/project.rb b/app/models/project.rb index 9d0348d848a..d57098407d0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -296,6 +296,8 @@ class Project < ActiveRecord::Base allow_destroy: true, reject_if: ->(attrs) { attrs[:id].blank? && attrs[:url].blank? } + accepts_nested_attributes_for :error_tracking_setting, update_only: true + delegate :name, to: :owner, allow_nil: true, prefix: true delegate :members, to: :team, prefix: true delegate :add_user, :add_users, to: :team diff --git a/app/services/projects/operations/update_service.rb b/app/services/projects/operations/update_service.rb index 7ff0599ee95..abd6d8de750 100644 --- a/app/services/projects/operations/update_service.rb +++ b/app/services/projects/operations/update_service.rb @@ -12,7 +12,7 @@ module Projects private def project_update_params - {} + params.slice(:error_tracking_setting_attributes) end end end diff --git a/app/views/projects/settings/operations/_error_tracking.html.haml b/app/views/projects/settings/operations/_error_tracking.html.haml new file mode 100644 index 00000000000..71335e4dfd0 --- /dev/null +++ b/app/views/projects/settings/operations/_error_tracking.html.haml @@ -0,0 +1,30 @@ +- return unless Feature.enabled?(:error_tracking, @project) && can?(current_user, :read_environment, @project) + +- setting = error_tracking_setting + +%section.settings.expanded.border-0.no-animate + .settings-header + %h4 + = _('Error Tracking') + %p + = _('To link Sentry to GitLab, enter your Sentry URL and Auth Token.') + .settings-content + = form_for @project, url: project_settings_operations_path(@project), method: :patch do |f| + = form_errors(@project) + .form-group + = f.fields_for :error_tracking_setting_attributes, setting do |form| + .form-check.form-group + = form.check_box :enabled, class: 'form-check-input' + = form.label :enabled, _('Active'), class: 'form-check-label' + .form-group + = form.label :api_url, _('Sentry API URL'), class: 'label-bold' + = form.url_field :api_url, class: 'form-control', placeholder: _('http://<sentry-host>/api/0/projects/{organization_slug}/{project_slug}/issues/') + %p.form-text.text-muted + = _('Enter your Sentry API URL') + .form-group + = form.label :token, _('Auth Token'), class: 'label-bold' + = form.text_field :token, class: 'form-control' + %p.form-text.text-muted + = _('Find and manage Auth Tokens in your Sentry account settings page.') + + = f.submit _('Save changes'), class: 'btn btn-success' diff --git a/app/views/projects/settings/operations/show.html.haml b/app/views/projects/settings/operations/show.html.haml index 0782029dbcd..b36fa9a5f51 100644 --- a/app/views/projects/settings/operations/show.html.haml +++ b/app/views/projects/settings/operations/show.html.haml @@ -1,4 +1,5 @@ - @content_class = 'limit-container-width' unless fluid_layout - page_title _('Operations') += render 'projects/settings/operations/error_tracking', expanded: true = render_if_exists 'projects/settings/operations/tracing' diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 092c37d96bf..f25f9cc531a 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -768,6 +768,9 @@ msgstr "" msgid "August" msgstr "" +msgid "Auth Token" +msgstr "" + msgid "Authentication Log" msgstr "" @@ -2761,6 +2764,9 @@ msgstr "" msgid "Enter the merge request title" msgstr "" +msgid "Enter your Sentry API URL" +msgstr "" + msgid "Environment variables" msgstr "" @@ -2863,6 +2869,9 @@ msgstr "" msgid "Error Reporting and Logging" msgstr "" +msgid "Error Tracking" +msgstr "" + msgid "Error fetching contributors data." msgstr "" @@ -3085,6 +3094,9 @@ msgstr "" msgid "Filter..." msgstr "" +msgid "Find and manage Auth Tokens in your Sentry account settings page." +msgstr "" + msgid "Find by path" msgstr "" @@ -5973,6 +5985,9 @@ msgstr "" msgid "Send usage data" msgstr "" +msgid "Sentry API URL" +msgstr "" + msgid "Sep" msgstr "" @@ -7101,6 +7116,9 @@ msgstr "" msgid "To import an SVN repository, check out %{svn_link}." msgstr "" +msgid "To link Sentry to GitLab, enter your Sentry URL and Auth Token." +msgstr "" + msgid "To move or copy an entire GitLab project from another GitLab installation to this one, navigate to the original project's settings page, generate an export file, and upload it here." msgstr "" @@ -7918,6 +7936,9 @@ msgstr "" msgid "here" msgstr "" +msgid "http://<sentry-host>/api/0/projects/{organization_slug}/{project_slug}/issues/" +msgstr "" + msgid "https://your-bitbucket-server" msgstr "" diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index fbb26de76d1..810f5bb64ba 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -11,25 +11,171 @@ describe Projects::Settings::OperationsController do project.add_maintainer(user) end - describe 'GET #show' do - it 'returns 404' do - get :show, params: project_params(project) + context 'error tracking' do + describe 'GET #show' do + it 'renders show template' do + get :show, params: project_params(project) - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end + + context 'with existing setting' do + let!(:error_tracking_setting) do + create(:project_error_tracking_setting, project: project) + end + + it 'loads existing setting' do + get :show, params: project_params(project) + + expect(controller.helpers.error_tracking_setting) + .to eq(error_tracking_setting) + end + end + + context 'without an existing setting' do + it 'builds a new setting' do + get :show, params: project_params(project) + + expect(controller.helpers.error_tracking_setting).to be_new_record + end + end + + context 'with feature flag disabled' do + before do + stub_feature_flags(error_tracking: false) + end + + it 'renders 404' do + get :show, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with insufficient permissions' do + before do + project.add_reporter(user) + end + + it 'renders 404' do + get :show, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as an anonymous user' do + before do + sign_out(user) + end + + it 'redirects to signup page' do + get :show, params: project_params(project) + + expect(response).to redirect_to(new_user_session_path) + end + end + end + + describe 'PATCH #update' do + let(:operations_update_service) { spy(:operations_update_service) } + let(:operations_url) { project_settings_operations_url(project) } + + let(:error_tracking_params) do + { + error_tracking_setting_attributes: { + enabled: '1', + api_url: 'http://url', + token: 'token' + } + } + end + let(:error_tracking_permitted) do + ActionController::Parameters.new(error_tracking_params).permit! + end + + context 'when update succeeds' do + before do + stub_operations_update_service_returning(status: :success) + end + + it 'shows a notice' do + patch :update, params: project_params(project, error_tracking_params) + + expect(response).to redirect_to(operations_url) + expect(flash[:notice]).to eq _('Your changes have been saved') + end + end + + context 'when update fails' do + before do + stub_operations_update_service_returning(status: :error) + end + + it 'renders show page' do + patch :update, params: project_params(project, error_tracking_params) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end + end + + context 'with feature flag disabled' do + before do + stub_feature_flags(error_tracking: false) + end + + it 'renders 404' do + patch :update, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with insufficient permissions' do + before do + project.add_reporter(user) + end + + it 'renders 404' do + patch :update, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as an anonymous user' do + before do + sign_out(user) + end + + it 'redirects to signup page' do + patch :update, params: project_params(project) + + expect(response).to redirect_to(new_user_session_path) + end + end end - end - describe 'PATCH #update' do - it 'returns 404' do - patch :update, params: project_params(project) + private - expect(response).to have_gitlab_http_status(:not_found) + def stub_operations_update_service_returning(return_value = {}) + expect(::Projects::Operations::UpdateService) + .to receive(:new).with(project, user, error_tracking_permitted) + .and_return(operations_update_service) + expect(operations_update_service).to receive(:execute) + .and_return(return_value) end end private - def project_params(project) - { namespace_id: project.namespace, project_id: project } + def project_params(project, params = {}) + { + namespace_id: project.namespace, + project_id: project, + project: params + } end end diff --git a/spec/features/projects/settings/operations_settings_spec.rb b/spec/features/projects/settings/operations_settings_spec.rb new file mode 100644 index 00000000000..1f2328a6dd8 --- /dev/null +++ b/spec/features/projects/settings/operations_settings_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Projects > Settings > For a forked project', :js do + let(:user) { create(:user) } + let(:project) { create(:project, :repository) } + let(:role) { :maintainer } + + before do + stub_feature_flags(error_tracking: true) + sign_in(user) + project.add_role(user, role) + end + + describe 'Sidebar > Operations' do + context 'when sidebar feature flag enabled' do + it 'renders the settings link in the sidebar' do + visit project_path(project) + wait_for_requests + + expect(page).to have_selector('a[title="Operations"]', visible: false) + end + end + + context 'when sidebar feature flag disabled' do + before do + stub_feature_flags(error_tracking: false) + end + + it 'does not render the settings link in the sidebar' do + visit project_path(project) + wait_for_requests + + expect(page).not_to have_selector('a[title="Operations"]', visible: false) + end + end + end +end diff --git a/spec/services/projects/operations/update_service_spec.rb b/spec/services/projects/operations/update_service_spec.rb index 332c1600cde..731be907453 100644 --- a/spec/services/projects/operations/update_service_spec.rb +++ b/spec/services/projects/operations/update_service_spec.rb @@ -11,6 +11,67 @@ describe Projects::Operations::UpdateService do subject { described_class.new(project, user, params) } describe '#execute' do + context 'error tracking' do + context 'with existing error tracking setting' do + let(:params) do + { + error_tracking_setting_attributes: { + enabled: false, + api_url: 'http://url', + token: 'token' + } + } + end + + before do + create(:project_error_tracking_setting, project: project) + end + + it 'updates the settings' do + expect(result[:status]).to eq(:success) + + project.reload + expect(project.error_tracking_setting).not_to be_enabled + expect(project.error_tracking_setting.api_url).to eq('http://url') + expect(project.error_tracking_setting.token).to eq('token') + end + end + + context 'without an existing error tracking setting' do + let(:params) do + { + error_tracking_setting_attributes: { + enabled: true, + api_url: 'http://url', + token: 'token' + } + } + 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://url') + expect(project.error_tracking_setting.token).to eq('token') + end + end + + context 'with invalid parameters' do + let(:params) { {} } + + let!(:error_tracking_setting) do + create(:project_error_tracking_setting, project: project) + end + + it 'does nothing' do + expect(result[:status]).to eq(:success) + expect(project.reload.error_tracking_setting) + .to eq(error_tracking_setting) + end + end + end + context 'with inappropriate params' do let(:params) { { name: '' } } diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb new file mode 100644 index 00000000000..752fd82c5e8 --- /dev/null +++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rails_helper' + +describe 'projects/settings/operations/show' do + let(:project) { create(:project) } + let(:user) { create(:user) } + + before do + assign :project, project + end + + describe 'Operations > Error Tracking' do + before do + stub_feature_flags(error_tracking: true) + + project.add_reporter(user) + + allow(view).to receive(:error_tracking_setting) + .and_return(error_tracking_setting) + allow(view).to receive(:current_user).and_return(user) + end + + let!(:error_tracking_setting) do + create(:project_error_tracking_setting, project: project) + end + + context 'Settings page ' do + it 'renders the Operations Settings page' do + render + + expect(rendered).to have_content _('Error Tracking') + expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token') + expect(rendered).to have_content _('Active') + end + end + end +end |