Commit 238a9674 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents b5294caa d3a100ab
...@@ -6,6 +6,8 @@ module Projects ...@@ -6,6 +6,8 @@ module Projects
before_action :check_license before_action :check_license
before_action :authorize_update_environment! before_action :authorize_update_environment!
helper_method :error_tracking_setting
def show def show
end end
...@@ -22,13 +24,18 @@ module Projects ...@@ -22,13 +24,18 @@ module Projects
private private
def error_tracking_setting
@error_tracking_setting ||= project.error_tracking_setting ||
project.build_error_tracking_setting
end
def update_params def update_params
params.require(:project).permit(permitted_project_params) params.require(:project).permit(permitted_project_params)
end end
# overridden in EE # overridden in EE
def permitted_project_params def permitted_project_params
{} { error_tracking_setting_attributes: [:enabled, :api_url, :token] }
end end
def check_license def check_license
......
...@@ -287,7 +287,7 @@ module ProjectsHelper ...@@ -287,7 +287,7 @@ module ProjectsHelper
# overridden in EE # overridden in EE
def settings_operations_available? def settings_operations_available?
false Feature.enabled?(:error_tracking, @project) && can?(current_user, :read_environment, @project)
end end
private private
...@@ -551,6 +551,7 @@ module ProjectsHelper ...@@ -551,6 +551,7 @@ module ProjectsHelper
services#edit services#edit
repository#show repository#show
ci_cd#show ci_cd#show
operations#show
badges#index badges#index
pages#show pages#show
] ]
......
...@@ -296,6 +296,8 @@ class Project < ActiveRecord::Base ...@@ -296,6 +296,8 @@ class Project < ActiveRecord::Base
allow_destroy: true, allow_destroy: true,
reject_if: ->(attrs) { attrs[:id].blank? && attrs[:url].blank? } 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 :name, to: :owner, allow_nil: true, prefix: true
delegate :members, to: :team, prefix: true delegate :members, to: :team, prefix: true
delegate :add_user, :add_users, to: :team delegate :add_user, :add_users, to: :team
......
...@@ -12,7 +12,7 @@ module Projects ...@@ -12,7 +12,7 @@ module Projects
private private
def project_update_params def project_update_params
{} params.slice(:error_tracking_setting_attributes)
end end
end end
end end
......
- 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'
- @content_class = 'limit-container-width' unless fluid_layout - @content_class = 'limit-container-width' unless fluid_layout
- page_title _('Operations') - page_title _('Operations')
= render 'projects/settings/operations/error_tracking', expanded: true
= render_if_exists 'projects/settings/operations/tracing' = render_if_exists 'projects/settings/operations/tracing'
...@@ -983,6 +983,9 @@ msgstr "" ...@@ -983,6 +983,9 @@ msgstr ""
msgid "August" msgid "August"
msgstr "" msgstr ""
msgid "Auth Token"
msgstr ""
msgid "Authentication Log" msgid "Authentication Log"
msgstr "" msgstr ""
...@@ -3264,6 +3267,9 @@ msgstr "" ...@@ -3264,6 +3267,9 @@ msgstr ""
msgid "Enter the merge request title" msgid "Enter the merge request title"
msgstr "" msgstr ""
msgid "Enter your Sentry API URL"
msgstr ""
msgid "Environment variables" msgid "Environment variables"
msgstr "" msgstr ""
...@@ -3741,6 +3747,9 @@ msgstr "" ...@@ -3741,6 +3747,9 @@ msgstr ""
msgid "Filter..." msgid "Filter..."
msgstr "" msgstr ""
msgid "Find and manage Auth Tokens in your Sentry account settings page."
msgstr ""
msgid "Find by path" msgid "Find by path"
msgstr "" msgstr ""
...@@ -7810,6 +7819,9 @@ msgstr "" ...@@ -7810,6 +7819,9 @@ msgstr ""
msgid "Send usage data" msgid "Send usage data"
msgstr "" msgstr ""
msgid "Sentry API URL"
msgstr ""
msgid "Sep" msgid "Sep"
msgstr "" msgstr ""
...@@ -9220,6 +9232,9 @@ msgstr "" ...@@ -9220,6 +9232,9 @@ msgstr ""
msgid "To import an SVN repository, check out %{svn_link}." msgid "To import an SVN repository, check out %{svn_link}."
msgstr "" 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." 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 "" msgstr ""
...@@ -10443,6 +10458,9 @@ msgstr "" ...@@ -10443,6 +10458,9 @@ msgstr ""
msgid "here" msgid "here"
msgstr "" msgstr ""
msgid "http://<sentry-host>/api/0/projects/{organization_slug}/{project_slug}/issues/"
msgstr ""
msgid "https://your-bitbucket-server" msgid "https://your-bitbucket-server"
msgstr "" msgstr ""
......
...@@ -11,25 +11,171 @@ describe Projects::Settings::OperationsController do ...@@ -11,25 +11,171 @@ describe Projects::Settings::OperationsController do
project.add_maintainer(user) project.add_maintainer(user)
end end
describe 'GET #show' do context 'error tracking' do
it 'returns 404' do describe 'GET #show' do
get :show, params: project_params(project) 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
end
describe 'PATCH #update' do private
it 'returns 404' do
patch :update, params: project_params(project)
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
end end
private private
def project_params(project) def project_params(project, params = {})
{ namespace_id: project.namespace, project_id: project } {
namespace_id: project.namespace,
project_id: project,
project: params
}
end end
end end
# 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
...@@ -11,6 +11,67 @@ describe Projects::Operations::UpdateService do ...@@ -11,6 +11,67 @@ describe Projects::Operations::UpdateService do
subject { described_class.new(project, user, params) } subject { described_class.new(project, user, params) }
describe '#execute' do 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 context 'with inappropriate params' do
let(:params) { { name: '' } } let(:params) { { name: '' } }
......
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment