Refactor to remove a special case
This commit is contained in:
parent
7d469cf1c1
commit
0a0f66c816
3 changed files with 29 additions and 7 deletions
9
lib/gitlab/ci_access.rb
Normal file
9
lib/gitlab/ci_access.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
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?
|
||||
|
||||
|
|
15
spec/lib/gitlab/ci_access_spec.rb
Normal file
15
spec/lib/gitlab/ci_access_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
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
|
Loading…
Reference in a new issue