Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
0a0f66c8
Commit
0a0f66c8
authored
May 22, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to remove a special case
parent
7d469cf1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
7 deletions
+29
-7
lib/gitlab/ci_access.rb
lib/gitlab/ci_access.rb
+9
-0
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+5
-7
spec/lib/gitlab/ci_access_spec.rb
spec/lib/gitlab/ci_access_spec.rb
+15
-0
No files found.
lib/gitlab/ci_access.rb
0 → 100644
View file @
0a0f66c8
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
lib/gitlab/git_access.rb
View file @
0a0f66c8
...
...
@@ -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?
...
...
spec/lib/gitlab/ci_access_spec.rb
0 → 100644
View file @
0a0f66c8
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment