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
03177975
Commit
03177975
authored
Mar 19, 2020
by
Michelle Gill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent renaming a locked file
parent
651a786d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
5 deletions
+62
-5
ee/changelogs/unreleased/38230-locked-files.yml
ee/changelogs/unreleased/38230-locked-files.yml
+5
-0
ee/lib/ee/gitlab/checks/diff_check.rb
ee/lib/ee/gitlab/checks/diff_check.rb
+5
-1
ee/spec/lib/gitlab/checks/diff_check_spec.rb
ee/spec/lib/gitlab/checks/diff_check_spec.rb
+52
-4
No files found.
ee/changelogs/unreleased/38230-locked-files.yml
0 → 100644
View file @
03177975
---
title
:
Prevent renaming a locked file
merge_request
:
27623
author
:
type
:
fixed
ee/lib/ee/gitlab/checks/diff_check.rb
View file @
03177975
...
...
@@ -65,7 +65,11 @@ module EE
def
path_locks_validation
lambda
do
|
diff
|
path
=
diff
.
new_path
||
diff
.
old_path
path
=
if
diff
.
renamed_file?
diff
.
old_path
else
diff
.
new_path
||
diff
.
old_path
end
lock_info
=
project
.
find_path_lock
(
path
)
...
...
ee/spec/lib/gitlab/checks/diff_check_spec.rb
View file @
03177975
...
...
@@ -219,13 +219,61 @@ describe Gitlab::Checks::DiffCheck do
end
context
'file lock rules'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:push_rule
)
{
create
(
:push_rule
)
}
let_it_be
(
:owner
)
{
create
(
:user
)
}
let
(
:path_lock
)
{
create
(
:path_lock
,
path:
'README'
,
project:
project
)
}
it
'returns an error if the changes update a path locked by another user'
do
path_lock
before
do
project
.
add_developer
(
owner
)
end
shared_examples
'a locked file'
do
let!
(
:path_lock
)
{
create
(
:path_lock
,
path:
filename
,
project:
project
,
user:
owner
)
}
before
do
allow
(
project
.
repository
).
to
receive
(
:new_commits
).
and_return
(
[
project
.
repository
.
commit
(
sha
)]
)
end
context
'and path is locked by another user'
do
it
'returns an error'
do
path_lock
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
"The path '
#{
filename
}
' is locked by
#{
path_lock
.
user
.
name
}
"
)
end
end
context
'and path is locked by current user'
do
let
(
:user
)
{
owner
}
it
'is allows changes'
do
path_lock
expect
{
subject
.
validate!
}.
not_to
raise_error
end
end
end
context
'when file has changes'
do
let_it_be
(
:filename
)
{
'files/ruby/popen.rb'
}
let_it_be
(
:sha
)
{
'570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
}
it_behaves_like
'a locked file'
end
context
'when file is renamed'
do
let_it_be
(
:filename
)
{
'files/js/commit.js.coffee'
}
let_it_be
(
:sha
)
{
'6907208d755b60ebeacb2e9dfea74c92c3449a1f'
}
it_behaves_like
'a locked file'
end
context
'when file is deleted'
do
let_it_be
(
:filename
)
{
'files/js/commit.js.coffee'
}
let_it_be
(
:sha
)
{
'd59c60028b053793cecfb4022de34602e1a9218e'
}
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
"The path 'README' is locked by
#{
path_lock
.
user
.
name
}
"
)
it_behaves_like
'a locked file'
end
it
'memoizes the validate_path_locks? call'
do
...
...
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