Commit 8cce1cda authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents e3d7e482 e8b67da0
...@@ -4,4 +4,5 @@ export default { ...@@ -4,4 +4,5 @@ export default {
fallbackClass: 'is-dragging', fallbackClass: 'is-dragging',
fallbackOnBody: true, fallbackOnBody: true,
ghostClass: 'is-ghost', ghostClass: 'is-ghost',
fallbackTolerance: 1,
}; };
...@@ -278,6 +278,19 @@ class Wiki ...@@ -278,6 +278,19 @@ class Wiki
@repository = nil @repository = nil
end end
def capture_git_error(action, &block)
yield block
rescue Gitlab::Git::Index::IndexError,
Gitlab::Git::CommitError,
Gitlab::Git::PreReceiveError,
Gitlab::Git::CommandError,
ArgumentError => error
Gitlab::ErrorTracking.log_exception(error, action: action, wiki_id: id)
false
end
private private
def multi_commit_options(action, message = nil, title = nil) def multi_commit_options(action, message = nil, title = nil)
...@@ -311,19 +324,6 @@ class Wiki ...@@ -311,19 +324,6 @@ class Wiki
"#{user.username} #{action} page: #{title}" "#{user.username} #{action} page: #{title}"
end end
def capture_git_error(action, &block)
yield block
rescue Gitlab::Git::Index::IndexError,
Gitlab::Git::CommitError,
Gitlab::Git::PreReceiveError,
Gitlab::Git::CommandError,
ArgumentError => error
Gitlab::ErrorTracking.log_exception(error, action: action, wiki_id: id)
false
end
def change_head_to_default_branch def change_head_to_default_branch
repository.raw_repository.write_ref('HEAD', "refs/heads/#{default_branch}") repository.raw_repository.write_ref('HEAD', "refs/heads/#{default_branch}")
end end
......
...@@ -6,11 +6,12 @@ module WikiPages ...@@ -6,11 +6,12 @@ module WikiPages
wiki = Wiki.for_container(container, current_user) wiki = Wiki.for_container(container, current_user)
page = WikiPage.new(wiki) page = WikiPage.new(wiki)
if page.create(@params) wiki.capture_git_error(event_action) do
execute_hooks(page) page.create(@params)
end end
if page.persisted? if page.persisted?
execute_hooks(page)
ServiceResponse.success(payload: { page: page }) ServiceResponse.success(payload: { page: page })
else else
ServiceResponse.error(message: _('Could not create wiki page'), payload: { page: page }) ServiceResponse.error(message: _('Could not create wiki page'), payload: { page: page })
......
...@@ -8,7 +8,7 @@ module WikiPages ...@@ -8,7 +8,7 @@ module WikiPages
# this class is not thread safe! # this class is not thread safe!
@old_slug = page.slug @old_slug = page.slug
if page.update(@params) if page.wiki.capture_git_error(event_action) { page.update(@params) }
execute_hooks(page) execute_hooks(page)
ServiceResponse.success(payload: { page: page }) ServiceResponse.success(payload: { page: page })
else else
......
# frozen_string_literal: true
class RemoveFrameworkColumnFromComplianceManagementFrameworks < ActiveRecord::Migration[6.1]
def change
remove_column :project_compliance_framework_settings, :framework, :smallint
end
end
0fffffc44c32a936760424541e183b1a41938750d4e10da9dd76c2a09094a07b
\ No newline at end of file
...@@ -16697,7 +16697,6 @@ ALTER SEQUENCE project_ci_cd_settings_id_seq OWNED BY project_ci_cd_settings.id; ...@@ -16697,7 +16697,6 @@ ALTER SEQUENCE project_ci_cd_settings_id_seq OWNED BY project_ci_cd_settings.id;
CREATE TABLE project_compliance_framework_settings ( CREATE TABLE project_compliance_framework_settings (
project_id bigint NOT NULL, project_id bigint NOT NULL,
framework smallint,
framework_id bigint, framework_id bigint,
CONSTRAINT check_d348de9e2d CHECK ((framework_id IS NOT NULL)) CONSTRAINT check_d348de9e2d CHECK ((framework_id IS NOT NULL))
); );
...@@ -133,7 +133,7 @@ module EE ...@@ -133,7 +133,7 @@ module EE
# @return [AuditEvent, nil] if record is persisted or nil if audit events # @return [AuditEvent, nil] if record is persisted or nil if audit events
# features are not enabled # features are not enabled
def unauth_security_event def unauth_security_event
return unless audit_events_enabled? return unless audit_events_enabled? && ::Gitlab::Database.read_write?
add_security_event_admin_details! add_security_event_admin_details!
......
...@@ -25,6 +25,6 @@ RSpec.describe Gitlab::SearchResults do ...@@ -25,6 +25,6 @@ RSpec.describe Gitlab::SearchResults do
end end
def search def search
subject.objects('projects').map { |project| project.compliance_framework_setting.framework } subject.objects('projects').map { |project| project.compliance_framework_setting }
end end
end end
...@@ -333,6 +333,16 @@ RSpec.describe AuditEventService, :request_store do ...@@ -333,6 +333,16 @@ RSpec.describe AuditEventService, :request_store do
expect(event.details).not_to have_key(:ip_address) expect(event.details).not_to have_key(:ip_address)
end end
end end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not create an event record in the database' do
expect { service.for_failed_login.unauth_security_event }.not_to change(AuditEvent, :count)
end
end
end end
describe '#for_project_group_link' do describe '#for_project_group_link' do
......
...@@ -4,4 +4,24 @@ require 'spec_helper' ...@@ -4,4 +4,24 @@ require 'spec_helper'
RSpec.describe WikiPages::CreateService do RSpec.describe WikiPages::CreateService do
it_behaves_like 'WikiPages::CreateService#execute', :project it_behaves_like 'WikiPages::CreateService#execute', :project
describe '#execute' do
let_it_be(:project) { create(:project) }
subject(:service) { described_class.new(container: project) }
context 'when wiki create fails due to git error' do
let(:wiki_git_error) { 'Could not create wiki page' }
it 'catches the thrown error and returns a ServiceResponse error' do
allow_next_instance_of(WikiPage) do |instance|
allow(instance).to receive(:create).and_raise(Gitlab::Git::CommandError.new(wiki_git_error))
end
result = service.execute
expect(result).to be_error
expect(result.message).to eq(wiki_git_error)
end
end
end
end end
...@@ -4,4 +4,26 @@ require 'spec_helper' ...@@ -4,4 +4,26 @@ require 'spec_helper'
RSpec.describe WikiPages::UpdateService do RSpec.describe WikiPages::UpdateService do
it_behaves_like 'WikiPages::UpdateService#execute', :project it_behaves_like 'WikiPages::UpdateService#execute', :project
describe '#execute' do
let_it_be(:project) { create(:project) }
let(:page) { create(:wiki_page, project: project) }
subject(:service) { described_class.new(container: project) }
context 'when wiki create fails due to git error' do
let(:wiki_git_error) { 'Could not update wiki page' }
it 'catches the thrown error and returns a ServiceResponse error' do
allow_next_instance_of(WikiPage) do |instance|
allow(instance).to receive(:update).and_raise(Gitlab::Git::CommandError.new(wiki_git_error))
end
result = service.execute(page)
expect(result).to be_error
expect(result.message).to eq(wiki_git_error)
end
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