Commit b7e5f73c authored by Matija Čupić's avatar Matija Čupić

Raise exception when user is not authorized

parent 0bc14b45
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class DestroyPipelineService < BaseService class DestroyPipelineService < BaseService
def execute(pipeline) def execute(pipeline)
return false unless can?(current_user, :destroy_pipeline, pipeline) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
AuditEventService.new(current_user, pipeline).security_event AuditEventService.new(current_user, pipeline).security_event
......
...@@ -53,14 +53,8 @@ describe ::Ci::DestroyPipelineService do ...@@ -53,14 +53,8 @@ describe ::Ci::DestroyPipelineService do
context 'user is not owner' do context 'user is not owner' do
let(:user) { create(:user) } let(:user) { create(:user) }
it 'returns false' do it 'raises an exception' do
is_expected.to eq(false) expect { subject }.to raise_error(Gitlab::Access::AccessDeniedError)
end
it 'does not destroy the pipeline' do
subject
expect { pipeline.reload }.not_to raise_error
end 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