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 {
fallbackClass: 'is-dragging',
fallbackOnBody: true,
ghostClass: 'is-ghost',
fallbackTolerance: 1,
};
......@@ -278,6 +278,19 @@ class Wiki
@repository = nil
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
def multi_commit_options(action, message = nil, title = nil)
......@@ -311,19 +324,6 @@ class Wiki
"#{user.username} #{action} page: #{title}"
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
repository.raw_repository.write_ref('HEAD', "refs/heads/#{default_branch}")
end
......
......@@ -6,11 +6,12 @@ module WikiPages
wiki = Wiki.for_container(container, current_user)
page = WikiPage.new(wiki)
if page.create(@params)
execute_hooks(page)
wiki.capture_git_error(event_action) do
page.create(@params)
end
if page.persisted?
execute_hooks(page)
ServiceResponse.success(payload: { page: page })
else
ServiceResponse.error(message: _('Could not create wiki page'), payload: { page: page })
......
......@@ -8,7 +8,7 @@ module WikiPages
# this class is not thread safe!
@old_slug = page.slug
if page.update(@params)
if page.wiki.capture_git_error(event_action) { page.update(@params) }
execute_hooks(page)
ServiceResponse.success(payload: { page: page })
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;
CREATE TABLE project_compliance_framework_settings (
project_id bigint NOT NULL,
framework smallint,
framework_id bigint,
CONSTRAINT check_d348de9e2d CHECK ((framework_id IS NOT NULL))
);
......@@ -133,7 +133,7 @@ module EE
# @return [AuditEvent, nil] if record is persisted or nil if audit events
# features are not enabled
def unauth_security_event
return unless audit_events_enabled?
return unless audit_events_enabled? && ::Gitlab::Database.read_write?
add_security_event_admin_details!
......
......@@ -25,6 +25,6 @@ RSpec.describe Gitlab::SearchResults do
end
def search
subject.objects('projects').map { |project| project.compliance_framework_setting.framework }
subject.objects('projects').map { |project| project.compliance_framework_setting }
end
end
......@@ -333,6 +333,16 @@ RSpec.describe AuditEventService, :request_store do
expect(event.details).not_to have_key(:ip_address)
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
describe '#for_project_group_link' do
......
......@@ -4,4 +4,24 @@ require 'spec_helper'
RSpec.describe WikiPages::CreateService do
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
......@@ -4,4 +4,26 @@ require 'spec_helper'
RSpec.describe WikiPages::UpdateService do
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
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