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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
0a081e7e
Commit
0a081e7e
authored
Dec 03, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If a user clicks on the LFS object, it should be served if the user has access to the object.
parent
6689224a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+17
-0
app/models/lfs_object.rb
app/models/lfs_object.rb
+10
-0
No files found.
app/controllers/projects/blob_controller.rb
View file @
0a081e7e
...
...
@@ -17,6 +17,7 @@ class Projects::BlobController < Projects::ApplicationController
before_action
:require_branch_head
,
only:
[
:edit
,
:update
]
before_action
:editor_variables
,
except:
[
:show
,
:preview
,
:diff
]
before_action
:after_edit_path
,
only:
[
:edit
,
:update
]
before_action
:show_lfs_object
,
only: :show
def
new
commit
unless
@repository
.
empty?
...
...
@@ -193,4 +194,20 @@ class Projects::BlobController < Projects::ApplicationController
file_content_encoding:
params
[
:encoding
]
}
end
def
show_lfs_object
return
unless
@blob
&&
@blob
.
text?
&&
@blob
.
data
.
present?
if
@blob
.
data
.
starts_with?
(
"version https://git-lfs.github.com/spec"
)
oid
=
@blob
.
data
.
match
(
/
#{
LfsObject
::
MATCH_FROM_POINTER_REGEX
}
/
)
if
oid
&&
oid
[
1
]
lfs_object
=
LfsObject
.
find_by_oid
(
oid
[
1
])
return
nil
unless
lfs_object
&&
lfs_object
.
file
.
exists?
if
lfs_object
.
projects
.
exists?
(
lfs_object
.
storage_project
(
@project
).
id
)
send_file
lfs_object
.
file
.
path
,
filename:
@blob
.
name
,
disposition:
'attachment'
end
end
end
end
end
app/models/lfs_object.rb
View file @
0a081e7e
...
...
@@ -5,4 +5,14 @@ class LfsObject < ActiveRecord::Base
validates
:oid
,
presence:
true
,
uniqueness:
true
mount_uploader
:file
,
LfsObjectUploader
MATCH_FROM_POINTER_REGEX
=
"(?<=sha256:)([0-9a-f]{64})"
def
storage_project
(
project
)
if
project
&&
project
.
forked?
project
.
forked_from_project
else
project
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