Commit 206d4e2c authored by Yorick Peterse's avatar Yorick Peterse

Move EE code out of Chain::Validate::Abilities

This moves EE specific code out of
Gitlab::Ci::Pipeline::Chain::Validate::Abilities and into
EE::Gitlab::Ci::Pipeline::Chain::Validate::Abilities. Since the moved
code was not tested in any way (that I could find at least), some tests
for this were also added.
parent baf626e5
# frozen_string_literal: true
module EE
module Gitlab
module Ci
module Pipeline
module Chain
module Validate
module Abilities
extend ::Gitlab::Utils::Override
override :perform!
def perform!
# We check for `builds_enabled?` here so that this error does
# not get produced before the "pipelines are disabled" error.
if project.builds_enabled? &&
(command.allow_mirror_update && !project.mirror_trigger_builds?)
return error('Pipeline is disabled for mirror updates')
end
super
end
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
set(:project) { create(:project, :repository) }
set(:user) { create(:user) }
let(:pipeline) do
build_stubbed(:ci_pipeline, project: project)
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command
.new(project: project, current_user: user, origin_ref: ref)
end
let(:step) { described_class.new(pipeline, command) }
let(:ref) { 'master' }
describe '#perform!' do
context 'when triggering builds for project mirrors is disabled' do
it 'returns an error' do
project.add_developer(user)
allow(command)
.to receive(:allow_mirror_update)
.and_return(true)
allow(project)
.to receive(:mirror_trigger_builds?)
.and_return(false)
step.perform!
expect(pipeline.errors.to_a)
.to include('Pipeline is disabled for mirror updates')
end
end
end
end
......@@ -14,10 +14,6 @@ module Gitlab
return error('Pipelines are disabled!')
end
if @command.allow_mirror_update && !project.mirror_trigger_builds?
return error('Pipeline is disabled for mirror updates')
end
unless allowed_to_trigger_pipeline?
if can?(current_user, :create_pipeline, project)
return error("Insufficient permissions for protected ref '#{command.ref}'")
......@@ -58,3 +54,5 @@ module Gitlab
end
end
end
Gitlab::Ci::Pipeline::Chain::Validate::Abilities.prepend(EE::Gitlab::Ci::Pipeline::Chain::Validate::Abilities)
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