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
1d0ecbd4
Commit
1d0ecbd4
authored
Jan 26, 2018
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync the changes to LFS when locking/unlocking files in the UI
parent
98f57443
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
3 deletions
+130
-3
app/services/lfs/unlock_file_service.rb
app/services/lfs/unlock_file_service.rb
+10
-1
changelogs/unreleased-ee/1830-implement-lfs-file-locking.yml
changelogs/unreleased-ee/1830-implement-lfs-file-locking.yml
+5
-0
ee/app/controllers/projects/path_locks_controller.rb
ee/app/controllers/projects/path_locks_controller.rb
+36
-2
spec/ee/requests/projects/path_locks_spec.rb
spec/ee/requests/projects/path_locks_spec.rb
+79
-0
No files found.
app/services/lfs/unlock_file_service.rb
View file @
1d0ecbd4
...
@@ -20,7 +20,6 @@ module Lfs
...
@@ -20,7 +20,6 @@ module Lfs
def
unlock_file
def
unlock_file
forced
=
params
[
:force
]
==
true
forced
=
params
[
:force
]
==
true
lock
=
project
.
lfs_file_locks
.
find
(
params
[
:id
])
if
lock
.
can_be_unlocked_by?
(
current_user
,
forced
)
if
lock
.
can_be_unlocked_by?
(
current_user
,
forced
)
lock
.
destroy!
lock
.
destroy!
...
@@ -32,5 +31,15 @@ module Lfs
...
@@ -32,5 +31,15 @@ module Lfs
error
(
"
#{
lock
.
path
}
is locked by GitLab User
#{
lock
.
user_id
}
"
,
403
)
error
(
"
#{
lock
.
path
}
is locked by GitLab User
#{
lock
.
user_id
}
"
,
403
)
end
end
end
end
def
lock
return
@lock
if
defined?
(
@lock
)
@lock
=
if
params
[
:id
].
present?
project
.
lfs_file_locks
.
find
(
params
[
:id
])
elsif
params
[
:path
].
present?
project
.
lfs_file_locks
.
find_by!
(
path:
params
[
:path
])
end
end
end
end
end
end
changelogs/unreleased-ee/1830-implement-lfs-file-locking.yml
0 → 100644
View file @
1d0ecbd4
---
title
:
Add support for LFS File Locking API
merge_request
:
4091
author
:
type
:
added
ee/app/controllers/projects/path_locks_controller.rb
View file @
1d0ecbd4
class
Projects::PathLocksController
<
Projects
::
ApplicationController
class
Projects::PathLocksController
<
Projects
::
ApplicationController
include
PathLocksHelper
include
PathLocksHelper
include
ExtractsPath
# Authorize
# Authorize
before_action
:require_non_empty_project
before_action
:require_non_empty_project
before_action
:authorize_push_code!
,
only:
[
:toggle
]
before_action
:authorize_push_code!
,
only:
[
:toggle
]
before_action
:check_license
before_action
:check_license
before_action
:assign_ref_vars
,
only: :toggle
before_action
:lfs_blob_ids
,
only: :toggle
def
index
def
index
@path_locks
=
@project
.
path_locks
.
page
(
params
[
:page
])
@path_locks
=
@project
.
path_locks
.
page
(
params
[
:page
])
...
@@ -15,9 +18,9 @@ class Projects::PathLocksController < Projects::ApplicationController
...
@@ -15,9 +18,9 @@ class Projects::PathLocksController < Projects::ApplicationController
path_lock
=
@project
.
path_locks
.
find_by
(
path:
params
[
:path
])
path_lock
=
@project
.
path_locks
.
find_by
(
path:
params
[
:path
])
if
path_lock
if
path_lock
PathLocks
::
UnlockService
.
new
(
project
,
current_user
).
execut
e
(
path_lock
)
unlock_fil
e
(
path_lock
)
else
else
PathLocks
::
LockService
.
new
(
project
,
current_user
).
execute
(
params
[
:path
])
lock_file
end
end
head
:ok
head
:ok
...
@@ -50,4 +53,35 @@ class Projects::PathLocksController < Projects::ApplicationController
...
@@ -50,4 +53,35 @@ class Projects::PathLocksController < Projects::ApplicationController
redirect_to
admin_license_path
redirect_to
admin_license_path
end
end
end
end
def
lock_file
path_lock
=
PathLocks
::
LockService
.
new
(
project
,
current_user
).
execute
(
params
[
:path
])
if
path_lock
.
persisted?
&&
sync_with_lfs?
Lfs
::
LockFileService
.
new
(
project
,
current_user
,
path:
params
[
:path
]).
execute
end
end
def
unlock_file
(
path_lock
)
PathLocks
::
UnlockService
.
new
(
project
,
current_user
).
execute
(
path_lock
)
if
sync_with_lfs?
Lfs
::
UnlockFileService
.
new
(
project
,
current_user
,
path:
path_lock
.
path
,
force:
true
).
execute
end
end
# Override get_id from ExtractsPath in this case is just the root of the default branch.
def
get_id
@ref
||=
project
.
repository
.
root_ref
end
def
lfs_file?
blob
=
project
.
repository
.
blob_at_branch
(
get_id
,
params
[
:path
])
@lfs_blob_ids
.
include?
(
blob
.
id
)
end
def
sync_with_lfs?
project
.
lfs_enabled?
&&
lfs_file?
end
end
end
spec/ee/requests/projects/path_locks_spec.rb
0 → 100644
View file @
1d0ecbd4
require
'rails_helper'
describe
Projects
::
PathLocksController
,
type: :request
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
project
.
owner
}
let
(
:viewer
)
{
user
}
before
do
login_as
(
viewer
)
end
describe
'POST #toggle'
do
context
'when locking a file'
do
context
'when LFS is enabled'
do
before
do
allow_any_instance_of
(
Projects
::
PathLocksController
).
to
receive
(
:sync_with_lfs?
).
and_return
(
true
)
end
it
'locks the file'
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
PathLock
.
count
}.
to
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
"locks the file in LFS"
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
LfsFileLock
.
count
}.
to
(
1
)
end
end
context
'when LFS is not enabled'
do
it
'locks the file'
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
PathLock
.
count
}.
to
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
"doesn't lock the file in LFS"
do
expect
{
toggle_lock
(
'README.md'
)
}.
not_to
change
{
LfsFileLock
.
count
}
end
end
end
context
'when unlocking a file'
do
context
'when LFS is enabled'
do
before
do
allow_any_instance_of
(
Projects
::
PathLocksController
).
to
receive
(
:sync_with_lfs?
).
and_return
(
true
)
toggle_lock
(
'README.md'
)
end
it
'unlocks the file'
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
PathLock
.
count
}.
to
(
0
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
"unlocks the file in LFS"
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
LfsFileLock
.
count
}.
to
(
0
)
end
end
end
context
'when LFS is not enabled'
do
before
do
toggle_lock
(
'README.md'
)
end
it
'unlocks the file'
do
expect
{
toggle_lock
(
'README.md'
)
}.
to
change
{
PathLock
.
count
}.
to
(
0
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
end
def
toggle_lock
(
path
)
post
toggle_project_path_locks_path
(
project
),
path:
path
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