Commit 787d3514 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Skip auth check when creating incident label

parent 874e714c
......@@ -14,27 +14,9 @@ module IncidentManagement
def execute
label = Labels::FindOrCreateService
.new(current_user, project, **LABEL_PROPERTIES)
.execute
if label.invalid?
log_invalid_label_info(label)
return ServiceResponse.error(payload: { label: label }, message: full_error_message(label))
end
.execute(skip_authorization: true)
ServiceResponse.success(payload: { label: label })
end
private
def log_invalid_label_info(label)
log_info <<~TEXT.chomp
Cannot create incident label "#{label.title}" \
for "#{label.project.full_name}": #{full_error_message(label)}.
TEXT
end
def full_error_message(label)
label.errors.full_messages.to_sentence
end
end
end
......@@ -52,7 +52,15 @@ RSpec.describe IncidentManagement::CreateIncidentLabelService do
end
context 'without label' do
it_behaves_like 'new label'
context 'when user has permissions to create labels' do
it_behaves_like 'new label'
end
context 'when user has no permissions to create labels' do
let_it_be(:user) { create(:user) }
it_behaves_like 'new label'
end
end
end
end
......@@ -16,12 +16,4 @@ RSpec.shared_examples 'create alert issue sets issue labels' do
expect(issue.labels).to eq([label])
end
end
context 'when create incident label responds with error' do
let(:label_service_response) { ServiceResponse.error(payload: { label: label }, message: 'label error') }
it 'creates an issue without labels' do
expect(issue.labels).to be_empty
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