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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
7d035c58
Commit
7d035c58
authored
Jan 27, 2018
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactor to reduce number of methods in Gitlab::Checks::ChangeAccess
Plus small update for LfsLocksApiController
parent
1b00af9b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
36 deletions
+59
-36
app/controllers/projects/lfs_locks_api_controller.rb
app/controllers/projects/lfs_locks_api_controller.rb
+1
-1
lib/gitlab/checks/change_access.rb
lib/gitlab/checks/change_access.rb
+8
-35
lib/gitlab/checks/commit_check.rb
lib/gitlab/checks/commit_check.rb
+50
-0
No files found.
app/controllers/projects/lfs_locks_api_controller.rb
View file @
7d035c58
...
...
@@ -61,7 +61,7 @@ class Projects::LfsLocksApiController < Projects::GitHttpClientController
end
def
download_request?
%w(index)
.
include?
(
params
[
:action
])
params
[
:action
]
==
'index'
end
def
upload_request?
...
...
lib/gitlab/checks/change_access.rb
View file @
7d035c58
...
...
@@ -120,48 +120,21 @@ module Gitlab
end
end
def
commit_check
@commit_check
||=
Gitlab
::
Checks
::
CommitCheck
.
new
(
project
,
user_access
.
user
,
newrev
,
oldrev
)
end
def
commits_check
return
if
deletion?
||
newrev
.
nil?
commits
.
each
do
|
commit
|
check_commit_diff
(
commit
)
end
end
def
check_commit_diff
(
commit
)
validations
=
validations_for_commit
(
commit
)
return
if
validations
.
empty?
commit
.
raw_deltas
.
each
do
|
diff
|
validations
.
each
do
|
validation
|
if
error
=
validation
.
call
(
diff
)
raise
::
Gitlab
::
GitAccess
::
UnauthorizedError
,
error
end
end
commit_check
.
validate
(
commit
,
validations_for_commit
(
commit
))
end
nil
end
def
validations_for_commit
(
commit
)
validate_lfs_file_locks?
?
[
lfs_file_locks_validation
]
:
[]
end
def
validate_lfs_file_locks?
project
.
lfs_enabled?
&&
project
.
lfs_file_locks
.
any?
&&
newrev
&&
oldrev
end
def
lfs_file_locks_validation
lambda
do
|
diff
|
path
=
diff
.
new_path
||
diff
.
old_path
lfs_lock
=
project
.
lfs_file_locks
.
find_by
(
path:
path
)
if
lfs_lock
&&
lfs_lock
.
user
!=
user_access
.
user
return
"The path '
#{
lfs_lock
.
path
}
' is locked in Git LFS by
#{
lfs_lock
.
user
.
name
}
"
end
end
# Method overwritten in EE to inject custom validations
def
validations_for_commit
(
_
)
commit_check
.
validations
end
private
...
...
lib/gitlab/checks/commit_check.rb
0 → 100644
View file @
7d035c58
module
Gitlab
module
Checks
class
CommitCheck
attr_reader
:project
,
:user
,
:newrev
,
:oldrev
def
initialize
(
project
,
user
,
newrev
,
oldrev
)
@project
=
project
@user
=
user
@newrev
=
user
@oldrev
=
user
end
def
validate
(
commit
,
validations
)
return
if
validations
.
empty?
commit
.
raw_deltas
.
each
do
|
diff
|
validations
.
each
do
|
validation
|
if
error
=
validation
.
call
(
diff
)
raise
::
Gitlab
::
GitAccess
::
UnauthorizedError
,
error
end
end
end
nil
end
def
validations
validate_lfs_file_locks?
?
[
lfs_file_locks_validation
]
:
[]
end
private
def
validate_lfs_file_locks?
project
.
lfs_enabled?
&&
project
.
lfs_file_locks
.
any?
&&
newrev
&&
oldrev
end
def
lfs_file_locks_validation
lambda
do
|
diff
|
path
=
diff
.
new_path
||
diff
.
old_path
lfs_lock
=
project
.
lfs_file_locks
.
find_by
(
path:
path
)
if
lfs_lock
&&
lfs_lock
.
user
!=
user
return
"The path '
#{
lfs_lock
.
path
}
' is locked in Git LFS by
#{
lfs_lock
.
user
.
name
}
"
end
end
end
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