Commit 0a0f66c8 authored by Michael Kozono's avatar Michael Kozono

Refactor to remove a special case

parent 7d469cf1
module Gitlab
# For backwards compatibility, generic CI (which is a build without a user) is
# allowed to :build_download_code without any other checks.
class CiAccess
def can_do_action?(action)
action == :build_download_code
end
end
end
......@@ -29,7 +29,11 @@ module Gitlab
@project = project
@protocol = protocol
@authentication_abilities = authentication_abilities
@user_access = UserAccess.new(user, project: project)
@user_access = if ci?
CiAccess.new
else
UserAccess.new(user, project: project)
end
end
def check(cmd, changes)
......@@ -62,11 +66,6 @@ module Gitlab
authentication_abilities.include?(:build_download_code) && user_access.can_do_action?(:build_download_code)
end
# Allow generic CI (build without a user) for backwards compatibility
def ci_can_download_code?
authentication_abilities.include?(:build_download_code) && ci?
end
def protocol_allowed?
Gitlab::ProtocolAccess.allowed?(protocol)
end
......@@ -129,7 +128,6 @@ module Gitlab
return if deploy_key?
passed = user_can_download_code? ||
ci_can_download_code? ||
build_can_download_code? ||
guest_can_download_code?
......
require 'spec_helper'
describe Gitlab::CiAccess, lib: true do
let(:access) { Gitlab::CiAccess.new }
describe '#can_do_action?' do
context 'when action is :build_download_code' do
it { expect(access.can_do_action?(:build_download_code)).to be_truthy }
end
context 'when action is not :build_download_code' do
it { expect(access.can_do_action?(:download_code)).to be_falsey }
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